Add ZeroTier check to installer

This commit is contained in:
sardelka9515 2022-08-21 15:13:36 +08:00
parent 84d578366a
commit 9e66762061
6 changed files with 82 additions and 11 deletions

View File

@ -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);

View File

@ -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" )]

View File

@ -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
{

View File

@ -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<int> 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();
}
}
}

View File

@ -131,5 +131,9 @@ namespace RageCoop.Core
var p = Run(command);
return p.StandardOutput.ReadToEnd()+p.StandardError.ReadToEnd();
}
public static void Check()
{
}
}
}

View File

@ -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" )]