Show Download progress on updates (needs to be tested)

This commit is contained in:
CreepyCrafter24 2019-10-20 18:31:32 +02:00
parent df04a2002f
commit c000acf098
3 changed files with 15 additions and 13 deletions

View File

@ -1,5 +1,6 @@
More Icons for Apps More Icons for Apps
More apps: Laptop Sim (when done) More apps: Laptop Sim (when done)
Use local info when building GUI (Except name/description) Use local info when building GUI (Except name/description)
Decent updater Decent updater and Installer (Do not open CMD)
Save Images on disk to allow offline usage Save Images on disk to allow offline usage
Test Updates

View File

@ -36,11 +36,12 @@ namespace UpTool2
Directory.CreateDirectory(app); Directory.CreateDirectory(app);
if (new DownloadDialog(appI.file, app + @"\package.zip").ShowDialog() != DialogResult.OK) if (new DownloadDialog(appI.file, app + @"\package.zip").ShowDialog() != DialogResult.OK)
throw new Exception("Download failed"); throw new Exception("Download failed");
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider(); 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()) string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(app + @"\package.zip"))).Replace("-", string.Empty).ToUpper();
throw new Exception("The hash is not equal to the one stored in the repo:\r\nPackage: " + pkghash + "\r\nOnline: " + appI.hash.ToUpper()); if (pkghash != appI.hash.ToUpper())
sha256.Dispose(); 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(app, appI);
#if !DEBUG #if !DEBUG
} }

View File

@ -85,14 +85,14 @@ namespace UpTool2
int version = int.Parse(meta.Element("Version").Value); int version = int.Parse(meta.Element("Version").Value);
if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version) 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); new XElement("meta", new XElement("Version", version)).Save(xml);
splash.Hide(); 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" }); 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" });