Fix major issue

This commit is contained in:
CreepyCrafter24 2020-03-24 23:14:40 +01:00
parent 18c8419495
commit 86009c2d88
4 changed files with 82 additions and 13 deletions

16
CLI.md
View File

@ -1,15 +1,15 @@
# CLI
Updating the cache: uptool update
Installing a package: uptool install <package>
Installing a package: uptool install \<package>
Upgrading a package: uptool upgrade <package>
Upgrading a package: uptool upgrade \<package>
Reinstalling a package: uptool reinstall <package>
Reinstalling a package: uptool reinstall \<package>
Removing a package: uptool remove <package>
Removing a package: uptool remove \<package>
Removing a package and all its configuration and data files: uptool purge <package>
Removing a package and all its configuration and data files: uptool purge \<package>
@ -17,6 +17,8 @@ List installed packages: uptool list
Upgrade all packages: uptool dist-upgrade
Search for a package: uptool search <text>
Search for a package: uptool search \<text>
Show package info: uptool show <package>
Show package info: uptool show \<package>
Start an app: uptool start \<package>

View File

@ -1,5 +1,11 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Xml.Linq;
namespace Installer
{
@ -9,15 +15,50 @@ namespace Installer
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
private static void Main(string[] args)
{
MutexLock.Lock();
try
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new InstallerForm());
if (!args.Any(s => new[] {"install", "i"}.Contains(s.TrimStart('-', '/').ToLower())))
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new InstallerForm());
}
else
{
WebClient client = new WebClient();
Console.WriteLine("Downloading metadata");
XElement meta = XDocument.Load("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml")
.Element("meta");
Console.WriteLine("Downloading binary");
byte[] dl = client.DownloadData(meta.Element("File").Value);
Console.WriteLine("Verifying integrity");
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
{
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
if (pkgHash != meta.Element("Hash").Value.ToUpper())
throw new Exception(
$"The hash is not equal to the one stored in the repo:\r\nPackage: {pkgHash}\r\nOnline: {meta.Element("Hash").Value.ToUpper()}");
}
Console.WriteLine("Extracting");
if (Directory.Exists(PathTool.GetRelative("Install")))
Directory.Delete(PathTool.GetRelative("Install"), 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"),
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"));
}
}
finally
{

View File

@ -85,6 +85,13 @@ namespace UpToolCLI
show.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
rootCommand.AddCommand(show);
Command start = new Command("start", "Starts an app")
{
Handler = CommandHandler.Create<string>(Show)
};
start.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
rootCommand.AddCommand(start);
return rootCommand.InvokeAsync(args).Result;
}
finally
@ -258,5 +265,24 @@ namespace UpToolCLI
}
Console.WriteLine("Done!");
}
private static void Start(string identifier, bool waitForExit)
{
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
Console.WriteLine($"Starting {tmp.Name}");
System.Diagnostics.Process tmp1 = AppExtras.RunApp(tmp);
if (waitForExit)
tmp1.WaitForExit();
}
Console.WriteLine("Done!");
}
}
}

View File

@ -116,7 +116,7 @@ Online: {appI.Hash.ToUpper()}");
}
else
{
CopyAll(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app", "Data"));
CopyAll(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
Directory.Delete(Path.Combine(tmp, "Data"), true);
}
XElement el = new XElement("app", new XElement("Name", name), new XElement("Description", description),