Refactoving, support for semantic versions in update checks

This commit is contained in:
CreepyCrafter24 2019-11-12 20:41:57 +01:00
parent 8490c54df2
commit efb9262c2e
4 changed files with 29 additions and 22 deletions

View File

@ -1,9 +1,9 @@
More Icons for Apps More Icons for Apps
More apps: Laptop Sim (when done) 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 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!

View File

@ -21,7 +21,7 @@ namespace UpTool2
string tmp = ""; string tmp = "";
try try
{ {
app = GlobalVariables.dir + @"\Apps\" + appI.ID.ToString(); app = appI.appPath;
tmp = GlobalVariables.dir + @"\tmp"; tmp = GlobalVariables.dir + @"\tmp";
if (Directory.Exists("")) if (Directory.Exists(""))
Directory.Delete("", true); Directory.Delete("", true);
@ -37,7 +37,7 @@ namespace UpTool2
if (pkghash != appI.hash.ToUpper()) 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()); 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 catch
{ {
@ -65,7 +65,7 @@ namespace UpTool2
Directory.Delete(tmp, true); Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp); Directory.CreateDirectory(tmp);
File.Copy(zipPath, app + @"\package.zip"); File.Copy(zipPath, app + @"\package.zip");
completeInstall(app, meta); completeInstall(meta);
} }
catch 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 #if !DEBUG
try try
{ {
#endif #endif
string tmp = GlobalVariables.dir + @"\tmp"; string tmp = GlobalVariables.dir + @"\tmp";
ZipFile.ExtractToDirectory(app + @"\package.zip", tmp); ZipFile.ExtractToDirectory(appPath + @"\package.zip", tmp);
Directory.Move(tmp + @"\Data", app + @"\app"); Directory.Move(tmp + @"\Data", appPath + @"\app");
if (appI.runnable) if (mainFile == null)
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"); new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version)).Save(appPath + @"\info.xml");
else else
new XElement("app", new XElement("Name", appI.name), new XElement("Description", appI.description), new XElement("Version", appI.version)).Save(app + @"\info.xml"); 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 = app + @"\app", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = appPath + @"\app", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit();
if (GlobalVariables.relE) if (GlobalVariables.relE)
GlobalVariables.reloadElements.Invoke(); GlobalVariables.reloadElements.Invoke();
#if !DEBUG #if !DEBUG

View File

@ -6,7 +6,6 @@ using System.Xml.Linq;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.IO.Compression; using System.IO.Compression;
using System.Security.Cryptography;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
namespace UpTool2 namespace UpTool2
@ -118,15 +117,16 @@ namespace UpTool2
infoPanel_Title.ForeColor = app.local ? Color.Red : Color.Black; infoPanel_Title.ForeColor = app.local ? Color.Red : Color.Black;
infoPanel_Description.Text = app.description; infoPanel_Description.Text = app.description;
action_install.Tag = app; 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.Tag = app;
action_remove.Enabled = Directory.Exists(GlobalVariables.getAppPath(app)); action_remove.Enabled = Directory.Exists(app.appPath);
action_update.Tag = app; 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.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++; availableUpdates++;
toolTip.SetToolTip(sidebarIcon, app.name); toolTip.SetToolTip(sidebarIcon, app.name);
sidebarPanel.Controls.Add(sidebarIcon); sidebarPanel.Controls.Add(sidebarIcon);

View File

@ -141,8 +141,13 @@ namespace UpTool2
static bool UpdateCheck(string dir, string xml, string metaXML) static bool UpdateCheck(string dir, string xml, string metaXML)
{ {
XElement meta = XDocument.Load(metaXML).Element("meta"); XElement meta = XDocument.Load(metaXML).Element("meta");
int version = int.Parse(meta.Element("Version").Value); bool updatable;
if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version) 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")) using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value, dir + @"\update.tmp"))
{ {
@ -170,7 +175,7 @@ namespace UpTool2
AssemblyName.GetAssemblyName(dir + @"\update.tmp"); AssemblyName.GetAssemblyName(dir + @"\update.tmp");
File.Move(dir + @"\update.tmp", dir + @"\update.exe"); 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(); 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 }); 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; return false;