新增安装器工具,用于辅助安装以及修复StarAgent

This commit is contained in:
智能大石头 2023-01-01 14:31:11 +08:00
parent 53e87a969b
commit 5ecd1ab50b
5 changed files with 225 additions and 0 deletions

46
Installer/Command.cs Normal file
View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
namespace Installer;
/// <summary>命令选项</summary>
internal class Command
{
#region
/// <summary>操作名</summary>
public String Name { get; set; }
/// <summary>参数集合</summary>
public IList<String> Arguments { get; set; } = new List<String>();
#endregion
#region
/// <summary>分析输入参数数组,得到命令选项列表</summary>
/// <param name="args"></param>
/// <returns></returns>
public static IList<Command> Parse(String[] args)
{
var commands = new List<Command>();
if (args == null || args.Length == 0) return commands;
Command command = null;
for (var i = 0; i < args.Length; i++)
{
// 命令以-开头,其它是参数
var arg = args[i];
if (arg[0] == '-')
commands.Add(command = new Command { Name = arg });
else
{
// 如果第一个参数不是-开头,则添加空名称命令
if (command == null)
commands.Add(command = new Command { Name = "" });
command.Arguments.Add(arg);
}
}
return commands;
}
#endregion
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net40;net45;net5.0;net6.0;net7.0</TargetFrameworks>
<AssemblyTitle>安装器</AssemblyTitle>
<Description>安装辅助工具</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 NewLife</Copyright>
<VersionPrefix>1.0</VersionPrefix>
<VersionSuffix>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<FileVersion>$(Version)</FileVersion>
<AssemblyVersion>$(VersionPrefix).*</AssemblyVersion>
<Deterministic>false</Deterministic>
<OutputPath>..\Bin\Agent</OutputPath>
<!--<ImplicitUsings>enable</ImplicitUsings>-->
<LangVersion>latest</LangVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>

70
Installer/Program.cs Normal file
View File

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Installer;
internal class Program
{
static void Main(String[] args)
{
if (args != null)
Console.WriteLine("args: {0}", String.Join(' ', args));
// 分解命令(可能包括多组),逐个执行
// 如installer.exe -install StarAgent -start StarAgent
foreach (var cmd in Command.Parse(args))
{
switch (cmd.Name.ToLower())
{
case "-install": Install(cmd.Arguments); break;
case "-uninstall": Uninstall(cmd.Arguments); break;
case "-reinstall": Reinstall(cmd.Arguments); break;
case "-start": Start(cmd.Arguments); break;
case "-stop": Stop(cmd.Arguments); break;
case "-restart": Restart(cmd.Arguments); break;
default:
break;
}
}
Console.WriteLine("Hello, World!");
}
static void Install(IList<String> args)
{
}
static void Uninstall(IList<String> args)
{
}
static void Reinstall(IList<String> args)
{
}
static void Start(IList<String> args)
{
if (args.Count == 0) return;
Process.Start("net", $"start {args[0]}");
}
static void Stop(IList<String> args)
{
if (args.Count == 0) return;
Process.Start("net", $"stop {args[0]}");
}
static void Restart(IList<String> args)
{
if (args.Count == 0) return;
Process.Start("net", $"start {args[0]}");
Process.Start("net", $"stop {args[0]}");
}
}

79
Installer/app.manifest Normal file
View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

View File

@ -38,6 +38,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{11AD
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkDetect", "Plugins\NetworkDetect\NetworkDetect.csproj", "{7178875E-F5DD-4136-A5E6-EEBF151396CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Installer", "Installer\Installer.csproj", "{3ACE1337-CD19-41BC-A2C7-EDF49474C367}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -88,6 +90,10 @@ Global
{7178875E-F5DD-4136-A5E6-EEBF151396CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7178875E-F5DD-4136-A5E6-EEBF151396CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7178875E-F5DD-4136-A5E6-EEBF151396CB}.Release|Any CPU.Build.0 = Release|Any CPU
{3ACE1337-CD19-41BC-A2C7-EDF49474C367}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3ACE1337-CD19-41BC-A2C7-EDF49474C367}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3ACE1337-CD19-41BC-A2C7-EDF49474C367}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3ACE1337-CD19-41BC-A2C7-EDF49474C367}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -96,6 +102,7 @@ Global
{7DE10A4D-1749-4474-A6B2-F52CA8462813} = {48B9E6E7-289F-42F2-8ACA-E7DF8E7C9059}
{677C6502-2C9C-4907-AD82-670BE77B0AE6} = {48B9E6E7-289F-42F2-8ACA-E7DF8E7C9059}
{7178875E-F5DD-4136-A5E6-EEBF151396CB} = {11AD7F18-1320-41C5-B4A9-F208DBCAA5A9}
{3ACE1337-CD19-41BC-A2C7-EDF49474C367} = {11AD7F18-1320-41C5-B4A9-F208DBCAA5A9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9337283C-C795-479F-A2F1-C892EBE2490C}