diff --git a/FolderLayout.txt b/FolderLayout.txt index 796b4c7..11cd08d 100644 --- a/FolderLayout.txt +++ b/FolderLayout.txt @@ -15,4 +15,6 @@ - Repos - Local Repo - Install - - __ZIP_CONTENTS \ No newline at end of file + - __ZIP CONTENTS + - tmp + - __FILES FOR UPDATE \ No newline at end of file diff --git a/UpTool2/AppInstall.cs b/UpTool2/AppInstall.cs index a0e1f33..b198067 100644 --- a/UpTool2/AppInstall.cs +++ b/UpTool2/AppInstall.cs @@ -31,14 +31,16 @@ namespace UpTool2 if (Directory.Exists(app)) Directory.Delete(app, true); Directory.CreateDirectory(app); - if (new DownloadDialog(appI.file, app + @"\package.zip").ShowDialog() != DialogResult.OK) + DownloadDialog dlg = new DownloadDialog(appI.file); + if (dlg.ShowDialog() != DialogResult.OK) throw new Exception("Download failed"); using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider()) { - string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(app + @"\package.zip"))).Replace("-", string.Empty).ToUpper(); + string pkghash = BitConverter.ToString(sha256.ComputeHash(dlg.result)).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()); } + File.WriteAllBytes(app + @"\package.zip", dlg.result); completeInstall(appI); #if !DEBUG } diff --git a/UpTool2/MainForm.Designer.cs b/UpTool2/MainForm.Designer.cs index 67857d9..5074938 100644 --- a/UpTool2/MainForm.Designer.cs +++ b/UpTool2/MainForm.Designer.cs @@ -44,7 +44,6 @@ this.searchBox = new System.Windows.Forms.TextBox(); this.controls_settings = new System.Windows.Forms.Button(); this.controls_reload = new System.Windows.Forms.Button(); - this.controls_local = new System.Windows.Forms.Button(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.searchPackageDialog = new System.Windows.Forms.OpenFileDialog(); this.infoPanel.SuspendLayout(); @@ -170,7 +169,6 @@ this.optionsPanel.Controls.Add(this.searchBox); this.optionsPanel.Controls.Add(this.controls_settings); this.optionsPanel.Controls.Add(this.controls_reload); - this.optionsPanel.Controls.Add(this.controls_local); this.optionsPanel.Dock = System.Windows.Forms.DockStyle.Top; this.optionsPanel.Location = new System.Drawing.Point(0, 0); this.optionsPanel.Name = "optionsPanel"; @@ -206,7 +204,7 @@ | System.Windows.Forms.AnchorStyles.Right))); this.searchBox.Location = new System.Drawing.Point(3, 33); this.searchBox.Name = "searchBox"; - this.searchBox.Size = new System.Drawing.Size(233, 20); + this.searchBox.Size = new System.Drawing.Size(262, 20); this.searchBox.TabIndex = 2; this.searchBox.TextChanged += new System.EventHandler(this.updateSidebarV); // @@ -230,17 +228,6 @@ this.controls_reload.UseVisualStyleBackColor = true; this.controls_reload.Click += new System.EventHandler(this.Controls_reload_Click); // - // controls_local - // - this.controls_local.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.controls_local.Location = new System.Drawing.Point(242, 31); - this.controls_local.Name = "controls_local"; - this.controls_local.Size = new System.Drawing.Size(23, 23); - this.controls_local.TabIndex = 6; - this.controls_local.Text = "⇓"; - this.controls_local.UseVisualStyleBackColor = true; - this.controls_local.Click += new System.EventHandler(this.controls_local_Click); - // // toolTip // this.toolTip.AutoPopDelay = 5000; @@ -296,7 +283,6 @@ private System.Windows.Forms.Button action_run; private System.Windows.Forms.Button controls_upload; private System.Windows.Forms.OpenFileDialog searchPackageDialog; - private System.Windows.Forms.Button controls_local; } } diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index e695f7e..d3348c0 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -98,8 +98,6 @@ namespace UpTool2 toolTip.SetToolTip(controls_settings, "Settings"); toolTip.SetToolTip(controls_reload, "Refresh repositories"); toolTip.SetToolTip(controls_upload, "Install package from disk"); - toolTip.SetToolTip(controls_local, "Install UpTool2 locally"); - controls_local.Visible = Application.ExecutablePath != GlobalVariables.dir + @"\UpTool2.exe"; searchBox.Size = (Application.ExecutablePath != GlobalVariables.dir + @"\UpTool2.exe") ? new Size(233, 20) : new Size(262, 20); toolTip.SetToolTip(filterBox, "Filter"); toolTip.SetToolTip(action_install, "Install"); @@ -234,13 +232,6 @@ namespace UpTool2 Program.splash.Hide(); BringToFront(); } - private void controls_local_Click(object sender, EventArgs e) - { - File.Copy(GlobalVariables.dir + @"\update.exe", GlobalVariables.dir + @"\UpTool2.exe", true); - Shortcut.Make(GlobalVariables.dir + @"\UpTool2.exe", Path.GetDirectoryName(Application.ExecutablePath) + "\\UpTool2.lnk"); - Shortcut.Make(GlobalVariables.dir + @"\UpTool2.exe", Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk"); - Close(); - } struct _IMAGE_FILE_HEADER { diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 36782af..871caff 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -17,6 +17,9 @@ using System.IO.Compression; namespace UpTool2 { + /*if (Application.ExecutablePath != GlobalVariables.dir + @"\UpTool2.exe") + Shortcut.Make(GlobalVariables.dir + @"\UpTool2.exe", Path.GetDirectoryName(Application.ExecutablePath) + "\\UpTool2.lnk"); + Shortcut.Make(GlobalVariables.dir + @"\UpTool2.exe", Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk");*/ static class Program { public static Form splash; @@ -52,13 +55,21 @@ namespace UpTool2 #endif hasHandle = true; } - if (!Directory.Exists(GlobalVariables.dir + @"\Apps")) - Directory.CreateDirectory(GlobalVariables.dir + @"\Apps"); string xml = GlobalVariables.dir + @"\info.xml"; FixXML(xml); string metaXML = XDocument.Load(xml).Element("meta").Element("UpdateSource").Value; online = Ping(metaXML); - if (!online || UpdateCheck(GlobalVariables.dir, metaXML)) + if (Application.ExecutablePath != GlobalVariables.dir + @"\UpTool2.exe") + { + if (!online) + throw new WebException("Could not install"); + installUpdate(XDocument.Load(metaXML).Element("meta")); + } + if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk")) + Shortcut.Make(GlobalVariables.dir + @"\UpTool2.exe", Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk"); + if (!Directory.Exists(GlobalVariables.dir + @"\Apps")) + Directory.CreateDirectory(GlobalVariables.dir + @"\Apps"); + if (!online || UpdateCheck(metaXML)) Application.Run(new MainForm()); #if !DEBUG } @@ -140,42 +151,47 @@ namespace UpTool2 } } - static bool UpdateCheck(string dir, string metaXML) + static bool UpdateCheck(string metaXML) { XElement meta = XDocument.Load(metaXML).Element("meta"); if (Assembly.GetExecutingAssembly().GetName().Version < Version.Parse(meta.Element("Version").Value)) { - 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(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 (Directory.Exists(dir + @"\Install\tmp")) - Directory.Delete(dir + @"\Install\tmp", true); - Directory.CreateDirectory(dir + @"\Install\tmp"); - 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\tmp" + s.Name, true); - }); - } - splash.Hide(); - Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = @"/C timeout /t 2 & xcopy /s /e /y tmp\* .", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = dir + @"\Install" }); + installUpdate(meta); return false; } return true; } + static void installUpdate(XElement meta) + { + 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(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 (Directory.Exists(GlobalVariables.dir + @"\Install\tmp")) + Directory.Delete(GlobalVariables.dir + @"\Install\tmp", true); + Directory.CreateDirectory(GlobalVariables.dir + @"\Install\tmp"); + 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(GlobalVariables.dir + @"\Install\tmp" + s.Name, true); + }); + } + splash.Hide(); + Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = @"/C timeout /t 2 & xcopy /s /e /y tmp\* .", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = GlobalVariables.dir + @"\Install" }); + } + public static bool Ping(string url) { try