diff --git a/RHLauncher.Helper/ServiceFileHandler.cs b/RHLauncher.Helper/ServiceFileHandler.cs index ca78a3b..8184919 100644 --- a/RHLauncher.Helper/ServiceFileHandler.cs +++ b/RHLauncher.Helper/ServiceFileHandler.cs @@ -19,15 +19,31 @@ namespace RHLauncher.RHLauncher.Helper string md5 = CalculateMD5(service); string serviceDatPath = Path.Combine(_installDirectory, "Service.dat"); - string[] lines = File.ReadAllLines(serviceDatPath); - string currentMd5 = lines[0]; - string currentService = string.Join(Environment.NewLine, lines, 1, lines.Length - 1); - - if (currentMd5 != md5) + try { - lines[0] = md5; - File.WriteAllLines(serviceDatPath, lines); + if (File.Exists(serviceDatPath)) + { + string[] lines = File.ReadAllLines(serviceDatPath); + + string currentMd5 = lines[0]; + string currentService = string.Join(Environment.NewLine, lines, 1, lines.Length - 1); + + if (currentMd5 != md5) + { + lines[0] = md5; + File.WriteAllLines(serviceDatPath, lines); + } + } + else + { + MsgBoxForm.Show("Service.dat file does not exist. Please check if the Install Directory is correct.", LocalizedStrings.Error); + return; + } + } + catch (Exception ex) + { + MsgBoxForm.Show("An error occurred while updating service: " + ex.Message, LocalizedStrings.Error); } } diff --git a/RHLauncher.LauncherForm/LauncherForm.cs b/RHLauncher.LauncherForm/LauncherForm.cs index aafb460..f451e88 100644 --- a/RHLauncher.LauncherForm/LauncherForm.cs +++ b/RHLauncher.LauncherForm/LauncherForm.cs @@ -145,6 +145,11 @@ namespace RHLauncher LaunchButton.Click -= LaunchGameButton_Click; LaunchButton.Click += LaunchGameButton_Click; break; + case UpdateState.Error: + LaunchButton.Text = LocalizedStrings.Launch; + LaunchButton.Click -= LaunchGameButton_Click; + LaunchButton.Click += LaunchGameButton_Click; + break; } } catch (Exception ex) diff --git a/RHLauncher.RegForm/RegForm.cs b/RHLauncher.RegForm/RegForm.cs index 9ff6459..7f25254 100644 --- a/RHLauncher.RegForm/RegForm.cs +++ b/RHLauncher.RegForm/RegForm.cs @@ -37,7 +37,7 @@ namespace RHLauncher private async Task SendEmailRequestAsync() { using HttpClient client = new(); - HttpResponseMessage response = await client.PostAsync(SendCodeUrl, new FormUrlEncodedContent(new[] + using HttpResponseMessage response = await client.PostAsync(SendCodeUrl, new FormUrlEncodedContent(new[] { new KeyValuePair("email", EmailTextBox.Text), @@ -99,7 +99,7 @@ namespace RHLauncher private async Task VerifyCodeSendRequestAsync() { using HttpClient client = new(); - HttpResponseMessage response = await client.PostAsync(VerifyCodeUrl, new FormUrlEncodedContent(new[] + using HttpResponseMessage response = await client.PostAsync(VerifyCodeUrl, new FormUrlEncodedContent(new[] { new KeyValuePair("email", EmailTextBox.Text), new KeyValuePair("verification_code", CodeTextBox.Text), @@ -113,7 +113,7 @@ namespace RHLauncher private async Task SendRequestAsync() { using HttpClient client = new(); - HttpResponseMessage response = await client.PostAsync(RegisterUrl, new FormUrlEncodedContent(new[] + using HttpResponseMessage response = await client.PostAsync(RegisterUrl, new FormUrlEncodedContent(new[] { new KeyValuePair("windyCode", NameTextBox.Text), new KeyValuePair("email", EmailTextBox.Text), diff --git a/RHLauncher/LauncherUpdater.cs b/RHLauncher/LauncherUpdater.cs index c9b620e..70505e4 100644 --- a/RHLauncher/LauncherUpdater.cs +++ b/RHLauncher/LauncherUpdater.cs @@ -17,7 +17,7 @@ namespace RHLauncher try { using HttpClient client = new(); - HttpResponseMessage response = await client.GetAsync(LauncherVersionUrl); + using HttpResponseMessage response = await client.GetAsync(LauncherVersionUrl); response.EnsureSuccessStatusCode(); string json = await response.Content.ReadAsStringAsync(); dynamic result = JsonConvert.DeserializeObject(json);