From b1d78252379f81362f2a29857936ac1d2b6ac70e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 18 Jan 2021 18:27:39 +1100 Subject: [PATCH] Update in-place instead of using Updater.exe --- MCGalaxy.sln | 6 -- MCGalaxy/Server/Maintenance/Updater.cs | 27 +++-- updater/Galaxy.ico | Bin 4286 -> 0 bytes updater/Program.cs | 142 ------------------------- updater/Properties/AssemblyInfo.cs | 36 ------- updater/Updater.csproj | 98 ----------------- updater/app.config | 3 - 7 files changed, 13 insertions(+), 299 deletions(-) delete mode 100644 updater/Galaxy.ico delete mode 100644 updater/Program.cs delete mode 100644 updater/Properties/AssemblyInfo.cs delete mode 100644 updater/Updater.csproj delete mode 100644 updater/app.config diff --git a/MCGalaxy.sln b/MCGalaxy.sln index cfb3b2210..07a2de33d 100644 --- a/MCGalaxy.sln +++ b/MCGalaxy.sln @@ -8,8 +8,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCGalaxyGUI", "GUI\MCGalaxy EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCGalaxy_", "MCGalaxy\MCGalaxy_.csproj", "{12597DB0-7C34-4DE1-88EA-9250FF3372EB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "updater\Updater.csproj", "{1C317052-9B87-471C-A8AF-5AB2D779C174}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCGalaxyCLI", "CLI\MCGalaxyCLI.csproj", "{A1A5B886-2D0A-4D2A-AE13-409560D5227C}" EndProject Global @@ -26,10 +24,6 @@ Global {12597DB0-7C34-4DE1-88EA-9250FF3372EB}.Debug|x86.Build.0 = Debug|x86 {12597DB0-7C34-4DE1-88EA-9250FF3372EB}.Release|x86.ActiveCfg = Release|x86 {12597DB0-7C34-4DE1-88EA-9250FF3372EB}.Release|x86.Build.0 = Release|x86 - {1C317052-9B87-471C-A8AF-5AB2D779C174}.Debug|x86.ActiveCfg = Debug|x86 - {1C317052-9B87-471C-A8AF-5AB2D779C174}.Debug|x86.Build.0 = Debug|x86 - {1C317052-9B87-471C-A8AF-5AB2D779C174}.Release|x86.ActiveCfg = Release|x86 - {1C317052-9B87-471C-A8AF-5AB2D779C174}.Release|x86.Build.0 = Release|x86 {A1A5B886-2D0A-4D2A-AE13-409560D5227C}.Debug|x86.Build.0 = Debug|x86 {A1A5B886-2D0A-4D2A-AE13-409560D5227C}.Debug|x86.ActiveCfg = Debug|x86 {A1A5B886-2D0A-4D2A-AE13-409560D5227C}.Release|x86.Build.0 = Release|x86 diff --git a/MCGalaxy/Server/Maintenance/Updater.cs b/MCGalaxy/Server/Maintenance/Updater.cs index 75dac0c31..3cfc736bf 100644 --- a/MCGalaxy/Server/Maintenance/Updater.cs +++ b/MCGalaxy/Server/Maintenance/Updater.cs @@ -71,7 +71,8 @@ namespace MCGalaxy { public static void PerformUpdate() { try { try { - DeleteFiles("Changelog.txt", "MCGalaxy_.update", "MCGalaxy.update", "MCGalaxyCLI.update"); + DeleteFiles("Changelog.txt", "MCGalaxy_.update", "MCGalaxy.update", "MCGalaxyCLI.update", + "prev_MCGalaxy_.dll", "prev_MCGalaxy.exe", "prev_MCGalaxyCLI.exe"); } catch { } @@ -91,20 +92,18 @@ namespace MCGalaxy { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) pl.save(); - // Although Process.Start checks path exists, that won't work correctly when running from mono - // (since 'mono' exists but Updater.exe might not) - // So always explicitly check that Updater.exe exists here - string path = Path.Combine(Utils.FolderPath, "Updater.exe"); - if (!File.Exists(path)) throw new FileNotFoundException("Unable to find " + path); + // Move current files to previous files (by moving instead of copying, + // can overwrite original the files without breaking the server) + File.Move("MCGalaxy_.dll", "prev_MCGalaxy_.dll"); + File.Move("MCGalaxy.exe", "prev_MCGalaxy.exe"); + File.Move("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe"); - try { - Process.Start(path, "securitycheck10934579068013978427893755755270374" + exeName); - } catch { - if (Type.GetType("Mono.Runtime") == null) throw; - // if running on mono, try again with 'mono /home/user1/MCG/MCGalaxyCLI.exe' instead - Process.Start("mono", path + " securitycheck10934579068013978427893755755270374" + exeName); - } - Server.Stop(false, "Updating server."); + // Move update files to current files + File.Move("MCGalaxy_.update", "MCGalaxy_.dll"); + File.Move("MCGalaxy.update", "MCGalaxy.exe"); + File.Move("MCGalaxyCLI.update", "MCGalaxyCLI.exe"); + + Server.Stop(true, "Updating server."); } catch (Exception ex) { Logger.LogError("Error performing update", ex); } diff --git a/updater/Galaxy.ico b/updater/Galaxy.ico deleted file mode 100644 index fbca34fdc7fce3693188f56402f9b319ac4dc088..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmcgw`A?ho9e(Zi^y}N$*anQbZ7yR&%o)xQ&Txez4Uhx^0YV5z5+EcEgfwl_&~#bb zrD=Mt?T+qj*R{K(O`E12((Y-KHmTb7!=`D+51X`Um)d8~>-;kH516AD8{2t5*YkOv z=Zhei_%A0%Fn$WJxdb6y5QHc%z9qEqGTu);_}Tj(7Eyv~HbXI);Zn@->Jsdd8EKjs ze!Cd~UfE6weya#kFhMq%_}%-@sn`6!nke$S5~>TWXphJkFIRD)!G_gl8|fV!>O86as5^^Dnc6i zD>US@{vy8ypUsHRxmYCFWHWR{gjE$0wwq9yDWZ$_oUOB9ty#tDeg$Xhtyp3YR%#_& zY*cWmPQgr-h>`{=DCZm8Fvnic?ssCN)q>qN5m#F5xY6OoTC0u| z2?@ulG#rZAkdv;#shMD94;`#2$QkDQRKzo7v=>U8`+Z!>CJBj<8LvIuiw~_fA(<`1 zOKe8G3fc=~oT}Ba*kr+Si;n3Uo%6O}aleW+_TXZYIWVv126gOoJ8>eeps!p(fnQ-A zCU}T-Cu{c-b9r7B1-xe>Lqst#XY|CFu_~!3^$YmYOS|~l*FTM^RzJcv6OuvVtw6+5 zy^Jdd6_hFn7tuU1J}eyaG-O zf;M8^Bca4CFcx#-Y>j>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tDNV!s7P(+nUY**=#azMIX*jO89Mu)NlhBzS#Ne9HGy%q>2KC5 zB|P4!;^Cx>i`>QKID5o1=6IeoT5A`Zy)c;Kh35|q@Be$i|NHm<0ym{eu>b%7 diff --git a/updater/Program.cs b/updater/Program.cs deleted file mode 100644 index fbc4b17b4..000000000 --- a/updater/Program.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Threading; -using System.Windows.Forms; - -namespace Updater { - - // !! NOTE !!! You must not use any MCGalaxy code here, as you cannot reference the dlls because updating replaces thems - class Program { - static int tries = 0; - static bool usingConsole = false; - const string check = "securitycheck10934579068013978427893755755270374"; - - static void Main(string[] args) { - AppDomain.CurrentDomain.UnhandledException += UnhandledError; - usingConsole = IsConsole(); - if (args.Length < 1 || !args[0].Contains(check)) { - ShowMessage("Updater was started incorrectly.", true); return; - } - - try { - args[0] = args[0].Replace(check, ""); - if (args[0] == ".exe") args[0] = "MCGalaxy.exe"; - - // Wait for other processes to finish - Console.WriteLine("Waiting for " + args[0] + " to exit..."); - while (Process.GetProcessesByName(args[0]).Length > 0) { - Thread.Sleep(1); - } - } catch (Exception e) { - UpdateFailed(e); - } - Update(args); - } - - static bool IsConsole() { - try { - string[] lines = File.ReadAllLines("Viewmode.cfg"); - foreach (string line in lines) { - // Find the cli = true/false line - if (!line.StartsWith("cli")) continue; - int sep = line.IndexOf('='); - if (sep == -1) continue; - - string value = line.Substring(sep + 1).Trim(); - return value.Equals("true", StringComparison.OrdinalIgnoreCase); - } - } catch { - } - return false; - } - - static void Update(string[] args) { - Console.WriteLine("Updating MCGalaxy..."); - // No files to update - if (!File.Exists("MCGalaxy.update") && !File.Exists("MCGalaxy_.update")) { - ShowMessage("Updater has no files to update", true); return; - } - - for (tries = 1; tries <= 3; tries++) { - if (!UpdateFile("MCGalaxy", ".exe")) continue; - if (!UpdateFile("MCGalaxy_", ".dll")) continue; - if (!UpdateFile("MCGalaxyCLI", ".exe")) continue; - - TryStartProcess(args[0]); - return; - } - } - - static bool UpdateFile(string name, string ext) { - if (!File.Exists(name + ".update")) return true; - - try { - if (File.Exists(name + ext)) { - if (File.Exists(name + ".backup")) - File.Delete(name + ".backup"); - File.Move(name + ext, name + ".backup"); - } - - File.Move(name + ".update", name + ext); - return true; - } catch (Exception ex) { - Retry(ex); - return false; - } - } - - static void Retry(Exception ex) { - if (tries == 3) { - UpdateFailed(ex); - } else { - Console.WriteLine("\n\nAn error occured while updating. Retrying...\n\n"); - Thread.Sleep(100); - } - } - - - static void StartProcess(string file) { - try { - Process.Start(file); - } catch { - if (Type.GetType("Mono.Runtime") == null) throw; - - // if running on mono, try again with 'mono /home/user1/MCG/MCGalaxyCLI.exe' instead - string absolutePath = AppDomain.CurrentDomain.BaseDirectory; - Process.Start("mono", Path.Combine(absolutePath, file)); - } - } - - static void TryStartProcess(string file) { - Console.WriteLine("Successfully updated MCGalaxy. Starting..."); - try { - StartProcess(file); - } catch (Exception) { - ShowMessage("Updater has updated MCGalaxy, but was unable to start it. You will need to start it manually.", false); - } - } - - - static void UpdateFailed(Exception e) { - ShowMessage("Updater failed to update MCGalaxy:\n\n" + e, true); - } - - static void UnhandledError(object sender, UnhandledExceptionEventArgs args) { - Exception e = (Exception)args.ExceptionObject; - ShowMessage("UnhandledException:\n\n" + e, true); - } - - static void ShowMessage(string message, bool error) { - if (usingConsole) { - Console.WriteLine(message); - } else { - string title = error ? "Updater Error" : "Updater"; - MessageBoxIcon icon = error ? MessageBoxIcon.Error : MessageBoxIcon.Information; - MessageBox.Show(message, title, MessageBoxButtons.OK, icon); - } - - if (error) Environment.Exit(0); - } - } -} diff --git a/updater/Properties/AssemblyInfo.cs b/updater/Properties/AssemblyInfo.cs deleted file mode 100644 index b809f3651..000000000 --- a/updater/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Updater")] -[assembly: AssemblyDescription("Simple updater for MCGalaxy")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Updater")] -[assembly: AssemblyCopyright("Copyright © 2011")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("a0c78baf-3bac-45d1-bc11-fda489845e08")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/updater/Updater.csproj b/updater/Updater.csproj deleted file mode 100644 index 0b0b0ca01..000000000 --- a/updater/Updater.csproj +++ /dev/null @@ -1,98 +0,0 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {1C317052-9B87-471C-A8AF-5AB2D779C174} - Exe - Properties - Updater - Updater - v4.0 - - - 512 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - False - - - x86 - true - full - true - ..\bin\Debug\ - TRACE - prompt - 4 - - - x86 - pdbonly - true - ..\bin\Release\ - TRACE - prompt - 4 - - - Updater.Program - - - Galaxy.ico - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file diff --git a/updater/app.config b/updater/app.config deleted file mode 100644 index b08d85c41..000000000 --- a/updater/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - -