diff --git a/Download.cs b/Download.cs index 4c6881f..06af21d 100644 --- a/Download.cs +++ b/Download.cs @@ -8,7 +8,7 @@ public partial class Download : Form { private string set_download = ""; private string set_folder = ""; - private DownloadService dl; + private DownloadService? dl = null; public Download(string url_download = "", string folder_download = "") { @@ -56,7 +56,7 @@ private void btDownload_Click(object sender, EventArgs e) } catch (Exception ek) { - MessageBox.Show($"Failed downloading Data", "Oh Snap!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + MessageBox.Show($"Failed downloading Data: "+ek.Message, "Oh Snap!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else diff --git a/Main.Designer.cs b/Main.Designer.cs index 54a1c23..a6a590f 100644 --- a/Main.Designer.cs +++ b/Main.Designer.cs @@ -30,7 +30,7 @@ private void InitializeComponent() { components = new System.ComponentModel.Container(); ListViewItem listViewItem1 = new ListViewItem(new string[] { "Yuuki", "tes.yuuki.me", "N/A", "N/A", "N/A" }, -1); - btStart = new Button(); + btStartNormal = new Button(); GetServerHost = new TextBox(); label2 = new Label(); GetProxyPort = new TextBox(); @@ -41,6 +41,7 @@ private void InitializeComponent() Set_LA_GameFolder = new TextBox(); label5 = new Label(); groupBox8 = new GroupBox(); + btStartYuukiServer = new Button(); GetTypeGame = new ComboBox(); btStartOfficialServer = new Button(); grProfile = new GroupBox(); @@ -162,23 +163,23 @@ private void InitializeComponent() tabPage7.SuspendLayout(); SuspendLayout(); // - // btStart + // btStartNormal // - btStart.Font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Point); - btStart.Location = new Point(6, 61); - btStart.Name = "btStart"; - btStart.Size = new Size(105, 38); - btStart.TabIndex = 0; - btStart.Text = "Launch"; - btStart.UseVisualStyleBackColor = true; - btStart.Click += btStart_Click; + btStartNormal.Font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Point); + btStartNormal.Location = new Point(6, 61); + btStartNormal.Name = "btStartNormal"; + btStartNormal.Size = new Size(105, 38); + btStartNormal.TabIndex = 0; + btStartNormal.Text = "Launch"; + btStartNormal.UseVisualStyleBackColor = true; + btStartNormal.Click += btStartNormal_Click; // // GetServerHost // GetServerHost.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point); GetServerHost.Location = new Point(6, 20); GetServerHost.Name = "GetServerHost"; - GetServerHost.Size = new Size(253, 35); + GetServerHost.Size = new Size(232, 35); GetServerHost.TabIndex = 2; // // label2 @@ -236,7 +237,7 @@ private void InitializeComponent() grConfigGameLite.Controls.Add(Set_LA_GameFolder); grConfigGameLite.Controls.Add(label5); grConfigGameLite.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - grConfigGameLite.Location = new Point(8, 126); + grConfigGameLite.Location = new Point(8, 111); grConfigGameLite.Name = "grConfigGameLite"; grConfigGameLite.Size = new Size(420, 59); grConfigGameLite.TabIndex = 19; @@ -273,36 +274,48 @@ private void InitializeComponent() // // groupBox8 // + groupBox8.Controls.Add(btStartYuukiServer); groupBox8.Controls.Add(GetServerHost); - groupBox8.Controls.Add(btStart); + groupBox8.Controls.Add(btStartNormal); groupBox8.Controls.Add(GetTypeGame); groupBox8.Controls.Add(btStartOfficialServer); groupBox8.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); groupBox8.Location = new Point(8, 6); groupBox8.Name = "groupBox8"; - groupBox8.Size = new Size(420, 114); + groupBox8.Size = new Size(420, 106); groupBox8.TabIndex = 18; groupBox8.TabStop = false; groupBox8.Text = "Connect to server"; // + // btStartYuukiServer + // + btStartYuukiServer.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); + btStartYuukiServer.Location = new Point(326, 20); + btStartYuukiServer.Name = "btStartYuukiServer"; + btStartYuukiServer.Size = new Size(91, 35); + btStartYuukiServer.TabIndex = 20; + btStartYuukiServer.Text = "YuukiPS"; + btStartYuukiServer.UseVisualStyleBackColor = true; + btStartYuukiServer.Click += btStartYuukiServer_Click; + // // GetTypeGame // GetTypeGame.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point); GetTypeGame.FormattingEnabled = true; GetTypeGame.Location = new Point(117, 61); GetTypeGame.Name = "GetTypeGame"; - GetTypeGame.Size = new Size(290, 38); + GetTypeGame.Size = new Size(300, 38); GetTypeGame.TabIndex = 14; GetTypeGame.SelectedIndexChanged += GetTypeGame_SelectedIndexChanged; // // btStartOfficialServer // btStartOfficialServer.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); - btStartOfficialServer.Location = new Point(265, 20); + btStartOfficialServer.Location = new Point(244, 20); btStartOfficialServer.Name = "btStartOfficialServer"; - btStartOfficialServer.Size = new Size(142, 35); + btStartOfficialServer.Size = new Size(81, 35); btStartOfficialServer.TabIndex = 13; - btStartOfficialServer.Text = "Official Server"; + btStartOfficialServer.Text = "Official"; btStartOfficialServer.UseVisualStyleBackColor = true; btStartOfficialServer.Click += btStartOfficialServer_Click; // @@ -313,7 +326,7 @@ private void InitializeComponent() grProfile.Controls.Add(btsave); grProfile.Controls.Add(label8); grProfile.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - grProfile.Location = new Point(8, 191); + grProfile.Location = new Point(6, 176); grProfile.Name = "grProfile"; grProfile.Size = new Size(420, 108); grProfile.TabIndex = 17; @@ -365,9 +378,9 @@ private void InitializeComponent() // grExtra // grExtra.Controls.Add(Extra_AkebiGC); - grExtra.Location = new Point(277, 302); + grExtra.Location = new Point(431, 264); grExtra.Name = "grExtra"; - grExtra.Size = new Size(151, 70); + grExtra.Size = new Size(217, 52); grExtra.TabIndex = 12; grExtra.TabStop = false; grExtra.Text = "Extra"; @@ -388,9 +401,9 @@ private void InitializeComponent() grProxy.Controls.Add(stIsRunProxy); grProxy.Controls.Add(CheckProxyEnable); grProxy.Controls.Add(label2); - grProxy.Location = new Point(8, 305); + grProxy.Location = new Point(431, 191); grProxy.Name = "grProxy"; - grProxy.Size = new Size(263, 67); + grProxy.Size = new Size(215, 67); grProxy.TabIndex = 11; grProxy.TabStop = false; grProxy.Text = "Proxy"; @@ -1303,7 +1316,7 @@ private void InitializeComponent() #endregion - private Button btStart; + private Button btStartNormal; private TextBox GetServerHost; private Label label2; private TextBox GetProxyPort; @@ -1409,5 +1422,6 @@ private void InitializeComponent() private Button btload; private GroupBox groupBox8; private GroupBox grConfigGameLite; + private Button btStartYuukiServer; } } \ No newline at end of file diff --git a/Main.cs b/Main.cs index 955d85c..d990074 100644 --- a/Main.cs +++ b/Main.cs @@ -17,7 +17,7 @@ public partial class Main : Form private Process? progress; // Server List - Thread thServerList; + Thread? thServerList = null; List ListServer = new List { new DataServer() }; @@ -40,17 +40,17 @@ public partial class Main : Form Extra.Discord discord = new Extra.Discord(); // Game - public Game.Genshin.Settings settings_genshin; + public Game.Genshin.Settings? settings_genshin = null; //KeyGS key; - Patch get_version; + Patch? get_version = null; public Main() { InitializeComponent(); } - [Obsolete] + private void Main_Load(object sender, EventArgs e) { Console.WriteLine("Loading...."); @@ -76,26 +76,26 @@ private void Main_Load(object sender, EventArgs e) notbootyet = false; } - private void btload_Click(object sender, EventArgs e) + private void btload_Click(object? sender, EventArgs e) { var get_select_profile = GetProfileServer.Text; LoadProfile(get_select_profile); } - private void Set_LA_Save_Click(object sender, EventArgs e) + private void Set_LA_Save_Click(object? sender, EventArgs e) { var get_select_profile = GetProfileServer.Text; SaveProfile(get_select_profile); } - private void GetProfileServer_SelectedIndexChanged(object sender, EventArgs e) + private void GetProfileServer_SelectedIndexChanged(object? sender, EventArgs e) { var get_select_profile = GetProfileServer.Text; Console.WriteLine("GetProfileServer_SelectedIndexChanged " + get_select_profile); LoadProfile(get_select_profile); } - private void GetTypeGame_SelectedIndexChanged(object sender, EventArgs e) + private void GetTypeGame_SelectedIndexChanged(object? sender, EventArgs e) { default_profile.game.type = (GameType)GetTypeGame.SelectedItem; } @@ -221,7 +221,7 @@ public void SaveProfile(string name_save = "Default") } catch (Exception ex) { - Console.WriteLine("Error save config, so reload it"); + Console.WriteLine("Error save config (" + ex.Message + "), so reload it"); configdata = new Config() { profile = new List() { tmp_profile } }; } @@ -240,8 +240,6 @@ public void SaveProfile(string name_save = "Default") } } - - private void btStartOfficialServer_Click(object sender, EventArgs e) { GetServerHost.Text = "official"; @@ -249,7 +247,14 @@ private void btStartOfficialServer_Click(object sender, EventArgs e) DoStart(); } - private void btStart_Click(object sender, EventArgs e) + private void btStartYuukiServer_Click(object sender, EventArgs e) + { + GetServerHost.Text = "https://ps.yuuki.me"; + CheckProxyEnable.Checked = true; + DoStart(); + } + + private void btStartNormal_Click(object sender, EventArgs e) { DoStart(); } @@ -453,11 +458,7 @@ public void DoStart() //open bat //Process.Start(file_update_AkebiGC); - ProcessStartInfo pInfo = new ProcessStartInfo(); - pInfo.FileName = file_update_AkebiGC; - Process p = Process.Start(pInfo); - - p.WaitForExit(); + Process.Start(new ProcessStartInfo(file_update_AkebiGC))?.WaitForExit(); // Update MD5 File.WriteAllText(get_AkebiGC_md5, version_akebi); @@ -761,11 +762,11 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = var use_channel = get_version.channel; // LOCALHOST - string MD5_UA_API_Original; - string MD5_UA_API_Patched; - string MD5_Metadata_API_Original; - string MD5_Metadata_API_Patched; - string MD5_API_Patched; + string MD5_UA_API_Original = ""; + string MD5_UA_API_Patched = ""; + string MD5_Metadata_API_Original = ""; + string MD5_Metadata_API_Patched = ""; + string MD5_API_Patched = ""; var DL_Patch = ""; if (get_version.patched != null) @@ -790,34 +791,34 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = // Select Metode (via API Cloud) if (use_channel == "OS") { - MD5_UA_API_Original = get_version.original.md5_check.os.userassembly.ToUpper(); - MD5_UA_API_Patched = get_version.patched.md5_vaild.os.ToUpper(); + MD5_UA_API_Original = get_version.original?.md5_check.os.userassembly.ToUpper() ?? string.Empty; + MD5_UA_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty; - MD5_Metadata_API_Original = get_version.original.md5_check.os.metadata; - MD5_Metadata_API_Patched = get_version.patched.md5_vaild.os.ToUpper(); + MD5_Metadata_API_Original = get_version.original?.md5_check.os.metadata ?? string.Empty; + MD5_Metadata_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty; - key_to_patch = get_version.patched.key_patch; - key_to_find = get_version.original.key_find.os; + key_to_patch = get_version.patched?.key_patch; + key_to_find = get_version.original?.key_find.os; Original_file_MA = DL_Original + "GenshinImpact_Data/Managed/Metadata/global-metadata.dat"; Original_file_UA = DL_Original + "GenshinImpact_Data/Native/UserAssembly.dll"; - MD5_API_Patched = get_version.patched.md5_vaild.os.ToUpper(); + MD5_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty; } else if (use_channel == "CN") { - MD5_UA_API_Original = get_version.original.md5_check.cn.userassembly.ToUpper(); - MD5_UA_API_Patched = get_version.patched.md5_vaild.cn.ToUpper(); + MD5_UA_API_Original = get_version.original?.md5_check.cn.userassembly.ToUpper() ?? string.Empty; + MD5_UA_API_Patched = get_version.patched?.md5_vaild.cn.ToUpper() ?? string.Empty; - MD5_Metadata_API_Original = get_version.original.md5_check.cn.metadata; - MD5_Metadata_API_Patched = get_version.patched.md5_vaild.cn.ToUpper(); + MD5_Metadata_API_Original = get_version.original?.md5_check.cn.metadata ?? string.Empty; + MD5_Metadata_API_Patched = get_version.patched?.md5_vaild.cn.ToUpper() ?? string.Empty; - key_to_patch = get_version.patched.key_patch; - key_to_find = get_version.original.key_find.cn; + key_to_patch = get_version.patched?.key_patch; + key_to_find = get_version.original?.key_find.cn; Original_file_MA = DL_Original + "YuanShen_Data/Managed/Metadata/global-metadata.dat"; Original_file_UA = DL_Original + "YuanShen_Data/Native/UserAssembly.dll"; - MD5_API_Patched = get_version.patched.md5_vaild.os.ToUpper(); + MD5_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty; } else { @@ -907,8 +908,9 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently); Console.WriteLine("We copy PathfileUA_Original to PathfileUA_Currently (UserAssembly) (33)"); } - catch (Exception exx) + catch (Exception) { + // skip return "Error copy (1)"; } } @@ -941,8 +943,9 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently); Console.WriteLine("We copy PathfileUA_Original to PathfileUA_Currently (UserAssembly) (6)"); } - catch (Exception exx) + catch (Exception) { + // skip return "Error copy (2)"; } } @@ -1003,8 +1006,9 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_UA_LOC_Original = Tool.CalculateMD5(PathfileUA_Original); Console.WriteLine("We copy file in PathfileUA_Currently to PathfileUA_Original files (22)"); } - catch (Exception exx) + catch (Exception) { + // skip return "Error copy PathfileUA_Currently to PathfileUA_Original (1)"; } } @@ -1030,8 +1034,9 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_Metadata_LOC_Currently = Tool.CalculateMD5(PathfileMetadata_Currently); Console.WriteLine("We copy PathfileMetadata_Original to PathfileMetadata_Currently"); } - catch (Exception exx) + catch (Exception) { + // skip return "Error copy PathfileMetadata_Original to PathfileMetadata_Currently (111)"; } } @@ -1066,8 +1071,9 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_Metadata_LOC_Currently = Tool.CalculateMD5(PathfileMetadata_Currently); Console.WriteLine("We copy file PathfileMetadata_Original to PathfileMetadata_Currently (6)"); } - catch (Exception exx) + catch (Exception) { + // skip return "Error copy PathfileMetadata_Original to PathfileMetadata_Currently (111)"; } } @@ -1128,7 +1134,7 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = MD5_Metadata_LOC_Original = Tool.CalculateMD5(PathfileMetadata_Original); Console.WriteLine("We copy file in PathfileMetadata_Currently to PathfileMetadata_Original files (22)"); } - catch (Exception exx) + catch (Exception) { return "Error copy PathfileMetadata_Currently to PathfileMetadata_Original (1)"; } @@ -1149,7 +1155,7 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = { File.Delete(PathfileUA_Original); } - catch (Exception exx) + catch (Exception) { // skip } @@ -1164,7 +1170,7 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = { File.Delete(PathfileMetadata_Original); } - catch (Exception exx) + catch (Exception) { // skip } @@ -1279,7 +1285,7 @@ public string PatchGame(bool patchit = true, bool online = true, string metode = } // keep patch - var ManualUA = Game.Genshin.Patch.UserAssembly.Do(PathfileUA_Currently, PathfileUA_Patched, key_to_find, key_to_patch); + var ManualUA = Game.Genshin.Patch.UserAssembly.Do(PathfileUA_Currently, PathfileUA_Patched, key_to_find!, key_to_patch!); if (!String.IsNullOrEmpty(ManualUA)) { return "Error Patch UserAssembly: " + ManualUA; @@ -1568,7 +1574,7 @@ public void CheckUpdate() var GetDataUpdate = API.GetUpdate(); if (GetDataUpdate != null) { - var judul = GetDataUpdate.name; // is dev or nightly or name update + var judul = "New Update: " + GetDataUpdate.name; // is dev or nightly or name update var name_version = GetDataUpdate.tag_name; // version name var infobody = GetDataUpdate.body; // info @@ -1730,6 +1736,7 @@ public void IsAcess(bool onoff) { GetTypeGame.Enabled = onoff; btStartOfficialServer.Enabled = onoff; + btStartYuukiServer.Enabled = onoff; GetServerHost.Enabled = onoff; grProxy.Enabled = onoff; @@ -1738,8 +1745,6 @@ public void IsAcess(bool onoff) grProfile.Enabled = onoff; } - - [Obsolete] private void CheckGameRun_Tick(object sender, EventArgs e) { var isrun = Process.GetProcesses().Where(pr => pr.ProcessName == "YuanShen" || pr.ProcessName == "GenshinImpact" || pr.ProcessName == "StarRail" || pr.ProcessName == "injector"); @@ -1747,7 +1752,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e) { // Jika Game tidak berjalan.... IsGameRun = false; - btStart.Text = "Launch"; + btStartNormal.Text = "Launch"; IsAcess(true); AllStop(); @@ -1774,7 +1779,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e) { // jika game jalan IsGameRun = true; - btStart.Text = "Stop"; + btStartNormal.Text = "Stop"; DoneCheck = false; IsAcess(false); @@ -1786,14 +1791,12 @@ private void CheckGameRun_Tick(object sender, EventArgs e) } } - [Obsolete] public void AllStop() { StopProxy(); StopGame(); } - [Obsolete] public void StopProxy() { if (proxy != null) @@ -1870,7 +1873,7 @@ private void linkDiscord_LinkClicked(object sender, LinkLabelLinkClickedEventArg private void linkGithub_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - Process.Start(new ProcessStartInfo("https://github.com/YuukiPS/Launcher-PC") { UseShellExecute = true }); + Process.Start(new ProcessStartInfo("https://github.com/YuukiPS/") { UseShellExecute = true }); } private void linkWeb_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -1886,7 +1889,6 @@ private void CekUpdateTT_Tick(object sender, EventArgs e) } } - [Obsolete] private void Main_FormClosing(object sender, FormClosingEventArgs e) { if (IsGameRun) @@ -1896,15 +1898,11 @@ private void Main_FormClosing(object sender, FormClosingEventArgs e) } } - - - [Obsolete] private void CheckProxyRun_Tick(object sender, EventArgs e) { CheckProxy(false); } - [Obsolete] void CheckProxy(bool force_off = false) { try @@ -2027,8 +2025,8 @@ public string UpdateKey() DEV_MA_Set_Key2_Patch.Text = ""; //UA - DEV_UA_Set_Key1_NoPatch.Text = get_version.original.key_find.os; - DEV_UA_Set_Key2_Patch.Text = get_version.patched.key_patch; + DEV_UA_Set_Key1_NoPatch.Text = get_version.original?.key_find.os; + DEV_UA_Set_Key2_Patch.Text = get_version.patched?.key_patch; } return "Successfully got Key, you can see update in developer tab"; } diff --git a/Yuuki/API.cs b/Yuuki/API.cs index 2c35706..08ad08b 100644 --- a/Yuuki/API.cs +++ b/Yuuki/API.cs @@ -17,17 +17,17 @@ public class API public static string API_GITHUB_YuukiPS = "https://api.github.com/repos/YuukiPS/Launcher-PC/"; public static string API_GITHUB_RSA = "https://api.github.com/repos/34736384/RSAPatch/"; - public static Client GS_DL(string dl = "os") + public static Client? GS_DL(string dl = "os") { var client = new RestClient(API_DL_WB); var request = new RestRequest("genshin/download/latest/" + dl); var response = client.Execute(request); var getme = response.StatusCode == HttpStatusCode.OK ? response.Content : response.StatusCode.ToString(); - return JsonConvert.DeserializeObject(getme); + return JsonConvert.DeserializeObject(getme!); } - public static VersionGenshin GetMD5VersionGS(string md5) + public static VersionGenshin? GetMD5VersionGS(string md5) { var client = new RestClient(API_DL_WB); var request = new RestRequest("genshin/version?md5=" + md5.ToUpper()); @@ -58,7 +58,7 @@ public static VersionGenshin GetMD5VersionGS(string md5) return null; } - public static Patch GetMD5Game(string md5, GameType type_game) + public static Patch? GetMD5Game(string md5, GameType type_game) { var url = type_game + "/patch/" + md5.ToUpper(); Console.WriteLine("GetMD5Game: " + md5 + " url: " + url); @@ -222,12 +222,6 @@ public static Patch GetMD5Game(string md5, GameType type_game) var request = new RestRequest("genshin/mod/akebi/" + ver_set); var response = client.Execute(request); - var whos = "cn"; - if (ch == 2) - { - whos = "os"; - } - if (response.StatusCode == HttpStatusCode.OK) { if (response.Content != null) @@ -237,13 +231,17 @@ public static Patch GetMD5Game(string md5, GameType type_game) var GetData = JsonConvert.DeserializeObject(response.Content); if (GetData != null) { - if (ch == 2) - { - return GetData.package.cn.md5 + "|" + GetData.package.cn.url; - } - else + var paket = GetData.package; + if (paket != null) { - return GetData.package.os.md5 + "|" + GetData.package.os.url; + if (ch == 2) + { + return $"{paket.cn?.md5}|{paket.cn?.url}"; + } + else + { + return paket.os?.md5 + "|" + paket.os?.url; + } } } } diff --git a/Yuuki/Proxy.cs b/Yuuki/Proxy.cs index bfb38a9..9d1edfa 100644 --- a/Yuuki/Proxy.cs +++ b/Yuuki/Proxy.cs @@ -8,8 +8,8 @@ namespace YuukiPS_Launcher.Yuuki { public class Proxy { - public ProxyServer proxyServer; - private ExplicitProxyEndPoint explicitEndPoint; + public ProxyServer? proxyServer = null; + private ExplicitProxyEndPoint? explicitEndPoint = null; private int port; private Uri our_server; @@ -20,7 +20,6 @@ public Proxy(int port, string host) this.our_server = new Uri(host); } - [Obsolete] public bool Start() { proxyServer = new ProxyServer(); @@ -36,7 +35,7 @@ public bool Start() { //Tool.findAndKillProcessRuningOn("" + port + ""); } - catch (Exception ex) + catch (Exception) { // skip } @@ -80,14 +79,19 @@ public bool Start() } - [Obsolete] public void Stop() { try { - explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest; - proxyServer.BeforeRequest -= OnRequest; - proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation; + if (explicitEndPoint != null) + { + explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest; + } + if (proxyServer != null) + { + proxyServer.BeforeRequest -= OnRequest; + proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation; + } } catch (Exception ex) { @@ -95,7 +99,7 @@ public void Stop() } finally { - if (proxyServer.ProxyRunning) + if (proxyServer != null && proxyServer.ProxyRunning) { Console.WriteLine("Proxy Stop"); proxyServer.Stop(); @@ -111,16 +115,19 @@ public void Stop() public void UninstallCertificate() { + if (proxyServer == null) + { + return; + } proxyServer.CertificateManager.RemoveTrustedRootCertificate(); proxyServer.CertificateManager.RemoveTrustedRootCertificateAsAdmin(); } - [Obsolete] - private Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) + private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) { // Do not decrypt SSL if not required domain/host - string hostname = e.WebSession.Request.RequestUri.Host; - if (HostPrivate(hostname) | hostname.EndsWith(our_server.Host)) + string hostname = e.HttpClient.Request.RequestUri.Host; + if (HostPrivate(hostname) || hostname.EndsWith(our_server.Host)) { e.DecryptSsl = true; } @@ -128,17 +135,16 @@ private Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEve { e.DecryptSsl = false; } - return Task.CompletedTask; + await Task.CompletedTask; } - [Obsolete] private Task OnRequest(object sender, SessionEventArgs e) { // Change Host - string hostname = e.WebSession.Request.RequestUri.Host; + string hostname = e.HttpClient.Request.RequestUri.Host; if (HostPrivate(hostname)) { - var q = e.WebSession.Request.RequestUri; + var q = e.HttpClient.Request.RequestUri; var url = e.HttpClient.Request.Url; diff --git a/Yuuki/Server.cs b/Yuuki/Server.cs index 77ad76f..afdbc4c 100644 --- a/Yuuki/Server.cs +++ b/Yuuki/Server.cs @@ -73,7 +73,7 @@ public static string DLJava() { Console.WriteLine("Unzip java"); FastZip fastZip = new FastZip(); - string fileFilter = null; + string? fileFilter = null; fastZip.ExtractZip(GetJavaZip, JAVA_FOLDER, fileFilter); } catch (Exception e) @@ -105,24 +105,25 @@ public static string DLJava() } public static bool CheckJava(string p = "") { - //Console.WriteLine("JAVA Folder: " + p); - string version = ""; try { - ProcessStartInfo procStartInfo = new ProcessStartInfo(p + "\\java", "-version "); - procStartInfo.RedirectStandardOutput = true; - procStartInfo.RedirectStandardError = true; - procStartInfo.UseShellExecute = false; - procStartInfo.CreateNoWindow = true; - Process proc = new Process(); - proc.StartInfo = procStartInfo; - proc.Start(); - version = proc.StandardError.ReadLine(); - //Console.WriteLine("JAVA: " + version); - if (version.Contains(JAVA_RQS)) + ProcessStartInfo? procStartInfo = new ProcessStartInfo(p + "\\java", "-version "); + procStartInfo!.RedirectStandardOutput = true; + procStartInfo!.RedirectStandardError = true; + procStartInfo!.UseShellExecute = false; + procStartInfo!.CreateNoWindow = true; + + if (procStartInfo != null) { - //string strOutput = version.Split(' ')[2].Replace("\"", ""); - return true; + Process proc = new Process(); + proc.StartInfo = procStartInfo!; + proc.Start(); + //Console.WriteLine("JAVA Folder: " + p); + string? version = proc.StandardError?.ReadLine(); + if (version != null && version.Contains(JAVA_RQS)) + { + return true; + } } } catch (Exception e) diff --git a/Yuuki/Tool.cs b/Yuuki/Tool.cs index 68af6b5..63254f7 100644 --- a/Yuuki/Tool.cs +++ b/Yuuki/Tool.cs @@ -85,16 +85,17 @@ public static void ExecuteCMD(String strCommand) try { Console.WriteLine(strCommand); - ProcessStartInfo commandInfo = new ProcessStartInfo(); - commandInfo.CreateNoWindow = true; - commandInfo.UseShellExecute = false; - commandInfo.RedirectStandardInput = false; - commandInfo.RedirectStandardOutput = false; - commandInfo.FileName = "cmd.exe"; - commandInfo.Arguments = strCommand; + ProcessStartInfo? commandInfo = new ProcessStartInfo(); + commandInfo!.CreateNoWindow = true; + commandInfo!.UseShellExecute = false; + commandInfo!.RedirectStandardInput = false; + commandInfo!.RedirectStandardOutput = false; + commandInfo!.FileName = "cmd.exe"; + commandInfo!.Arguments = strCommand; + if (commandInfo != null) { - Process process = Process.Start(commandInfo); + Process? process = Process.Start(commandInfo!); if (process != null) { //process.WaitForExit(); @@ -102,7 +103,7 @@ public static void ExecuteCMD(String strCommand) } } } - catch (Exception ex) + catch (Exception) { // skip } diff --git a/YuukiPS Launcher.csproj b/YuukiPS Launcher.csproj index 32b1970..ffdbd04 100644 --- a/YuukiPS Launcher.csproj +++ b/YuukiPS Launcher.csproj @@ -12,14 +12,15 @@ Properties\app.manifest - 2023.7.6.1005 - 2023.7.6.1005 + 2023.7.6.1139 + 2023.7.6.1139 true YuukiPS Exe Asset\Image\yuuki.ico true + x64