diff --git a/FolderLayout.txt b/FolderLayout.txt index 68c79d1..796b4c7 100644 --- a/FolderLayout.txt +++ b/FolderLayout.txt @@ -13,4 +13,6 @@ - info.xml - Version - Repos - - Local Repo \ No newline at end of file + - Local Repo +- Install + - __ZIP_CONTENTS \ No newline at end of file diff --git a/UpTool2/DownloadDialog.cs b/UpTool2/DownloadDialog.cs index 9571619..62eead2 100644 --- a/UpTool2/DownloadDialog.cs +++ b/UpTool2/DownloadDialog.cs @@ -14,15 +14,18 @@ namespace UpTool2 public partial class DownloadDialog : Form { bool close; - public DownloadDialog(string uri, string file) + WebClient client; + public byte[] result; + public DownloadDialog(string uri) { InitializeComponent(); try { WebClient client = new WebClient(); client.DownloadProgressChanged += progressChanged; - client.DownloadFileCompleted += done; - client.DownloadFileAsync(new Uri(uri), file); + client.DownloadDataCompleted += done; + //client.DownloadFileAsync(new Uri(uri), file); + client.DownloadDataAsync(new Uri(uri), client); } catch { @@ -31,10 +34,11 @@ namespace UpTool2 } } - private void done(object sender, AsyncCompletedEventArgs e) + private void done(object sender, DownloadDataCompletedEventArgs e) { DialogResult = DialogResult.OK; close = true; + result = e.Result; Close(); } diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 0924d4a..05e0093 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -145,26 +145,29 @@ namespace UpTool2 XElement meta = XDocument.Load(metaXML).Element("meta"); if (Assembly.GetExecutingAssembly().GetName().Version < Version.Parse(meta.Element("Version").Value)) { - using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value, dir + @"\update.tmp")) + byte[] dl; + using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value)) { if (dlg.ShowDialog() != DialogResult.OK) throw new Exception("Failed to update"); + dl = dlg.result; } using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider()) { - string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(dir + @"\update.tmp"))).Replace("-", string.Empty).ToUpper(); + string pkghash = BitConverter.ToString(sha256.ComputeHash(dl)).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()); } - if (File.Exists(dir + @"\update.exe")) - File.Delete(dir + @"\update.exe"); - if (Directory.Exists(dir + @"\update")) - Directory.Delete(dir + @"\update", true); - ZipFile.ExtractToDirectory(dir + @"\update.tmp", dir + @"\update"); - File.Delete(dir + @"\update.tmp"); - string[] array = Directory.GetFiles(dir + @"\update\Release"); - for (int i = 0; i < array.Length; i++) - File.Copy(array[i], dir + @"\update.exe", true); + if (Directory.Exists(dir + @"\Install")) + Directory.Delete(dir + @"\Install", true); + using (MemoryStream ms = new MemoryStream(dl)) + using (ZipArchive ar = new ZipArchive(ms)) + { + ar.Entries.Where(s => !string.IsNullOrEmpty(s.Name)).ToList().ForEach(s => + { + s.ExtractToFile(dir + @"\Install\" + s.Name, true); + }); + } 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;