diff --git a/ToDo.txt b/ToDo.txt index 7af31d4..f1bdb15 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -1,5 +1,6 @@ More Icons for Apps More apps: Laptop Sim (when done) Use local info when building GUI (Except name/description) -Decent updater -Save Images on disk to allow offline usage \ No newline at end of file +Decent updater and Installer (Do not open CMD) +Save Images on disk to allow offline usage +Test Updates \ No newline at end of file diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index 8241ec1..70ba323 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -36,11 +36,12 @@ namespace UpTool2 Directory.CreateDirectory(app); if (new DownloadDialog(appI.file, app + @"\package.zip").ShowDialog() != DialogResult.OK) throw new Exception("Download failed"); - SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider(); - string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(app + @"\package.zip"))).Replace("-", string.Empty).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()); - sha256.Dispose(); + using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider()) + { + string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(app + @"\package.zip"))).Replace("-", string.Empty).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()); + } completeInstall(app, appI); #if !DEBUG } diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 9fa2719..9fde828 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -85,14 +85,14 @@ namespace UpTool2 int version = int.Parse(meta.Element("Version").Value); if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version) { - using (var client = new WebClient()) + if (new DownloadDialog(meta.Element("File").Value, dir + @"\update.exe").ShowDialog() != DialogResult.OK) + throw new Exception("Failed to update"); + using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider()) { - client.DownloadFile(meta.Element("File").Value, dir + @"\update.exe"); + string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(dir + @"\update.exe"))).Replace("-", string.Empty).ToUpper(); + if (pkghash != meta.Element("Hash").Value.ToUpper()) + throw new Exception("The hash is not equal to the one stored in the repo:\r\nPackage: " + pkghash + "\r\nOnline: " + meta.Element("Hash").Value.ToUpper()); } - SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider(); - if (BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(dir + @"\update.exe"))).Replace("-", string.Empty).ToUpper() != meta.Element("Hash").Value) - throw new Exception("The hash is not equal to the one stored in the repo"); - sha256.Dispose(); new XElement("meta", new XElement("Version", version)).Save(xml); splash.Hide(); Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C echo Running Update & timeout /t 4 & copy /b/v/y \"" + dir + @"\update.exe" + "\" \"" + Application.ExecutablePath + "\" & echo Done Updating, please restart & pause" });