diff --git a/ToDo and Notes.txt b/ToDo and Notes.txt index 3bce580..bf56fd4 100644 --- a/ToDo and Notes.txt +++ b/ToDo and Notes.txt @@ -1,9 +1,9 @@ More Icons for Apps More apps: Laptop Sim (when done) -Split up main File (MainForm.cs) to (more or less) independent modules Automatically push Meta.xml changes after building - - +Support semantic versioning for app updates (App object versions will have to be converted) +Use binary version for Updates +Less code in MainForm.cs! diff --git a/UpTool2/AppInstall.cs b/UpTool2/AppInstall.cs index 64714a8..620ca14 100644 --- a/UpTool2/AppInstall.cs +++ b/UpTool2/AppInstall.cs @@ -21,7 +21,7 @@ namespace UpTool2 string tmp = ""; try { - app = GlobalVariables.dir + @"\Apps\" + appI.ID.ToString(); + app = appI.appPath; tmp = GlobalVariables.dir + @"\tmp"; if (Directory.Exists("")) Directory.Delete("", true); @@ -37,7 +37,7 @@ namespace UpTool2 if (pkghash != appI.hash.ToUpper()) throw new Exception("The hash is not equal to the one stored in the repo:\r\nPackage: " + pkghash + "\r\nOnline: " + appI.hash.ToUpper()); } - completeInstall(app, appI); + completeInstall(appI); } catch { @@ -65,7 +65,7 @@ namespace UpTool2 Directory.Delete(tmp, true); Directory.CreateDirectory(tmp); File.Copy(zipPath, app + @"\package.zip"); - completeInstall(app, meta); + completeInstall(meta); } catch { @@ -80,20 +80,22 @@ namespace UpTool2 } } - static void completeInstall(string app, App appI) + static void completeInstall(App app) => completeInstall(app.appPath, app.name, app.description, app.version, app.mainFile); + + static void completeInstall(string appPath, string name, string description, int version, string mainFile) { #if !DEBUG try { #endif string tmp = GlobalVariables.dir + @"\tmp"; - ZipFile.ExtractToDirectory(app + @"\package.zip", tmp); - Directory.Move(tmp + @"\Data", app + @"\app"); - if (appI.runnable) - new XElement("app", new XElement("Name", appI.name), new XElement("Description", appI.description), new XElement("Version", appI.version), new XElement("MainFile", appI.mainFile)).Save(app + @"\info.xml"); + ZipFile.ExtractToDirectory(appPath + @"\package.zip", tmp); + Directory.Move(tmp + @"\Data", appPath + @"\app"); + if (mainFile == null) + new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version)).Save(appPath + @"\info.xml"); else - new XElement("app", new XElement("Name", appI.name), new XElement("Description", appI.description), new XElement("Version", appI.version)).Save(app + @"\info.xml"); - Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = app + @"\app", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); + new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version), new XElement("MainFile", mainFile)).Save(appPath + @"\info.xml"); + Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = appPath + @"\app", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); if (GlobalVariables.relE) GlobalVariables.reloadElements.Invoke(); #if !DEBUG diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index b27c33c..927cb6f 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -6,7 +6,6 @@ using System.Xml.Linq; using System.IO; using System.Diagnostics; using System.IO.Compression; -using System.Security.Cryptography; using Microsoft.VisualBasic; namespace UpTool2 @@ -118,15 +117,16 @@ namespace UpTool2 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(GlobalVariables.getAppPath(app))); + action_install.Enabled = !(app.local || Directory.Exists(app.appPath)); action_remove.Tag = app; - action_remove.Enabled = Directory.Exists(GlobalVariables.getAppPath(app)); + action_remove.Enabled = Directory.Exists(app.appPath); action_update.Tag = app; - action_update.Enabled = (!app.local) && File.Exists(GlobalVariables.getInfoPath(app)) && int.Parse(XDocument.Load(GlobalVariables.getInfoPath(app)).Element("app").Element("Version").Value) < app.version; + string ver = XDocument.Load(app.infoPath).Element("app").Element("Version").Value; + action_update.Enabled = (!app.local) && File.Exists(app.infoPath) && int.Parse(ver) < app.version; action_run.Tag = app; - action_run.Enabled = (!app.local) && app.runnable && Directory.Exists(GlobalVariables.getAppPath(app)); + action_run.Enabled = (!app.local) && app.runnable && Directory.Exists(app.appPath); }; - if ((!app.local) && File.Exists(GlobalVariables.getInfoPath(app)) && int.Parse(XDocument.Load(GlobalVariables.getInfoPath(app)).Element("app").Element("Version").Value) < app.version) + if ((!app.local) && File.Exists(app.infoPath) && int.Parse(XDocument.Load(app.infoPath).Element("app").Element("Version").Value) < app.version) availableUpdates++; toolTip.SetToolTip(sidebarIcon, app.name); sidebarPanel.Controls.Add(sidebarIcon); diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 3fbc37c..8a55fef 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -141,8 +141,13 @@ namespace UpTool2 static bool UpdateCheck(string dir, string xml, string metaXML) { XElement meta = XDocument.Load(metaXML).Element("meta"); - int version = int.Parse(meta.Element("Version").Value); - if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version) + bool updatable; + string ver = meta.Element("Version").Value; + if (int.TryParse(ver, out int version)) + updatable = int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version; + else + updatable = Assembly.GetExecutingAssembly().GetName().Version.CompareTo(Version.Parse(ver)) < 0; + if (updatable) { using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value, dir + @"\update.tmp")) { @@ -170,7 +175,7 @@ namespace UpTool2 AssemblyName.GetAssemblyName(dir + @"\update.tmp"); File.Move(dir + @"\update.tmp", dir + @"\update.exe"); } - new XElement("meta", new XElement("Version", version)).Save(xml); + new XElement("meta", new XElement("Version", ver)).Save(xml); splash.Hide(); Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C timeout /t 2 & copy /b/v/y \"" + dir + @"\update.exe" + "\" \"" + Application.ExecutablePath + "\" & \"" + Application.ExecutablePath + "\"", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }); return false;