Parcourir la source

Updated to 4.5

hellzerg il y a 6 ans
Parent
commit
e8e93f965f
6 fichiers modifiés avec 58 ajouts et 10 suppressions
  1. 3 0
      CHANGELOG.md
  2. 1 1
      Optimizer/AboutForm.cs
  3. 50 5
      Optimizer/MainForm.cs
  4. 1 1
      Optimizer/Program.cs
  5. 2 2
      README.md
  6. 1 1
      version.txt

+ 3 - 0
CHANGELOG.md

@@ -2,6 +2,9 @@
 
 All notable changes to this project will be documented in this file.
 
+## [4.5] - 2018-10-08
+- Improved: You can now update the app automatically by clicking Check for update in Options
+
 ## [4.4] - 2018-09-21
 - Improved: Disable Automatic Updates (Windows 10)
 - Added: Make HOSTS file read-only

+ 1 - 1
Optimizer/AboutForm.cs

@@ -150,7 +150,7 @@ namespace Optimizer
 
         private void l2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
         {
-            Process.Start("https://carcinos.eu/deadmoon");
+            Process.Start("https://github.com/hellzerg/optimizer");
         }
     }
 }

+ 50 - 5
Optimizer/MainForm.cs

@@ -33,7 +33,6 @@ namespace Optimizer
         DesktopTypePosition _desktopItemPosition = DesktopTypePosition.Top;
 
         readonly string _latestVersionLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/version.txt";
-        readonly string _releasesLink = "https://github.com/hellzerg/optimizer/releases";
         readonly string _changelogLink = "https://github.com/hellzerg/optimizer/blob/master/CHANGELOG.md";
 
         readonly string _noNewVersionMessage = "You already have the latest version!";
@@ -49,9 +48,14 @@ namespace Optimizer
         readonly string _errorModernAppsMessage = "The following app(s) couldn't be uninstalled:\n";
         readonly string _resetMessage = "Are you sure you want to reset configuration?\n\nThis will reset all your preferences, including any icons you extracted or downloaded using Integrator, but will not touch anything on your computer!";
 
-        private string NewVersionMessage(string latest)
+        private string NewVersionMessage(string latestVersion)
         {
-            return string.Format("There is a new version available!\n\nLatest version: {0}\nCurrent version: {1}\n\nDo you want to download it now?", latest, Program.GetCurrentVersionTostring());
+            return string.Format("There is a new version available!\n\nLatest version: {0}\nCurrent version: {1}\n\nDo you want to download it now?", latestVersion, Program.GetCurrentVersionTostring());
+        }
+
+        private string NewDownloadLink(string latestVersion)
+        {
+            return string.Format("https://github.com/hellzerg/optimizer/releases/download/{0}/Optimizer-{0}.exe", latestVersion);
         }
 
         private void CheckForUpdate()
@@ -77,11 +81,45 @@ namespace Optimizer
                 {
                     if (MessageBox.Show(NewVersionMessage(latestVersion), "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                     {
+                        // PATCHING PROCESS
                         try
                         {
-                            Process.Start(_releasesLink);
+                            Assembly currentAssembly = Assembly.GetEntryAssembly();
+
+                            if (currentAssembly == null)
+                            {
+                                currentAssembly = Assembly.GetCallingAssembly();
+                            }
+
+                            string appFolder = Path.GetDirectoryName(currentAssembly.Location);
+                            string appName = Path.GetFileNameWithoutExtension(currentAssembly.Location);
+                            string appExtension = Path.GetExtension(currentAssembly.Location);
+
+                            string archiveFile = Path.Combine(appFolder, appName + "_old" + appExtension);
+                            string appFile = Path.Combine(appFolder, appName + appExtension);
+                            string tempFile = Path.Combine(appFolder, appName + "_tmp" + appExtension);
+
+                            // DOWNLOAD NEW VERSION
+                            client.DownloadFile(NewDownloadLink(latestVersion), tempFile);
+
+                            // DELETE PREVIOUS BACK-UP
+                            if (File.Exists(archiveFile))
+                            {
+                                File.Delete(archiveFile);
+                            }
+
+                            // MAKE BACK-UP
+                            File.Move(appFile, archiveFile);
+
+                            // PATCH
+                            File.Move(tempFile, appFile);
+
+                            Application.Restart();
+                        }
+                        catch (Exception ex)
+                        {
+                            MessageBox.Show(ex.Message);
                         }
-                        catch { }
                     }
                 }
                 else if (float.Parse(latestVersion) == Program.GetCurrentVersion())
@@ -95,6 +133,11 @@ namespace Optimizer
             }
         }
 
+        private void Patch()
+        {
+            
+        }
+
         private void EnableToggleEvents()
         {
             toggleSwitch12.Click += new EventHandler(toggleSwitch12_Click);
@@ -220,6 +263,8 @@ namespace Optimizer
             CheckForIllegalCrossThreadCalls = false;
             Options.ApplyTheme(this);
 
+            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+
             if (Utilities.CurrentWindowsVersion == WindowsVersion.Unsupported)
             {
                 tabCollection.TabPages.Remove(universalTab);

+ 1 - 1
Optimizer/Program.cs

@@ -18,7 +18,7 @@ namespace Optimizer
 
         // Enter current version here
         internal readonly static float Major = 4;
-        internal readonly static float Minor = 4;
+        internal readonly static float Minor = 5;
 
         internal static string GetCurrentVersionTostring()
         {

+ 2 - 2
README.md

@@ -37,5 +37,5 @@ https://github.com/hellzerg/optimizer/blob/master/IMAGES.md
 
 ## Details: ##
 
-* Latest version: 4.4
-* Released: September 21, 2018
+* Latest version: 4.5
+* Released: October 8, 2018

+ 1 - 1
version.txt

@@ -1 +1 @@
-4.4
+4.5