Separate installer CLI

This commit is contained in:
CreepyCrafter24 2020-04-09 13:58:06 +02:00
parent c186afa8b4
commit eca073fab3
12 changed files with 173 additions and 123 deletions

View File

@ -24,10 +24,11 @@ jobs:
$pkgtoolver = $([Reflection.Assembly]::Loadfile($(pwd).Path + "\\UpTool build tool\\bin\\Release\\netcoreapp3.1\\pkgtool.dll").GetName().version.ToString())
echo "::set-output name=vers::$asmver"
echo "::set-output name=pkgvers::$pkgtoolver"
cd $Env:GITHUB_WORKSPACE\Installer
cd $Env:GITHUB_WORKSPACE\InstallerCLI
& "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\Installer.exe
& "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\*.dll
& "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\Installer.runtimeconfig.json
& "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\Info.txt
cd $Env:GITHUB_WORKSPACE
- name: Create Release
id: create_release

View File

@ -27,7 +27,8 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InstallerForm));
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(Installer.InstallerForm));
this.install = new System.Windows.Forms.Button();
this.installLabel = new System.Windows.Forms.Label();
this.progress = new System.Windows.Forms.ProgressBar();
@ -37,11 +38,10 @@
this.pathBox = new System.Windows.Forms.CheckBox();
this.updateAppsBox = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// install
//
this.install.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.install.Anchor =
((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left) |
System.Windows.Forms.AnchorStyles.Right)));
this.install.Location = new System.Drawing.Point(12, 116);
this.install.Name = "install";
this.install.Size = new System.Drawing.Size(539, 27);
@ -49,41 +49,35 @@
this.install.Text = "Install";
this.install.UseVisualStyleBackColor = true;
this.install.Click += new System.EventHandler(this.install_Click);
//
// installLabel
//
this.installLabel.AutoSize = true;
this.installLabel.Location = new System.Drawing.Point(12, 9);
this.installLabel.Name = "installLabel";
this.installLabel.Size = new System.Drawing.Size(550, 75);
this.installLabel.TabIndex = 1;
this.installLabel.Text = resources.GetString("installLabel.Text");
//
// progress
//
this.progress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progress.Anchor =
((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left) |
System.Windows.Forms.AnchorStyles.Right)));
this.progress.Location = new System.Drawing.Point(12, 116);
this.progress.Maximum = 8;
this.progress.Name = "progress";
this.progress.Size = new System.Drawing.Size(539, 27);
this.progress.TabIndex = 2;
this.progress.Visible = false;
//
// processLabel
//
this.processLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.processLabel.Anchor =
((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left) |
System.Windows.Forms.AnchorStyles.Right)));
this.processLabel.ForeColor = System.Drawing.SystemColors.ControlText;
this.processLabel.Location = new System.Drawing.Point(386, 91);
this.processLabel.Name = "processLabel";
this.processLabel.Size = new System.Drawing.Size(165, 22);
this.processLabel.TabIndex = 3;
this.processLabel.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// log
//
this.log.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.log.Anchor =
((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Right)));
this.log.Location = new System.Drawing.Point(524, 3);
this.log.Name = "log";
this.log.Size = new System.Drawing.Size(36, 23);
@ -92,10 +86,9 @@
this.log.UseVisualStyleBackColor = true;
this.log.Visible = false;
this.log.Click += new System.EventHandler(this.log_Click);
//
// startupBox
//
this.startupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.startupBox.Anchor =
((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left)));
this.startupBox.AutoSize = true;
this.startupBox.Enabled = false;
this.startupBox.Location = new System.Drawing.Point(130, 91);
@ -104,10 +97,9 @@
this.startupBox.TabIndex = 5;
this.startupBox.Text = "Update on Startup";
this.startupBox.CheckedChanged += new System.EventHandler(this.startupBox_CheckedChanged);
//
// pathBox
//
this.pathBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.pathBox.Anchor =
((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left)));
this.pathBox.AutoSize = true;
this.pathBox.Location = new System.Drawing.Point(12, 91);
this.pathBox.Name = "pathBox";
@ -115,10 +107,9 @@
this.pathBox.TabIndex = 6;
this.pathBox.Text = "Register in PATH";
this.pathBox.CheckedChanged += new System.EventHandler(this.pathBox_CheckedChanged);
//
// updateAppsBox
//
this.updateAppsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.updateAppsBox.Anchor =
((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left)));
this.updateAppsBox.AutoSize = true;
this.updateAppsBox.Enabled = false;
this.updateAppsBox.Location = new System.Drawing.Point(258, 91);
@ -126,9 +117,6 @@
this.updateAppsBox.Size = new System.Drawing.Size(94, 19);
this.updateAppsBox.TabIndex = 5;
this.updateAppsBox.Text = "Update Apps";
//
// InstallerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(563, 156);
@ -141,13 +129,12 @@
this.Controls.Add(this.startupBox);
this.Controls.Add(this.pathBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
this.Name = "InstallerForm";
this.ShowIcon = false;
this.Text = "UpTool2 Installer";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion

View File

@ -28,7 +28,7 @@ namespace Installer
Step(0, "Initialized");
_log = _log.TrimStart(Environment.NewLine.ToCharArray());
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
pathBox.Checked = Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install")));
pathBox.Checked = !File.Exists(PathTool.InfoXml) || Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install")));
startupBox.Checked = pathBox.Checked && _rkApp.GetValue(AppName) != null;
updateAppsBox.Checked = pathBox.Checked && startupBox.Checked && (string)_rkApp.GetValue(AppName) == "uptool dist-upgrade";
}
@ -77,9 +77,7 @@ Online: {meta.Element("Hash").Value.ToUpper()}");
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
Path.Append(PathTool.GetRelative("Install"));
if (startupBox.Checked)
{
_rkApp.SetValue(AppName, updateAppsBox.Checked ? "uptool dist-upgrade" : "uptool upgrade-self");
}
else if (_rkApp.GetValue(AppName) != null)
_rkApp.DeleteValue(AppName, false);
}

View File

@ -17,63 +17,15 @@ namespace Installer
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main(string[] args)
private static void Main()
{
try
{
if (!args.Any(s => new[] {"install", "i"}.Contains(s.TrimStart('-', '/').ToLower())))
{
MutexLock.Lock();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new InstallerForm());
}
else
{
Thread.Sleep(2000);
MutexLock.Lock();
ExternalFunctionalityManager.Init(new UtLibFunctionsCli());
WebClient client = new WebClient();
Console.WriteLine("Downloading metadata");
UpdateCheck.Reload("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml");
Console.WriteLine("Downloading binary");
byte[] dl = client.DownloadData(UpdateCheck.App);
Console.WriteLine("Verifying integrity");
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
{
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty)
.ToUpper();
if (pkgHash != UpdateCheck.AppHash)
throw new Exception($@"The hash is not equal to the one stored in the repo:
Package: {pkgHash}
Online: {UpdateCheck.AppHash}");
}
Console.WriteLine("Extracting");
if (Directory.Exists(PathTool.GetRelative("Install")))
{
foreach (string file in Directory.GetFiles(PathTool.GetRelative("Install"))) File.Delete(file);
foreach (string dir in Directory.GetDirectories(PathTool.GetRelative("Install")))
if (System.IO.Path.GetFileName(dir) != "tmp")
Directory.Delete(dir, true);
}
Directory.CreateDirectory(PathTool.GetRelative("Install"));
using (MemoryStream ms = new MemoryStream(dl))
{
using ZipArchive ar = new ZipArchive(ms);
ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
}
Console.WriteLine("Creating shortcut");
Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"UpTool2.lnk"));
Console.WriteLine("Creating PATH entry");
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
Path.Append(PathTool.GetRelative("Install"));
Console.WriteLine("Preparing Repos");
XmlTool.FixXml();
RepoManagement.FetchRepos();
}
MutexLock.Lock();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new InstallerForm());
}
finally
{

2
InstallerCLI/Info.txt Normal file
View File

@ -0,0 +1,2 @@
Use "Installer --help" for info
(on non-windows platforms, use the dotnet CLI to run Installer.dll)

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Installer</AssemblyName>
<RootNamespace>Installer</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UpToolLib\UpToolLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20158.1" />
</ItemGroup>
</Project>

82
InstallerCLI/Program.cs Normal file
View File

@ -0,0 +1,82 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Security.Cryptography;
using System.Threading;
using UpToolLib;
using UpToolLib.Tool;
namespace Installer
{
public static class Program
{
public static int Main(string[] args)
{
Thread.Sleep(2000);
MutexLock.Lock();
try
{
ExternalFunctionalityManager.Init(new UtLibFunctions());
RootCommand rootCommand = new RootCommand();
Command install = new Command("install", "Install UpTool")
{
new Option<bool>(new[] {"--noPrep", "-p"}, "Doesn't initialize repos. Use with caution!")
};
install.AddAlias("-i");
install.AddAlias("i");
install.Handler = CommandHandler.Create<bool>(Install);
rootCommand.AddCommand(install);
return rootCommand.InvokeAsync(args).Result;
}
catch (Exception e)
{
Console.WriteLine($"FAILED: {e}");
return 1;
}
finally
{
MutexLock.Unlock();
}
}
private static void Install(bool noPrep)
{
WebClient client = new WebClient();
Console.WriteLine("Downloading metadata");
UpdateCheck.Reload("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml");
Console.WriteLine("Downloading binary");
byte[] dl = client.DownloadData(UpdateCheck.App);
Console.WriteLine("Verifying integrity");
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
{
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty)
.ToUpper();
if (pkgHash != UpdateCheck.AppHash)
throw new Exception($@"The hash is not equal to the one stored in the repo:
Package: {pkgHash}
Online: {UpdateCheck.AppHash}");
}
Console.WriteLine("Extracting");
if (Directory.Exists(PathTool.GetRelative("Install")))
{
foreach (string file in Directory.GetFiles(PathTool.GetRelative("Install"))) File.Delete(file);
foreach (string dir in Directory.GetDirectories(PathTool.GetRelative("Install")))
if (Path.GetFileName(dir) != "tmp")
Directory.Delete(dir, true);
}
Directory.CreateDirectory(PathTool.GetRelative("Install"));
using (MemoryStream ms = new MemoryStream(dl))
{
using ZipArchive ar = new ZipArchive(ms);
ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
}
if (noPrep) return;
Console.WriteLine("Preparing Repos");
XmlTool.FixXml();
RepoManagement.FetchRepos();
}
}
}

View File

@ -1,15 +1,14 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Threading;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using UpToolLib.DataStructures;
namespace Installer
{
public class UtLibFunctionsCli : IExternalFunctionality
public class UtLibFunctions : IExternalFunctionality
{
public Tuple<bool, byte[]> Download(Uri link)
{
@ -39,24 +38,10 @@ namespace Installer
public string FetchImageB64(Uri link)
{
using WebClient client = new WebClient();
Image src = Image.FromStream(
client.OpenRead(link));
Bitmap dest = new Bitmap(70, 70);
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
using (Graphics g = Graphics.FromImage(dest))
{
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
using ImageAttributes wrapMode = new ImageAttributes();
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height,
GraphicsUnit.Pixel, wrapMode);
}
using Image image = Image.Load(client.OpenRead(link));
image.Mutate(x => x.Resize(70, 70));
using MemoryStream ms = new MemoryStream();
dest.Save(ms, ImageFormat.Png);
image.SaveAsPng(ms);
return Convert.ToBase64String(ms.ToArray());
}
@ -108,8 +93,7 @@ namespace Installer
public object GetDefaultIcon() => 0;
public object ImageFromB64(string b64) =>
(Bitmap) new ImageConverter().ConvertFrom(Convert.FromBase64String(b64));
public object ImageFromB64(string b64) => 0;
public void Log(string text) => Console.WriteLine(text);
}

View File

@ -21,6 +21,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolLib", "UpToolLib\UpTo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolCLI", "UpToolCLI\UpToolCLI.csproj", "{3EC369B9-D927-4A53-BE1A-7E7006081BCE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GUI", "GUI", "{EA919DFD-766B-423C-99DF-C99356592842}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CLI", "CLI", "{3CFAB991-C12A-4B51-BC91-6965133DAF53}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{0E778462-504C-4183-A27E-44EEE7B8CCDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InstallerCLI", "InstallerCLI\InstallerCLI.csproj", "{493B2CC5-29E9-4F10-A2F5-E10B9584D667}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -47,6 +55,10 @@ Global
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Release|Any CPU.Build.0 = Release|Any CPU
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Debug|Any CPU.Build.0 = Debug|Any CPU
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Release|Any CPU.ActiveCfg = Release|Any CPU
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -54,4 +66,12 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {008127DC-F473-4709-A763-75F5FCED93AB}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FACD621F-6C6D-4D4B-B322-4364A0F9B4C2} = {0E778462-504C-4183-A27E-44EEE7B8CCDD}
{AAB8D6BA-3A43-4DC4-95EE-6757482B77FD} = {0E778462-504C-4183-A27E-44EEE7B8CCDD}
{C0C1E002-9E13-4E8F-A035-DBDC5128E00E} = {EA919DFD-766B-423C-99DF-C99356592842}
{3EC369B9-D927-4A53-BE1A-7E7006081BCE} = {3CFAB991-C12A-4B51-BC91-6965133DAF53}
{1D273392-3796-4BE9-A67F-BB402315D52D} = {EA919DFD-766B-423C-99DF-C99356592842}
{493B2CC5-29E9-4F10-A2F5-E10B9584D667} = {3CFAB991-C12A-4B51-BC91-6965133DAF53}
EndGlobalSection
EndGlobal

View File

@ -222,7 +222,7 @@ namespace UpTool2
Process.Start(new ProcessStartInfo
{
FileName = PathTool.GetRelative("Install", "tmp", "Installer.exe"),
Arguments = "-i",
Arguments = "i -p",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = PathTool.GetRelative("Install")

View File

@ -111,6 +111,11 @@ namespace UpToolCLI
rootCommand.AddCommand(start);
return rootCommand.InvokeAsync(args).Result;
}
catch (Exception e)
{
Console.WriteLine($"FAILED: {e}");
return 1;
}
finally
{
MutexLock.Unlock();
@ -153,7 +158,7 @@ Online: {UpdateCheck.InstallerHash}");
Process.Start(new ProcessStartInfo
{
FileName = file,
Arguments = "-i",
Arguments = "i",
WorkingDirectory = PathTool.GetRelative("Install"),
UseShellExecute = false
});