diff --git a/CLI.md b/CLI.md index fae6efa..565c2b3 100644 --- a/CLI.md +++ b/CLI.md @@ -1,7 +1,7 @@ # CLI Updating the cache: uptool update -Installing a package: uptool install \ +Installing a package (set \ to a file for local): uptool install \ Upgrading a package: uptool upgrade \ diff --git a/Installer/InstallerForm.cs b/Installer/InstallerForm.cs index 01653be..37789ac 100644 --- a/Installer/InstallerForm.cs +++ b/Installer/InstallerForm.cs @@ -14,13 +14,13 @@ namespace Installer { public partial class InstallerForm : Form { - private string Log = ""; + private string _log = ""; public InstallerForm() { InitializeComponent(); Step(0, "Initialized"); - Log.TrimStart(Environment.NewLine.ToCharArray()); + _log.TrimStart(Environment.NewLine.ToCharArray()); } private void install_Click(object sender, EventArgs e) @@ -54,10 +54,10 @@ namespace Installer } Step(5, "Creating shortcut"); Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); + System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); Step(6, "Creating PATH entry"); - if (!PATH.Content.Contains(PATH.GetName(PathTool.GetRelative("Install")))) - PATH.Append(PathTool.GetRelative("Install")); + if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install")))) + Path.Append(PathTool.GetRelative("Install")); Step(7, "Done!"); } catch (Exception ex) @@ -85,9 +85,9 @@ namespace Installer { progress.Value = p; processLabel.Text = text; - Log += $"{Environment.NewLine}[{DateTime.Now.ToString(CultureInfo.InvariantCulture).Split(' ')[1]}] {text}"; + _log += $"{Environment.NewLine}[{DateTime.Now.ToString(CultureInfo.InvariantCulture).Split(' ')[1]}] {text}"; } - private void log_Click(object sender, EventArgs e) => new Thread(() => MessageBox.Show(Log)).Start(); + private void log_Click(object sender, EventArgs e) => new Thread(() => MessageBox.Show(_log)).Start(); } } \ No newline at end of file diff --git a/Installer/PATH.cs b/Installer/PATH.cs index df10404..7c33388 100644 --- a/Installer/PATH.cs +++ b/Installer/PATH.cs @@ -4,7 +4,7 @@ using System.Linq; namespace Installer { - public static class PATH + public static class Path { public static string[] Content { @@ -15,6 +15,6 @@ namespace Installer public static void Append(string path, bool escape = true) => Content = Content.Append(escape ? GetName(path) : path).ToArray(); - public static string GetName(string path) => Path.GetFullPath(path); + public static string GetName(string path) => System.IO.Path.GetFullPath(path); } } \ No newline at end of file diff --git a/Installer/PathTool.cs b/Installer/PathTool.cs index a4d54e1..da81767 100644 --- a/Installer/PathTool.cs +++ b/Installer/PathTool.cs @@ -6,14 +6,14 @@ namespace Installer { internal static class PathTool { - public static string dir => - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2"); + public static string Dir => + System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2"); - public static string tempPath => GetRelative("tmp"); - public static string appsPath => GetRelative("Apps"); + public static string TempPath => GetRelative("tmp"); + public static string AppsPath => GetRelative("Apps"); public static string InfoXml => GetRelative("info.xml"); public static string GetRelative(params string[] segments) => - Path.Combine(new[] {dir}.Concat(segments).ToArray()); + System.IO.Path.Combine(new[] {Dir}.Concat(segments).ToArray()); } } \ No newline at end of file diff --git a/Installer/Program.cs b/Installer/Program.cs index 039f45c..52a2bf2 100644 --- a/Installer/Program.cs +++ b/Installer/Program.cs @@ -54,10 +54,10 @@ namespace Installer } Console.WriteLine("Creating shortcut"); Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); + 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")); + if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install")))) + Path.Append(PathTool.GetRelative("Install")); } } finally diff --git a/UpTool build tool/BatchScripts.cs b/UpTool build tool/BatchScripts.cs new file mode 100644 index 0000000..c15dbf1 --- /dev/null +++ b/UpTool build tool/BatchScripts.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; + +namespace UpTool_build_tool +{ + internal static class BatchScripts + { + public static Tuple Create(bool shortcuts, string? mainBin, string programName, string? postInstall, string? postRemove) + { + string installBat = "@echo off\r\necho INSTALL"; + string removeBat = "@echo off\r\necho REMOVE"; + if (shortcuts) + { + installBat += "\r\n"; + installBat += + $@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}';$s.Save()"""; + removeBat += "\r\n"; + removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk"""; + } + if (!string.IsNullOrWhiteSpace(mainBin)) + { + removeBat += "\r\n"; + removeBat += $@"taskkill /f /im ""{Path.GetFileName(mainBin)}"""; + } + installBat += $"\r\n{postInstall}"; + removeBat += $"\r\n{postRemove}"; + return new Tuple(installBat, removeBat); + } + } +} \ No newline at end of file diff --git a/UpTool build tool/Program.cs b/UpTool build tool/Program.cs index 19be541..ff93aa4 100644 --- a/UpTool build tool/Program.cs +++ b/UpTool build tool/Program.cs @@ -14,24 +14,26 @@ namespace UpTool_build_tool public static int Main(string[] args) { RootCommand rootCommand = new RootCommand(); - Command build = new Command("build", "Builds a generic package with or without shortcuts from a directory"); - build.AddOption(new Option("--binDir", "Directory to package")); - build.AddOption(new Option("--mainBin", "The applications main binary")); - build.AddOption(new Option("--packageFile", "Directory to package")); - build.AddOption(new Option("--postInstall", () => "", - "Command(s) to run after installing the package")); - build.AddOption( - new Option("--postRemove", () => "", "Command(s) to run after removing the package")); - build.AddOption(new Option("--noLogo", "Disables the logo")); - build.AddOption(new Option("--noShortcuts", - "When this is enabled the scripts will not generate a start-menu item")); - build.Handler = CommandHandler.Create(Build); + Command build = new Command("build", "Builds a generic package with or without shortcuts from a directory") + { + new Option("--binDir", "Directory to package"), + new Option("--mainBin", () => "FIND_BIN", "The applications main binary"), + new Option("--packageFile", "Directory to package"), + new Option("--postInstall", () => "", "Command(s) to run after installing the package (This will be pasted into the .bat AND .sh file)"), + new Option("--postRemove", () => "", "Command(s) to run after removing the package (This will be pasted into the .bat AND .sh file)"), + new Option("--noLogo", "Disables the logo"), + new Option("--noShortcuts", + "When this is enabled the scripts will not generate a start-menu item"), + new Option("--noWine", + "This indicates that your program supports multiple platforms natively and doesn't require WINE") + }; + build.Handler = CommandHandler.Create((Action)Build); rootCommand.AddCommand(build); return rootCommand.InvokeAsync(args).Result; } private static void Build(string binDir, string mainBin, string packageFile, string postInstall, - string postRemove, bool noLogo, bool noShortcuts) + string postRemove, bool noLogo, bool noShortcuts, bool noWine) { Stopwatch watch = Stopwatch.StartNew(); if (!noLogo) @@ -55,9 +57,7 @@ namespace UpTool_build_tool { archive.AddDirectory(binDir, "Data", new[] {".xml", ".pdb"}, new[] {packageFile}); Console.WriteLine("Creating batch scripts..."); - string installBat = "@echo off\r\necho INSTALL"; - string removeBat = "@echo off\r\necho REMOVE"; - if (string.IsNullOrWhiteSpace(mainBin)) + if (mainBin == "FIND_BIN") { string[] tmp = Directory.GetFiles(binDir, "*.exe"); if (tmp.Length > 0) @@ -71,35 +71,22 @@ namespace UpTool_build_tool } } string programName = Path.GetFileNameWithoutExtension(mainBin); - if (!noShortcuts) - { - installBat += "\r\n"; - installBat += - $@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}';$s.Save()"""; - removeBat += "\r\n"; - removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk"""; - } - if (!string.IsNullOrWhiteSpace(mainBin)) - { - removeBat += "\r\n"; - removeBat += $@"taskkill /f /im ""{Path.GetFileName(mainBin)}"""; - } - installBat += $"\r\n{postInstall}"; - removeBat += $"\r\n{postRemove}"; - using (Stream s = archive.CreateEntry("Install.bat").Open()) - { - using StreamWriter writer = new StreamWriter(s); - writer.Write(installBat); - } - using (Stream s = archive.CreateEntry("Remove.bat").Open()) - { - using StreamWriter writer = new StreamWriter(s); - writer.Write(removeBat); - } + (string installBat, string removeBat) = BatchScripts.Create(!noShortcuts, mainBin, programName, postInstall, postRemove); + archive.AddFile("Install.bat", installBat); + archive.AddFile("Remove.bat", removeBat); + ShScripts.Create(archive.AddFile, !noShortcuts, mainBin, programName, postInstall, postRemove, !noWine); + } watch.Stop(); Console.WriteLine($"Completed package creation in {watch.Elapsed}"); Console.WriteLine($"Output file: {Path.GetFullPath(packageFile)}"); } + + private static void AddFile(this ZipArchive archive, string fileName, string content) + { + using Stream s = archive.CreateEntry(fileName).Open(); + using StreamWriter writer = new StreamWriter(s); + writer.Write(content); + } } } \ No newline at end of file diff --git a/UpTool build tool/Properties/AssemblyInfo.cs b/UpTool build tool/Properties/AssemblyInfo.cs deleted file mode 100644 index 97290d1..0000000 --- a/UpTool build tool/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("UpTool_build_tool")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UpTool_build_tool")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("AAB8D6BA-3A43-4DC4-95EE-6757482B77FD")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/UpTool build tool/ShScripts.cs b/UpTool build tool/ShScripts.cs new file mode 100644 index 0000000..0f0f33d --- /dev/null +++ b/UpTool build tool/ShScripts.cs @@ -0,0 +1,39 @@ +using System; +using System.Text.RegularExpressions; + +namespace UpTool_build_tool +{ + internal static class ShScripts + { + public static void Create(Action fileSave, bool shortcuts, string? mainBin, string programName, string? postInstall, string? postRemove, bool wine) + { + Regex rgx = new Regex("[^a-z0-9]"); + Regex upRgx = new Regex("[^a-zA-Z0-9 -]"); + string lnkName = $"~/.local/share/applications/{rgx.Replace(programName.ToLower(), "")}.desktop"; + string installSh = "#!/bin/bash\necho INSTALL"; + string removeSh = "#!/bin/bash\necho REMOVE"; + if (shortcuts) + { + installSh += $@" +echo ""[Desktop Entry]"" > {lnkName} +echo ""Exec={(wine ? "wine " : "")}{mainBin}"" >> {lnkName} +echo ""Icon=application/x-shellscript"" >> {lnkName} +echo ""Name={upRgx.Replace(programName, "")}"" >> {lnkName} +echo ""StartupNotify=false"" >> {lnkName} +echo ""Terminal=false"" >> {lnkName} +echo ""Type=Application"" >> {lnkName}"; + removeSh += "\r\n"; + removeSh += $@"rm {lnkName}"; + } + if (!string.IsNullOrWhiteSpace(mainBin)) + { + removeSh += "\r\n"; + removeSh += $@"pkill -f ""{mainBin}"""; + } + installSh += $"\r\n{postInstall}"; + removeSh += $"\r\n{postRemove}"; + fileSave("Install.sh", installSh); + fileSave("Remove.sh", removeSh); + } + } +} \ No newline at end of file diff --git a/UpTool build tool/UpTool build tool.csproj b/UpTool build tool/UpTool build tool.csproj index 2e3ff5a..190c210 100644 --- a/UpTool build tool/UpTool build tool.csproj +++ b/UpTool build tool/UpTool build tool.csproj @@ -7,10 +7,10 @@ false 8 enable - false + 1.0.* - .\pkgtool.exe build --noLogo --noShortcuts --binDir . + .\pkgtool build --noLogo --noShortcuts --binDir . --mainBin "" ..\UpTool2.ico diff --git a/UpTool2/MainForm.Designer.cs b/UpTool2/MainForm.Designer.cs index 768faca..7e36675 100644 --- a/UpTool2/MainForm.Designer.cs +++ b/UpTool2/MainForm.Designer.cs @@ -221,7 +221,7 @@ this.ResumeLayout(false); } - #endregion +#endregion private System.Windows.Forms.FlowLayoutPanel sidebarPanel; private System.Windows.Forms.Panel infoPanel; diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index e070b4a..c6b3663 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -39,8 +39,8 @@ namespace UpTool2 } Program.SetSplash(8, "Reloading data"); ReloadElements(); - if (!Directory.Exists(PathTool.appsPath)) - Directory.CreateDirectory(PathTool.appsPath); + if (!Directory.Exists(PathTool.AppsPath)) + Directory.CreateDirectory(PathTool.AppsPath); } private void Action_install_Click(object sender, EventArgs e) @@ -91,7 +91,7 @@ namespace UpTool2 while (GlobalVariables.Apps.ContainsKey(id) || Directory.Exists(PathTool.GetAppPath(id))) 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, ""); + GlobalVariables.MinimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, ""); AppInstall.InstallZip(searchPackageDialog.FileName, appI, true); #if !DEBUG } @@ -109,8 +109,8 @@ namespace UpTool2 ClearSelection(); infoPanel_Title.Invalidate(); infoPanel_Description.Invalidate(); - int F = sidebarPanel.Controls.Count; - for (int i = 0; i < F; i++) sidebarPanel.Controls[0].Dispose(); + int f = sidebarPanel.Controls.Count; + for (int i = 0; i < f; i++) sidebarPanel.Controls[0].Dispose(); GlobalVariables.Apps.Clear(); //add toolTip.SetToolTip(controls_settings, "Settings"); @@ -133,21 +133,21 @@ namespace UpTool2 BackgroundImage = (Bitmap) app.Icon, BackgroundImageLayout = ImageLayout.Stretch }; - bool updateable = !app.Local && (app.status & Status.Updatable) == Status.Updatable; + bool updateable = !app.Local && (app.Status & Status.Updatable) == Status.Updatable; sidebarIcon.Click += (sender, e) => { infoPanel_Title.Text = app.Name; infoPanel_Title.ForeColor = app.Local ? Color.Red : Color.Black; infoPanel_Description.Text = app.Description; action_install.Tag = app; - action_install.Enabled = !(app.Local || Directory.Exists(app.appPath)); + action_install.Enabled = !(app.Local || Directory.Exists(app.AppPath)); action_remove.Tag = app; - action_remove.Enabled = Directory.Exists(app.appPath); + action_remove.Enabled = Directory.Exists(app.AppPath); action_update.Tag = app; action_update.Enabled = updateable; action_run.Tag = app; - action_run.Enabled = (app.status & Status.Installed) == Status.Installed && !app.Local && - app.Runnable && Directory.Exists(app.appPath); + action_run.Enabled = (app.Status & Status.Installed) == Status.Installed && !app.Local && + app.Runnable && Directory.Exists(app.AppPath); }; if (updateable) availableUpdates++; @@ -229,7 +229,7 @@ namespace UpTool2 Panel sidebarIcon = (Panel) sidebarPanel.Controls[i]; App app = (App) sidebarIcon.Tag; sidebarIcon.Visible = apps.Contains(app) && - ((int) app.status & (int) (Program.Online ? status : Status.Installed)) != 0; + ((int) app.Status & (int) (Program.Online ? status : Status.Installed)) != 0; } ClearSelection(); #if DEBUG diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 0d4107f..88eabd9 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -19,8 +19,8 @@ namespace UpTool2 internal static class Program { public static Form Splash; - private static int SplashProgress; - private static string SplashMessage; + private static int _splashProgress; + private static string _splashMessage; public static bool Online; [STAThread] @@ -47,10 +47,10 @@ namespace UpTool2 try { #endif - ExternalFunctionalityManager.Init(new UTLibFunctions()); + ExternalFunctionalityManager.Init(new UtLibFunctions()); SetSplash(1, "Initializing paths"); - if (!Directory.Exists(PathTool.dir)) - Directory.CreateDirectory(PathTool.dir); + if (!Directory.Exists(PathTool.Dir)) + Directory.CreateDirectory(PathTool.Dir); FixXml(); SetSplash(2, "Performing checks"); string metaXml = XDocument.Load(PathTool.InfoXml).Element("meta").Element("UpdateSource").Value; @@ -135,10 +135,10 @@ namespace UpTool2 20); g.FillRectangle(Brushes.Gray, bar); g.FillRectangle(Brushes.Black, - new Rectangle(bar.X, bar.Y, (bar.Width * SplashProgress) / 10, bar.Height)); + new Rectangle(bar.X, bar.Y, (bar.Width * _splashProgress) / 10, bar.Height)); g.DrawRectangle(Pens.DimGray, bar); //g.DrawString(SplashMessage, smallFont, Brushes.White, new PointF(bar.Left, bar.Bottom)); - g.DrawString(SplashMessage, smallFont, Brushes.White, bar, + g.DrawString(_splashMessage, smallFont, Brushes.White, bar, new StringFormat {Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center}); }; int xOff = 0; @@ -163,9 +163,9 @@ namespace UpTool2 public static void SetSplash(int progress, string status) => Splash.Invoke(new Action(() => { - SplashProgress = progress; + _splashProgress = progress; Console.WriteLine(status); - SplashMessage = status; + _splashMessage = status; Splash.Invoke((Action) Splash.Invalidate); })); diff --git a/UpTool2/SourcesForm.cs b/UpTool2/SourcesForm.cs index b010589..c1bda80 100644 --- a/UpTool2/SourcesForm.cs +++ b/UpTool2/SourcesForm.cs @@ -6,29 +6,29 @@ namespace UpTool2 { public partial class SettingsForms : Form { - private readonly XDocument doc; - private readonly XElement meta; - private readonly XElement repos; + private readonly XDocument _doc; + private readonly XElement _meta; + private readonly XElement _repos; public SettingsForms() { InitializeComponent(); Program.FixXml(); - doc = XDocument.Load(PathTool.InfoXml); - meta = doc.Element("meta"); - repos = meta.Element("Repos"); - foreach (XElement repo in repos.Elements("Repo")) + _doc = XDocument.Load(PathTool.InfoXml); + _meta = _doc.Element("meta"); + _repos = _meta.Element("Repos"); + foreach (XElement repo in _repos.Elements("Repo")) sourceGrid.Rows.Add(repo.Element("Name").Value, repo.Element("Link").Value); } private void SettingsForms_FormClosing(object sender, FormClosingEventArgs e) { - repos.RemoveNodes(); + _repos.RemoveNodes(); for (int y = 0; y < sourceGrid.Rows.Count; y++) if (y + 1 < sourceGrid.Rows.Count) - repos.Add(new XElement("Repo", new XElement("Name", (string) sourceGrid.Rows[y].Cells[0].Value), + _repos.Add(new XElement("Repo", new XElement("Name", (string) sourceGrid.Rows[y].Cells[0].Value), new XElement("Link", (string) sourceGrid.Rows[y].Cells[1].Value))); - doc.Save(PathTool.InfoXml); + _doc.Save(PathTool.InfoXml); } } } \ No newline at end of file diff --git a/UpTool2/UTLibFunctions.cs b/UpTool2/UTLibFunctions.cs index b542d0e..0ed173c 100644 --- a/UpTool2/UTLibFunctions.cs +++ b/UpTool2/UTLibFunctions.cs @@ -11,7 +11,7 @@ using UpToolLib.DataStructures; namespace UpTool2 { - internal class UTLibFunctions : IExternalFunctionality + internal class UtLibFunctions : IExternalFunctionality { public Tuple Download(Uri link) { @@ -47,7 +47,7 @@ namespace UpTool2 public bool YesNoDialog(string text, bool _) => MessageBox.Show(text, "", MessageBoxButtons.YesNo) == DialogResult.Yes; - public void OKDialog(string text) => MessageBox.Show(text); + public void OkDialog(string text) => MessageBox.Show(text); public object GetDefaultIcon() => Resources.C_64.ToBitmap(); public object ImageFromB64(string b64) => diff --git a/UpToolCLI/Program.cs b/UpToolCLI/Program.cs index 1889b32..b857e4d 100644 --- a/UpToolCLI/Program.cs +++ b/UpToolCLI/Program.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Invocation; +using System.Drawing; +using System.IO; using System.Linq; using UpToolLib; using UpToolLib.DataStructures; @@ -9,14 +11,15 @@ using UpToolLib.Tool; namespace UpToolCLI { - public class Program + public static class Program { public static int Main(string[] args) { MutexLock.Lock(); try { - ExternalFunctionalityManager.Init(new UTLibFunctions()); + XmlTool.FixXml(); + ExternalFunctionalityManager.Init(new UtLibFunctions()); RootCommand rootCommand = new RootCommand(); rootCommand.AddCommand(new Command("update", "Updates the cache") { @@ -25,40 +28,40 @@ namespace UpToolCLI Command install = new Command("install", "Install a package") { - Handler = CommandHandler.Create(Install) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app or the file name"), + new Option(new[] {"--force", "-f"}, "Overwrites older files") }; - install.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); - install.AddOption(new Option(new[] {"--force", "-f"}, "Overwrites older files")); + install.Handler = CommandHandler.Create(Install); rootCommand.AddCommand(install); Command upgrade = new Command("upgrade", "Upgrade a package") { - Handler = CommandHandler.Create(Upgrade) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app"), + new Option(new[] {"--force", "-f"}, "Overwrites older files") }; - upgrade.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); - upgrade.AddOption(new Option(new[] {"--force", "-f"}, "Overwrites older files")); + upgrade.Handler = CommandHandler.Create(Upgrade); rootCommand.AddCommand(upgrade); Command reinstall = new Command("reinstall", "Reinstall a package") { - Handler = CommandHandler.Create(Reinstall) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app"), + new Option(new[] {"--force", "-f"}, "Overwrites older files") }; - reinstall.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); - reinstall.AddOption(new Option(new[] {"--force", "-f"}, "Overwrites older files")); + reinstall.Handler = CommandHandler.Create(Reinstall); rootCommand.AddCommand(reinstall); Command remove = new Command("remove", "Remove a package") { - Handler = CommandHandler.Create(Remove) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app") }; - remove.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); + remove.Handler = CommandHandler.Create(Remove); rootCommand.AddCommand(remove); Command purge = new Command("purge", "Completely remove a package") { - Handler = CommandHandler.Create(Purge) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app") }; - purge.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); + purge.Handler = CommandHandler.Create(Purge); rootCommand.AddCommand(purge); rootCommand.AddCommand(new Command("list", "Lists installed packages") @@ -73,25 +76,25 @@ namespace UpToolCLI Command search = new Command("search", "Search for packages") { - Handler = CommandHandler.Create(Search) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app") }; - search.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); + search.Handler = CommandHandler.Create(Search); rootCommand.AddCommand(search); Command show = new Command("show", "Shows package info") { - Handler = CommandHandler.Create(Show) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app") }; - show.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); + show.Handler = CommandHandler.Create(Show); rootCommand.AddCommand(show); Command start = new Command("start", "Starts an app") { - Handler = CommandHandler.Create(Show) + new Option(new[] {"--identifier", "-i"}, "Something to identify the app"), + new Option(new[] {"--waitForExit", "-wait"}, "Waits until the program quits") }; - start.AddOption(new Option(new[] {"--identifier", "-i"}, "Something to identify the app")); + start.Handler = CommandHandler.Create(Start); rootCommand.AddCommand(start); - return rootCommand.InvokeAsync(args).Result; } finally @@ -107,7 +110,7 @@ namespace UpToolCLI RepoManagement.GetReposFromDisk(); Console.WriteLine(); IEnumerable tmp = GlobalVariables.Apps.Where(s => - (s.Value.status & Status.Updatable) == Status.Updatable).Select(s => s.Value); + (s.Value.Status & Status.Updatable) == Status.Updatable).Select(s => s.Value); IEnumerable apps = tmp as App[] ?? tmp.ToArray(); int updatableCount = apps.Count(); Console.WriteLine(updatableCount == 0 @@ -120,10 +123,10 @@ namespace UpToolCLI { RepoManagement.GetReposFromDisk(); foreach (KeyValuePair app in GlobalVariables.Apps.Where(s => - (s.Value.status & Status.Installed) == Status.Installed)) + (s.Value.Status & Status.Installed) == Status.Installed)) { - Console.BackgroundColor = (app.Value.status & Status.Local) == Status.Local ? ConsoleColor.DarkRed : - (app.Value.status & Status.Updatable) == Status.Updatable ? ConsoleColor.DarkGreen : + Console.BackgroundColor = (app.Value.Status & Status.Local) == Status.Local ? ConsoleColor.DarkRed : + (app.Value.Status & Status.Updatable) == Status.Updatable ? ConsoleColor.DarkGreen : ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{app.Value.Name} ({app.Key})"); @@ -135,7 +138,7 @@ namespace UpToolCLI { RepoManagement.GetReposFromDisk(); foreach (KeyValuePair app in GlobalVariables.Apps.Where(s => - (s.Value.status & Status.Updatable) == Status.Updatable)) + (s.Value.Status & Status.Updatable) == Status.Updatable)) { Console.WriteLine($"Updating {app.Value.Name}"); AppExtras.Update(app.Value, false); @@ -167,21 +170,17 @@ namespace UpToolCLI RepoManagement.GetReposFromDisk(); App[] apps = AppExtras.FindApps(identifier); if (apps.Length == 0) - { Console.WriteLine("Package not found."); - } else { App tmp = apps.First(); - if ((tmp.status & Status.Updatable) == Status.Updatable) + if ((tmp.Status & Status.Updatable) == Status.Updatable) { Console.WriteLine($"Upgrading {tmp.Name}"); AppExtras.Update(tmp, force); } else - { Console.WriteLine("Package is up-to-date"); - } } Console.WriteLine("Done!"); } @@ -191,9 +190,7 @@ namespace UpToolCLI RepoManagement.GetReposFromDisk(); App[] apps = AppExtras.FindApps(identifier); if (apps.Length == 0) - { Console.WriteLine("Package not found."); - } else { App tmp = apps.First(); @@ -208,21 +205,17 @@ namespace UpToolCLI RepoManagement.GetReposFromDisk(); App[] apps = AppExtras.FindApps(identifier); if (apps.Length == 0) - { Console.WriteLine("Package not found."); - } else { App tmp = apps.First(); - if ((tmp.status & Status.Installed) == Status.Installed) + if ((tmp.Status & Status.Installed) == Status.Installed) { Console.WriteLine($"Removing {tmp.Name}"); AppExtras.Remove(tmp, false); } else - { Console.WriteLine("Package is not installed"); - } } Console.WriteLine("Done!"); } @@ -232,21 +225,17 @@ namespace UpToolCLI RepoManagement.GetReposFromDisk(); App[] apps = AppExtras.FindApps(identifier); if (apps.Length == 0) - { Console.WriteLine("Package not found."); - } else { App tmp = apps.First(); - if ((tmp.status & Status.Installed) == Status.Installed) + if ((tmp.Status & Status.Installed) == Status.Installed) { Console.WriteLine($"Purgeing {tmp.Name}"); AppExtras.Remove(tmp, true); } else - { Console.WriteLine("Package is not installed"); - } } Console.WriteLine("Done!"); } @@ -257,15 +246,25 @@ namespace UpToolCLI App[] apps = AppExtras.FindApps(identifier); if (apps.Length == 0) { - Console.WriteLine("Package not found."); + if (File.Exists(identifier)) + { + Console.WriteLine("Name:"); + string name = Console.ReadLine(); + AppInstall.InstallZip(identifier, new App(name, "Locally installed package, removal only", GlobalVariables.MinimumVer, "", true, "", + Guid.NewGuid(), Color.Red, "", false, ""), force); + Console.WriteLine($"Successfully installed \"{name}\""); + } + else + { + Console.WriteLine("Package not found."); + Console.WriteLine(identifier); + } } else { App tmp = apps.First(); - if ((tmp.status & Status.Installed) == Status.Installed) - { + if ((tmp.Status & Status.Installed) == Status.Installed) Console.WriteLine("Package is already installed"); - } else { Console.WriteLine($"Installing {tmp.Name}"); @@ -280,16 +279,19 @@ namespace UpToolCLI 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(); + if (tmp.Runnable) + { + Console.WriteLine($"Starting {tmp.Name}"); + System.Diagnostics.Process tmp1 = AppExtras.RunApp(tmp); + if (waitForExit) + tmp1.WaitForExit(); + } + else + Console.WriteLine($"{tmp.Name} is not runnable"); } Console.WriteLine("Done!"); } diff --git a/UpToolCLI/UTLibFunctions.cs b/UpToolCLI/UTLibFunctions.cs index 0a26d46..51fe92e 100644 --- a/UpToolCLI/UTLibFunctions.cs +++ b/UpToolCLI/UTLibFunctions.cs @@ -8,7 +8,7 @@ using UpToolLib.DataStructures; namespace UpToolCLI { - public class UTLibFunctions : IExternalFunctionality + public class UtLibFunctions : IExternalFunctionality { public Tuple Download(Uri link) { @@ -82,7 +82,7 @@ namespace UpToolCLI return current; } - public void OKDialog(string text) + public void OkDialog(string text) { Console.WriteLine(text); Console.BackgroundColor = ConsoleColor.White; diff --git a/UpToolLib/DataStructures/App.cs b/UpToolLib/DataStructures/App.cs index d9dfe95..84ba6f4 100644 --- a/UpToolLib/DataStructures/App.cs +++ b/UpToolLib/DataStructures/App.cs @@ -38,13 +38,13 @@ namespace UpToolLib.DataStructures MainFile = mainFile ?? throw new ArgumentNullException(nameof(mainFile)); } - public Status status + public Status Status { get { - if (!System.IO.File.Exists(infoPath)) - return Status.Not_Installed; - if (Version.TryParse(XDocument.Load(infoPath).Element("app").Element("Version").Value, + if (!System.IO.File.Exists(InfoPath)) + return Status.NotInstalled; + if (Version.TryParse(XDocument.Load(InfoPath).Element("app").Element("Version").Value, out Version ver) && ver >= Version) return Local ? Status.Installed | Status.Local : Status.Installed; return Status.Installed | Status.Updatable; @@ -68,15 +68,15 @@ ID: {Id} Color: {Color.ToKnownColor()} Runnable: {Runnable} MainFile: {MainFile} -Status: {status} +Status: {Status} Object Hash Code: {GetHashCode()}"; public static bool operator ==(App left, App right) => left.Equals(right); public static bool operator !=(App left, App right) => !(left == right); - public string appPath => PathTool.GetAppPath(Id); - public string dataPath => PathTool.GetDataPath(Id); - public string infoPath => PathTool.GetInfoPath(Id); + public string AppPath => PathTool.GetAppPath(Id); + public string DataPath => PathTool.GetDataPath(Id); + public string InfoPath => PathTool.GetInfoPath(Id); } } \ No newline at end of file diff --git a/UpToolLib/DataStructures/IExternalFunctionality.cs b/UpToolLib/DataStructures/IExternalFunctionality.cs index 7ed41cd..4cf41e9 100644 --- a/UpToolLib/DataStructures/IExternalFunctionality.cs +++ b/UpToolLib/DataStructures/IExternalFunctionality.cs @@ -7,7 +7,7 @@ namespace UpToolLib.DataStructures public Tuple Download(Uri link); public string FetchImageB64(Uri link); public bool YesNoDialog(string text, bool defaultVal); - public void OKDialog(string text); + public void OkDialog(string text); public object GetDefaultIcon(); public object ImageFromB64(string b64); public void Log(string text); diff --git a/UpToolLib/DataStructures/Status.cs b/UpToolLib/DataStructures/Status.cs index 792bccc..d1ed9b9 100644 --- a/UpToolLib/DataStructures/Status.cs +++ b/UpToolLib/DataStructures/Status.cs @@ -5,7 +5,7 @@ namespace UpToolLib.DataStructures [Flags] public enum Status { - Not_Installed = 1, + NotInstalled = 1, Updatable = 2, Installed = 4, Local = 8, diff --git a/UpToolLib/ExternalFunctionalityManager.cs b/UpToolLib/ExternalFunctionalityManager.cs index 37f19c3..3135bdc 100644 --- a/UpToolLib/ExternalFunctionalityManager.cs +++ b/UpToolLib/ExternalFunctionalityManager.cs @@ -4,11 +4,11 @@ namespace UpToolLib { public static class ExternalFunctionalityManager { - internal static IExternalFunctionality instance; + internal static IExternalFunctionality Instance; public static void Init(IExternalFunctionality externalFunctionality) { - instance = externalFunctionality; + Instance = externalFunctionality; } } } \ No newline at end of file diff --git a/UpToolLib/GlobalVariables.cs b/UpToolLib/GlobalVariables.cs index e3031f2..ee73fb2 100644 --- a/UpToolLib/GlobalVariables.cs +++ b/UpToolLib/GlobalVariables.cs @@ -7,6 +7,6 @@ namespace UpToolLib public static class GlobalVariables { public static readonly Dictionary Apps = new Dictionary(); - public static Version minimumVer => Version.Parse("0.0.0.0"); + public static Version MinimumVer => Version.Parse("0.0.0.0"); } } \ No newline at end of file diff --git a/UpToolLib/Lock.cs b/UpToolLib/Lock.cs index 0f62346..14dfb27 100644 --- a/UpToolLib/Lock.cs +++ b/UpToolLib/Lock.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading; namespace UpToolLib diff --git a/UpToolLib/Properties/Resources.Designer.cs b/UpToolLib/Properties/Resources.Designer.cs deleted file mode 100644 index 3ad664b..0000000 --- a/UpToolLib/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace UpToolLib.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UpToolLib.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/UpToolLib/Properties/Resources.resx b/UpToolLib/Properties/Resources.resx deleted file mode 100644 index 4fdb1b6..0000000 --- a/UpToolLib/Properties/Resources.resx +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/UpToolLib/Tool/AppExtras.cs b/UpToolLib/Tool/AppExtras.cs index 9292180..36128eb 100644 --- a/UpToolLib/Tool/AppExtras.cs +++ b/UpToolLib/Tool/AppExtras.cs @@ -14,8 +14,8 @@ namespace UpToolLib.Tool Process.Start( new ProcessStartInfo { - FileName = Path.Combine(app.dataPath, app.MainFile), - WorkingDirectory = app.dataPath + FileName = Path.Combine(app.DataPath, app.MainFile), + WorkingDirectory = app.DataPath }); public static void Update(App app, bool overwrite) @@ -26,32 +26,61 @@ namespace UpToolLib.Tool public static void Remove(App app, bool deleteAll) { - string tmp = PathTool.tempPath; + string tmp = PathTool.TempPath; if (Directory.Exists(tmp)) Directory.Delete(tmp, true); Directory.CreateDirectory(tmp); - if (File.Exists(Path.Combine(app.appPath, "package.zip"))) + if (File.Exists(Path.Combine(app.AppPath, "package.zip"))) { - ZipFile.ExtractToDirectory(Path.Combine(app.appPath, "package.zip"), tmp); - Process.Start(new ProcessStartInfo + 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"), + WorkingDirectory = Path.Combine(app.AppPath, "app"), CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden - }).WaitForExit(); - if (!deleteAll) CheckDirecory(Path.Combine(tmp, "Data"), app.dataPath); + }).WaitForExit();*/ + int key = new[] + { + PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, + PlatformID.WinCE + } + .Contains(Environment.OSVersion.Platform) ? 0 : + File.Exists(Path.Combine(tmp, "Remove.sh")) ? 1 : 2; + ProcessStartInfo prc = new ProcessStartInfo + { + FileName = key switch + { + 0 => "cmd.exe", + 1 => "bash", + 2 => "wine", + _ => throw new Exception() + }, + WorkingDirectory = Path.Combine(app.AppPath, "app"), + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }; + foreach (string s in key switch + { + 0 => new[] {"/C", $"{Path.Combine(tmp, "Remove.bat")}"}, + 1 => new[] {Path.Combine(tmp, "Remove.sh")}, + 2 => new[] {"cmd", "/C", $"{Path.Combine(tmp, "Remove.bat")}"}, + _ => throw new Exception() + }) + prc.ArgumentList.Add(s); + Process.Start(prc)?.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.Exists(app.dataPath) && - Directory.GetFiles(app.dataPath).Length + Directory.GetDirectories(app.dataPath).Length == + 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.Exists(app.DataPath) && + Directory.GetFiles(app.DataPath).Length + Directory.GetDirectories(app.DataPath).Length == 0)) - Directory.Delete(app.appPath, true); + Directory.Delete(app.AppPath, true); } private static void CheckDirecory(string tmp, string app) diff --git a/UpToolLib/Tool/AppInstall.cs b/UpToolLib/Tool/AppInstall.cs index 8597f91..989df75 100644 --- a/UpToolLib/Tool/AppInstall.cs +++ b/UpToolLib/Tool/AppInstall.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Linq; using System.IO; using System.IO.Compression; using System.Security.Cryptography; @@ -23,8 +24,8 @@ namespace UpToolLib.Tool try { #endif - app = appI.appPath; - tmp = PathTool.tempPath; + app = appI.AppPath; + tmp = PathTool.TempPath; if (Directory.Exists(tmp)) Directory.Delete(tmp, true); Directory.CreateDirectory(tmp); @@ -39,7 +40,7 @@ namespace UpToolLib.Tool if (!Directory.Exists(app)) Directory.CreateDirectory(app); } - (bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.instance.Download(new Uri(appI.File)); + (bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.Instance.Download(new Uri(appI.File)); if (!dlSuccess) throw new Exception("Download failed"); using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider()) @@ -77,9 +78,9 @@ Online: {appI.Hash.ToUpper()}"); string tmp = ""; try { - app = meta.appPath; + app = meta.AppPath; Directory.CreateDirectory(app); - tmp = PathTool.tempPath; + tmp = PathTool.TempPath; if (Directory.Exists(tmp)) Directory.Delete(tmp, true); Directory.CreateDirectory(tmp); @@ -102,18 +103,16 @@ 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, bool force) => CompleteInstall(app.appPath, app.Name, + 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, bool force) { - string tmp = PathTool.tempPath; + 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")); @@ -124,14 +123,62 @@ Online: {appI.Hash.ToUpper()}"); if (mainFile != null) el.Add(new XElement(new XElement("MainFile", mainFile))); el.Save(Path.Combine(appPath, "info.xml")); - Process.Start(new ProcessStartInfo + /*if (new[] { PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE }.Contains(Environment.OSVersion.Platform)) + Process.Start(new ProcessStartInfo + { + FileName = "cmd.exe", + ArgumentList = {"/C", $"{Path.Combine(tmp, "Install.bat")}"}, + WorkingDirectory = Path.Combine(appPath, "app"), + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }).WaitForExit(); + else if (File.Exists(Path.Combine(tmp, "Install.sh"))) + Process.Start(new ProcessStartInfo + { + FileName = "bash", + ArgumentList = {Path.Combine(tmp, "Install.sh")}, + WorkingDirectory = Path.Combine(appPath, "app"), + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }).WaitForExit(); + else + Process.Start(new ProcessStartInfo + { + FileName = "wine", + ArgumentList = {"cmd", "/C", $"{Path.Combine(tmp, "Install.bat")}"}, + WorkingDirectory = Path.Combine(appPath, "app"), + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }).WaitForExit();*/ + int key = new[] + { + PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, + PlatformID.WinCE + } + .Contains(Environment.OSVersion.Platform) ? 0 : + File.Exists(Path.Combine(tmp, "Install.sh")) ? 1 : 2; + ProcessStartInfo prc = new ProcessStartInfo { - FileName = "cmd.exe", - Arguments = $"/C \"{Path.Combine(tmp, "Install.bat")}\"", + FileName = key switch + { + 0 => "cmd.exe", + 1 => "bash", + 2 => "wine", + _ => throw new Exception() + }, WorkingDirectory = Path.Combine(appPath, "app"), CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden - }).WaitForExit(); + }; + foreach (string s in key switch + { + 0 => new[] {"/C", $"{Path.Combine(tmp, "Install.bat")}"}, + 1 => new[] {Path.Combine(tmp, "Install.sh")}, + 2 => new[] {"cmd", "/C", $"{Path.Combine(tmp, "Install.bat")}"}, + _ => throw new Exception() + }) + prc.ArgumentList.Add(s); + Process.Start(prc)?.WaitForExit(); } private static void CopyAll(string source, string target) diff --git a/UpToolLib/Tool/PathTool.cs b/UpToolLib/Tool/PathTool.cs index 35ad974..9597dfb 100644 --- a/UpToolLib/Tool/PathTool.cs +++ b/UpToolLib/Tool/PathTool.cs @@ -6,17 +6,17 @@ namespace UpToolLib.Tool { public static class PathTool { - public static string dir => + public static string Dir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2"); - public static string tempPath => GetRelative("tmp"); - public static string appsPath => GetRelative("Apps"); + public static string TempPath => GetRelative("tmp"); + public static string AppsPath => GetRelative("Apps"); public static string InfoXml => GetRelative("info.xml"); public static string GetRelative(params string[] segments) => - Path.Combine(new[] {dir}.Concat(segments).ToArray()); + Path.Combine(new[] {Dir}.Concat(segments).ToArray()); - public static string GetAppPath(Guid app) => Path.Combine(appsPath, app.ToString()); + public static string GetAppPath(Guid app) => Path.Combine(AppsPath, app.ToString()); public static string GetDataPath(Guid app) => Path.Combine(GetAppPath(app), "app"); diff --git a/UpToolLib/Tool/RepoManagement.cs b/UpToolLib/Tool/RepoManagement.cs index 205338e..72766f8 100644 --- a/UpToolLib/Tool/RepoManagement.cs +++ b/UpToolLib/Tool/RepoManagement.cs @@ -25,11 +25,11 @@ namespace UpToolLib.Tool try { #endif - ExternalFunctionalityManager.instance.Log($"[{i + 1}] Loading {repArr[i]}"); + ExternalFunctionalityManager.Instance.Log($"[{i + 1}] Loading {repArr[i]}"); XDocument repo = XDocument.Load(new Uri(repArr[i]).Unshorten().AbsoluteUri); repArr.AddRange(repo.Element("repo").Elements("repolink").Select(s => s.Value) .Where(s => !repArr.Contains(s))); - XElement[] tmp_apparray = repo.Element("repo").Elements("app").Where(app => + XElement[] tmpApparray = repo.Element("repo").Elements("app").Where(app => !tmpAppsList.Any(a => a.Element("ID").Value == app.Element("ID").Value) || !tmpAppsList .Where(a => a.Element("ID").Value == app.Element("ID").Value).Any(a => @@ -37,13 +37,12 @@ namespace UpToolLib.Tool .Concat(repo.Element("repo").Elements("applink") .Select(s => { - ExternalFunctionalityManager.instance.Log($"- Loading {s.Value}"); + ExternalFunctionalityManager.Instance.Log($"- Loading {s.Value}"); return XDocument.Load(new Uri(s.Value).Unshorten().AbsoluteUri).Element("app"); })) .ToArray(); - for (int i1 = 0; i1 < tmp_apparray.Length; i1++) + foreach (XElement app in tmpApparray) { - XElement app = tmp_apparray[i1]; //"Sanity check" Version.Parse(app.Element("Version").Value); Guid.Parse(app.Element("ID").Value); @@ -63,14 +62,16 @@ namespace UpToolLib.Tool { tmpAppsList.Last() .Add(new XElement("Icon", - ExternalFunctionalityManager.instance.FetchImageB64( + ExternalFunctionalityManager.Instance.FetchImageB64( new Uri(app.Element("Icon").Value).Unshorten()))); } catch { + // ignored } - if (tmpAppsList.Count(a => a.Element("ID").Value == app.Element("ID").Value) > 1) + XElement app1 = app; + if (tmpAppsList.Count(a => a.Element("ID").Value == app1.Element("ID").Value) > 1) tmpAppsList.Where(a => a.Element("ID").Value == app.Element("ID").Value).Reverse() .Skip(1) .ToList().ForEach(a => tmpAppsList.Remove(a)); @@ -79,7 +80,7 @@ namespace UpToolLib.Tool } catch (Exception e) { - ExternalFunctionalityManager.instance.OKDialog( + ExternalFunctionalityManager.Instance.OkDialog( $"Failed to load repo: {repArr[i]}{Environment.NewLine}{e}"); } #endif @@ -112,7 +113,7 @@ namespace UpToolLib.Tool string locInPath = PathTool.GetInfoPath(id); XElement locIn = File.Exists(locInPath) ? XDocument.Load(locInPath).Element("app") : app; if (int.TryParse(app.Element("Version").Value, out _)) - app.Element("Version").Value = GlobalVariables.minimumVer.ToString(); + app.Element("Version").Value = GlobalVariables.MinimumVer.ToString(); GlobalVariables.Apps.Add(id, new App( locIn.Element("Name").Value, locIn.Element("Description").Value, @@ -123,15 +124,15 @@ namespace UpToolLib.Tool id, Color.White, app.Element("Icon") == null - ? ExternalFunctionalityManager.instance.GetDefaultIcon() - : ExternalFunctionalityManager.instance.ImageFromB64(app.Element("Icon").Value), + ? ExternalFunctionalityManager.Instance.GetDefaultIcon() + : ExternalFunctionalityManager.Instance.ImageFromB64(app.Element("Icon").Value), locIn.Element("MainFile") != null || app.Element("MainFile") != null, locIn.Element("MainFile") == null ? app.Element("MainFile") == null ? "" : app.Element("MainFile").Value : locIn.Element("MainFile").Value )); }); - Directory.GetDirectories(PathTool.appsPath) + Directory.GetDirectories(PathTool.AppsPath) .Where(s => Guid.TryParse(Path.GetFileName(s), out Guid guid) && !GlobalVariables.Apps.ContainsKey(guid)).ToList().ForEach(s => { @@ -141,14 +142,14 @@ namespace UpToolLib.Tool XElement data = XDocument.Load(PathTool.GetInfoPath(tmp)).Element("app"); GlobalVariables.Apps.Add(tmp, new App("(local) " + data.Element("Name").Value, data.Element("Description").Value, - GlobalVariables.minimumVer, "", true, "", tmp, Color.Red, - ExternalFunctionalityManager.instance.GetDefaultIcon(), + GlobalVariables.MinimumVer, "", true, "", tmp, Color.Red, + ExternalFunctionalityManager.Instance.GetDefaultIcon(), data.Element("MainFile") != null, data.Element("MainFile") == null ? "" : data.Element("MainFile").Value)); } catch (Exception e) { - if (ExternalFunctionalityManager.instance.YesNoDialog( + if (ExternalFunctionalityManager.Instance.YesNoDialog( $@"An error occured while loading this local repo: {e.Message} Do you want to exit? Otherwise the folder will be deleted, possibly causeing problems later.", false)) diff --git a/UpToolLib/Tool/XmlTool.cs b/UpToolLib/Tool/XmlTool.cs index a597dbc..5ba25ce 100644 --- a/UpToolLib/Tool/XmlTool.cs +++ b/UpToolLib/Tool/XmlTool.cs @@ -8,6 +8,8 @@ namespace UpToolLib.Tool { public static void FixXml() { + if (!Directory.Exists(PathTool.AppsPath)) + Directory.CreateDirectory(PathTool.AppsPath); if (!File.Exists(PathTool.InfoXml) || XDocument.Load(PathTool.InfoXml).Element("meta") == null) new XElement("meta").Save(PathTool.InfoXml); XDocument x = XDocument.Load(PathTool.InfoXml); diff --git a/UpToolLib/UpToolLib.csproj b/UpToolLib/UpToolLib.csproj index 99f988e..fcaf778 100644 --- a/UpToolLib/UpToolLib.csproj +++ b/UpToolLib/UpToolLib.csproj @@ -8,19 +8,4 @@ - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - -