Fix some stuff
This commit is contained in:
parent
d7306150e8
commit
101ea5843a
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,10 @@
|
|||
<AssemblyName>uptool</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>..\UpTool2.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20158.1" />
|
||||
|
|
|
@ -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,6 +30,8 @@ namespace UpToolLib.Tool
|
|||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
if (File.Exists(Path.Combine(app.appPath, "package.zip")))
|
||||
{
|
||||
ZipFile.ExtractToDirectory(Path.Combine(app.appPath, "package.zip"), tmp);
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
|
@ -41,11 +43,12 @@ namespace UpToolLib.Tool
|
|||
}).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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 (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);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user