From 9e667620614e1e9b62191e899411e0a5e29689dd Mon Sep 17 00:00:00 2001 From: sardelka9515 Date: Sun, 21 Aug 2022 15:13:36 +0800 Subject: [PATCH] Add ZeroTier check to installer --- RageCoop.Client.Installer/MainWindow.xaml.cs | 46 +++++++++++++++++++- RageCoop.Client/Properties/AssemblyInfo.cs | 4 +- RageCoop.Client/Util/Util.cs | 5 --- RageCoop.Core/Networking/HttpHelper.cs | 30 +++++++++++++ RageCoop.Core/Networking/ZeroTierHelper.cs | 4 ++ RageCoop.Server/Properties/AssemblyInfo.cs | 4 +- 6 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 RageCoop.Core/Networking/HttpHelper.cs diff --git a/RageCoop.Client.Installer/MainWindow.xaml.cs b/RageCoop.Client.Installer/MainWindow.xaml.cs index e92904b..4a9e520 100644 --- a/RageCoop.Client.Installer/MainWindow.xaml.cs +++ b/RageCoop.Client.Installer/MainWindow.xaml.cs @@ -15,7 +15,7 @@ using System.Windows.Shapes; using System.IO; using System.Diagnostics; using System.Reflection; -using RageCoop.Client; +using RageCoop.Core; using System.Threading; using System.Net; using System.Windows.Forms; @@ -54,6 +54,7 @@ namespace RageCoop.Client.Installer catch (Exception ex) { MessageBox.Show("Installation failed: " + ex.ToString()); + Environment.Exit(1); } }); } @@ -107,6 +108,7 @@ namespace RageCoop.Client.Installer foreach (var f in Directory.GetFiles(scriptsPath, "RageCoop.*", SearchOption.AllDirectories)) { + if (f.EndsWith("RageCoop.Client.Settings.xml")) { continue; } File.Delete(f); } foreach (var f in Directory.GetFiles(installPath, "*.dll", SearchOption.AllDirectories)) @@ -162,7 +164,7 @@ namespace RageCoop.Client.Installer } if (File.Exists(menyooConfig)) { - var lines = File.ReadAllLines(menyooConfig).Where(x => x.EndsWith(" = " +(int)settings.MenuKey)); + var lines = File.ReadAllLines(menyooConfig).Where(x => !x.StartsWith(";") && x.EndsWith(" = " +(int)settings.MenuKey)); if (lines.Any()) { if(MessageBox.Show("Following menyoo config value will conflict with RAGECOOP menu key\n" + @@ -189,6 +191,46 @@ namespace RageCoop.Client.Installer } } + checkZT: + UpdateStatus("Checking ZeroTier"); + try + { + ZeroTierHelper.Check(); + } + catch + { + if (MessageBox.Show("You can't join ZeroTier server unless ZeroTier is installed, do you want to download and install it?","Install ZeroTier",MessageBoxButton.YesNo)==MessageBoxResult.Yes) + { + var url = "https://download.zerotier.com/dist/ZeroTier%20One.msi"; + UpdateStatus("Downloading ZeroTier from "+url); + try + { + HttpHelper.DownloadFile(url, "ZeroTier.msi", (p) => UpdateStatus("Downloading ZeroTier " + p + "%")); + UpdateStatus("Installing ZeroTier"); + Process.Start("ZeroTier.msi").WaitForExit(); + /* + for (int i = 0; i < 10; i++) + { + Thread.Sleep(1000); + UpdateStatus("Waiting ZeroTier to start... " + i); + try + { + ZeroTierHelper.Check(); + break; + } + catch(Exception ex) { UpdateStatus(ex.ToString()); } + } + goto checkZT; + */ + } + catch + { + MessageBox.Show("Failed to download ZeroTier, please download it from officail website"); + Process.Start(url); + } + } + } + UpdateStatus("Completed!"); MessageBox.Show("Installation sucessful!"); Environment.Exit(0); diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs index 3121ad2..cd55b55 100644 --- a/RageCoop.Client/Properties/AssemblyInfo.cs +++ b/RageCoop.Client/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ using System.Resources; // Version informationr( -[assembly: AssemblyVersion("1.5.1.37")] -[assembly: AssemblyFileVersion("1.5.1.37")] +[assembly: AssemblyVersion("1.5.1.48")] +[assembly: AssemblyFileVersion("1.5.1.48")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/RageCoop.Client/Util/Util.cs b/RageCoop.Client/Util/Util.cs index f1edbde..f860084 100644 --- a/RageCoop.Client/Util/Util.cs +++ b/RageCoop.Client/Util/Util.cs @@ -128,11 +128,6 @@ namespace RageCoop.Client { settings = (Settings)ser.Deserialize(stream); } - - using (FileStream stream = new FileStream(path, FileMode.Truncate, FileAccess.ReadWrite)) - { - ser.Serialize(stream, settings); - } } else { diff --git a/RageCoop.Core/Networking/HttpHelper.cs b/RageCoop.Core/Networking/HttpHelper.cs new file mode 100644 index 0000000..596ea7b --- /dev/null +++ b/RageCoop.Core/Networking/HttpHelper.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Threading; + +namespace RageCoop.Core +{ + internal static class HttpHelper + { + public static void DownloadFile(string url,string destination,Action progressCallback) + { + AutoResetEvent ae=new AutoResetEvent(false); + WebClient client = new WebClient(); + + // TLS only + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + + client.DownloadProgressChanged += (s, e1) => progressCallback(e1.ProgressPercentage); + client.DownloadFileCompleted += (s, e2) => + { + ae.Set(); + }; + client.DownloadFileAsync(new Uri(url), destination); + ae.WaitOne(); + } + } +} diff --git a/RageCoop.Core/Networking/ZeroTierHelper.cs b/RageCoop.Core/Networking/ZeroTierHelper.cs index 1b49097..685da7d 100644 --- a/RageCoop.Core/Networking/ZeroTierHelper.cs +++ b/RageCoop.Core/Networking/ZeroTierHelper.cs @@ -131,5 +131,9 @@ namespace RageCoop.Core var p = Run(command); return p.StandardOutput.ReadToEnd()+p.StandardError.ReadToEnd(); } + public static void Check() + { + + } } } diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs index fdd228e..6af5fc8 100644 --- a/RageCoop.Server/Properties/AssemblyInfo.cs +++ b/RageCoop.Server/Properties/AssemblyInfo.cs @@ -15,7 +15,7 @@ using System.Resources; [assembly: AssemblyCulture("")] // Version informationr( -[assembly: AssemblyVersion("1.5.1.31")] -[assembly: AssemblyFileVersion("1.5.1.31")] +[assembly: AssemblyVersion("1.5.1.34")] +[assembly: AssemblyFileVersion("1.5.1.34")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]