Add more error handling

This commit is contained in:
Junior 2023-06-05 23:03:15 -03:00
parent 7917f223e1
commit 71f7609dc5
4 changed files with 32 additions and 11 deletions

View file

@ -19,15 +19,31 @@ namespace RHLauncher.RHLauncher.Helper
string md5 = CalculateMD5(service); string md5 = CalculateMD5(service);
string serviceDatPath = Path.Combine(_installDirectory, "Service.dat"); string serviceDatPath = Path.Combine(_installDirectory, "Service.dat");
string[] lines = File.ReadAllLines(serviceDatPath);
string currentMd5 = lines[0]; try
string currentService = string.Join(Environment.NewLine, lines, 1, lines.Length - 1);
if (currentMd5 != md5)
{ {
lines[0] = md5; if (File.Exists(serviceDatPath))
File.WriteAllLines(serviceDatPath, lines); {
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);
} }
} }

View file

@ -145,6 +145,11 @@ namespace RHLauncher
LaunchButton.Click -= LaunchGameButton_Click; LaunchButton.Click -= LaunchGameButton_Click;
LaunchButton.Click += LaunchGameButton_Click; LaunchButton.Click += LaunchGameButton_Click;
break; break;
case UpdateState.Error:
LaunchButton.Text = LocalizedStrings.Launch;
LaunchButton.Click -= LaunchGameButton_Click;
LaunchButton.Click += LaunchGameButton_Click;
break;
} }
} }
catch (Exception ex) catch (Exception ex)

View file

@ -37,7 +37,7 @@ namespace RHLauncher
private async Task<string> SendEmailRequestAsync() private async Task<string> SendEmailRequestAsync()
{ {
using HttpClient client = new(); 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<string, string>("email", EmailTextBox.Text), new KeyValuePair<string, string>("email", EmailTextBox.Text),
@ -99,7 +99,7 @@ namespace RHLauncher
private async Task<string> VerifyCodeSendRequestAsync() private async Task<string> VerifyCodeSendRequestAsync()
{ {
using HttpClient client = new(); 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<string, string>("email", EmailTextBox.Text), new KeyValuePair<string, string>("email", EmailTextBox.Text),
new KeyValuePair<string, string>("verification_code", CodeTextBox.Text), new KeyValuePair<string, string>("verification_code", CodeTextBox.Text),
@ -113,7 +113,7 @@ namespace RHLauncher
private async Task<string> SendRequestAsync() private async Task<string> SendRequestAsync()
{ {
using HttpClient client = new(); 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<string, string>("windyCode", NameTextBox.Text), new KeyValuePair<string, string>("windyCode", NameTextBox.Text),
new KeyValuePair<string, string>("email", EmailTextBox.Text), new KeyValuePair<string, string>("email", EmailTextBox.Text),

View file

@ -17,7 +17,7 @@ namespace RHLauncher
try try
{ {
using HttpClient client = new(); using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(LauncherVersionUrl); using HttpResponseMessage response = await client.GetAsync(LauncherVersionUrl);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync(); string json = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(json); dynamic result = JsonConvert.DeserializeObject(json);