Fix some stuff

This commit is contained in:
CreepyCrafter24 2020-03-24 21:27:41 +01:00
parent d7306150e8
commit 101ea5843a
5 changed files with 79 additions and 38 deletions

View File

@ -51,7 +51,7 @@ namespace UpTool2
try
{
#endif
AppInstall.Install((App) action_install.Tag);
AppInstall.Install((App) action_install.Tag, true);
ReloadElements();
trying = false;
#if !DEBUG
@ -91,7 +91,7 @@ namespace UpTool2
id = Guid.NewGuid();
App appI = new App(AppNameDialog.Show(), "Locally installed package, removal only",
GlobalVariables.minimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, "");
AppInstall.InstallZip(searchPackageDialog.FileName, appI);
AppInstall.InstallZip(searchPackageDialog.FileName, appI, true);
#if !DEBUG
}
catch (Exception e1)
@ -173,7 +173,7 @@ namespace UpTool2
{
try
{
AppExtras.Update((App) action_install.Tag);
AppExtras.Update((App) action_install.Tag, false);
}
catch (Exception e1)
{

View File

@ -22,23 +22,26 @@ namespace UpToolCLI
Command install = new Command("install", "Install a package")
{
Handler = CommandHandler.Create<string>(Install)
Handler = CommandHandler.Create<string, bool>(Install)
};
install.AddOption(new Option<string>(new[] { "--identifier", "-i" }, "Something to identify the app"));
install.AddOption(new Option<bool>(new[] { "--force", "-f" }, "Overwrites older files"));
rootCommand.AddCommand(install);
Command upgrade = new Command("upgrade", "Upgrade a package")
{
Handler = CommandHandler.Create<string>(Upgrade)
Handler = CommandHandler.Create<string, bool>(Upgrade)
};
upgrade.AddOption(new Option<string>(new[] { "--identifier", "-i" }, "Something to identify the app"));
upgrade.AddOption(new Option<bool>(new[] { "--force", "-f" }, "Overwrites older files"));
rootCommand.AddCommand(upgrade);
Command reinstall = new Command("reinstall", "Reinstall a package")
{
Handler = CommandHandler.Create<string>(Reinstall)
Handler = CommandHandler.Create<string, bool>(Reinstall)
};
reinstall.AddOption(new Option<string>(new[] { "--identifier", "-i" }, "Something to identify the app"));
reinstall.AddOption(new Option<bool>(new[] { "--force", "-f" }, "Overwrites older files"));
rootCommand.AddCommand(reinstall);
Command remove = new Command("remove", "Remove a package")
@ -109,8 +112,9 @@ namespace UpToolCLI
foreach (KeyValuePair<Guid, App> app in GlobalVariables.Apps.Where(s => (s.Value.status & Status.Updatable) == Status.Updatable))
{
Console.WriteLine($"Updating {app.Value.Name}");
AppExtras.Update(app.Value);
AppExtras.Update(app.Value, false);
}
Console.WriteLine("Done!");
}
private static void Show(string identifier)
@ -132,7 +136,7 @@ namespace UpToolCLI
Console.WriteLine($"{apps[i].Name} ({apps[i].Id}");
}
private static void Upgrade(string identifier)
private static void Upgrade(string identifier, bool force)
{
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
@ -144,14 +148,15 @@ namespace UpToolCLI
if ((tmp.status & Status.Updatable) == Status.Updatable)
{
Console.WriteLine($"Upgrading {tmp.Name}");
AppExtras.Update(tmp);
AppExtras.Update(tmp, force);
}
else
Console.WriteLine("Package is up-to-date");
}
Console.WriteLine("Done!");
}
private static void Reinstall(string identifier)
private static void Reinstall(string identifier, bool force)
{
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
@ -161,8 +166,9 @@ namespace UpToolCLI
{
App tmp = apps.First();
Console.WriteLine($"Reinstalling {tmp.Name}");
AppExtras.Update(tmp);
AppExtras.Update(tmp, force);
}
Console.WriteLine("Done!");
}
private static void Remove(string identifier)
@ -182,6 +188,7 @@ namespace UpToolCLI
else
Console.WriteLine("Package is not installed");
}
Console.WriteLine("Done!");
}
private static void Purge(string identifier)
@ -201,9 +208,10 @@ namespace UpToolCLI
else
Console.WriteLine("Package is not installed");
}
Console.WriteLine("Done!");
}
private static void Install(string identifier)
private static void Install(string identifier, bool force)
{
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
@ -217,9 +225,10 @@ namespace UpToolCLI
else
{
Console.WriteLine($"Installing {tmp.Name}");
AppInstall.Install(tmp);
AppInstall.Install(tmp, true);
}
}
Console.WriteLine("Done!");
}
}
}

View File

@ -5,6 +5,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>uptool</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>..\UpTool2.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />

View File

@ -18,10 +18,10 @@ namespace UpToolLib.Tool
WorkingDirectory = app.dataPath
});
public static void Update(App app)
public static void Update(App app, bool overwrite)
{
Remove(app, false);
AppInstall.Install(app);
Remove(app, overwrite);
AppInstall.Install(app, overwrite);
}
public static void Remove(App app, bool deleteAll)
@ -30,22 +30,25 @@ namespace UpToolLib.Tool
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
ZipFile.ExtractToDirectory(Path.Combine(app.appPath, "package.zip"), tmp);
Process.Start(new ProcessStartInfo
if (File.Exists(Path.Combine(app.appPath, "package.zip")))
{
FileName = "cmd.exe",
Arguments = $"/C \"{Path.Combine(tmp, "Remove.bat")}\"",
WorkingDirectory = Path.Combine(app.appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
if (!deleteAll) CheckDirecory(Path.Combine(tmp, "Data"), app.dataPath);
Directory.Delete(tmp, true);
ZipFile.ExtractToDirectory(Path.Combine(app.appPath, "package.zip"), tmp);
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C \"{Path.Combine(tmp, "Remove.bat")}\"",
WorkingDirectory = Path.Combine(app.appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
if (!deleteAll) CheckDirecory(Path.Combine(tmp, "Data"), app.dataPath);
Directory.Delete(tmp, true);
}
if (File.Exists(app.infoPath))
File.Delete(app.infoPath);
if (File.Exists(Path.Combine(app.appPath, "package.zip")))
File.Delete(Path.Combine(app.appPath, "package.zip"));
if (deleteAll || Directory.GetFiles(app.dataPath).Length + Directory.GetDirectories(app.dataPath).Length == 0)
if (deleteAll || (Directory.Exists(app.dataPath) && Directory.GetFiles(app.dataPath).Length + Directory.GetDirectories(app.dataPath).Length == 0))
Directory.Delete(app.appPath, true);
}

View File

@ -14,8 +14,8 @@ namespace UpToolLib.Tool
/// Install an application
/// </summary>
/// <param name="appI">The app to install</param>
/// <param name="download">A method to download files. Input: app file, Outputs: whether the download was successful and the data</param>
public static void Install(App appI)
/// <param name="force">Set to true to overwrite all old data</param>
public static void Install(App appI, bool force)
{
string app = "";
string tmp = "";
@ -28,9 +28,17 @@ namespace UpToolLib.Tool
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
if (Directory.Exists(app))
Directory.Delete(app, true);
Directory.CreateDirectory(app);
if (force)
{
if (Directory.Exists(app))
Directory.Delete(app, true);
Directory.CreateDirectory(app);
}
else
{
if (!Directory.Exists(app))
Directory.CreateDirectory(app);
}
(bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.instance.Download(new Uri(appI.File));
if (!dlSuccess)
throw new Exception("Download failed");
@ -44,7 +52,7 @@ Package: {pkgHash}
Online: {appI.Hash.ToUpper()}");
}
File.WriteAllBytes(Path.Combine(app, "package.zip"), dlData);
CompleteInstall(appI);
CompleteInstall(appI, force);
#if !DEBUG
}
catch
@ -63,7 +71,7 @@ Online: {appI.Hash.ToUpper()}");
#endif
}
public static void InstallZip(string zipPath, App meta)
public static void InstallZip(string zipPath, App meta, bool force)
{
string app = "";
string tmp = "";
@ -76,7 +84,7 @@ Online: {appI.Hash.ToUpper()}");
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
File.Copy(zipPath, Path.Combine(app, "package.zip"));
CompleteInstall(meta);
CompleteInstall(meta, force);
}
catch
{
@ -94,13 +102,19 @@ Online: {appI.Hash.ToUpper()}");
//Use
//PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Hello World')"
//for message boxes
private static void CompleteInstall(App app) => CompleteInstall(app.appPath, app.Name, app.Description, app.Version, app.MainFile);
private static void CompleteInstall(App app, bool force) => CompleteInstall(app.appPath, app.Name, app.Description, app.Version, app.MainFile, force);
private static void CompleteInstall(string appPath, string name, string description, Version version, string mainFile)
private static void CompleteInstall(string appPath, string name, string description, Version version, string mainFile, bool force)
{
string tmp = PathTool.tempPath;
ZipFile.ExtractToDirectory(Path.Combine(appPath, "package.zip"), tmp);
Directory.Move(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
if (force)
Directory.Move(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
else
{
CopyAll(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app", "Data"));
Directory.Delete(Path.Combine(tmp, "Data"), true);
}
XElement el = new XElement("app", new XElement("Name", name), new XElement("Description", description),
new XElement("Version", version));
if (mainFile != null)
@ -115,5 +129,16 @@ Online: {appI.Hash.ToUpper()}");
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
}
private static void CopyAll(string source, string target)
{
if (string.Equals(Path.GetFullPath(source), Path.GetFullPath(target), StringComparison.CurrentCultureIgnoreCase))
return;
if (!Directory.Exists(target))
Directory.CreateDirectory(target);
foreach (string file in Directory.GetFiles(source)) File.Copy(file, Path.Combine(target, Path.GetFileName(file)), true);
foreach (string dir in Directory.GetDirectories(source))
CopyAll(dir, Path.Combine(target, Path.GetFileName(dir)));
}
}
}