Skip to content

Commit

Permalink
Update to v0.1.0-beta4 (#47)
Browse files Browse the repository at this point in the history
* #46 Remove redundant command execution in GmlButton

The `Command.Execute` call within the button click event handler was redundant since the command is already executed elsewhere. This change improves code readability and prevents potential double execution of the command.

* Handle disk full errors with new localized messages.

Added a new IsDiskFull resource string in multiple languages to display an error message when the disk is full. Updated the SystemService and OverviewPageViewModel to catch IOException and check for disk full errors using the new IsDiskFull method in SystemService.

* Add error handling for game profile initialization

Introduce a new error message "GameProfileError" in resource files. Implement logic to capture and display this error when initializing game profiles, ensuring errors are properly logged and displayed to the user.

* Add placeholder for Sentry Java logging

Commented-out code added as a placeholder for future Sentry logging implementation. This will facilitate capturing Java log4j-related exceptions once the actual logging code is integrated.

* Update submodule link Gml.Client
  • Loading branch information
GamerVII-NET authored Aug 11, 2024
1 parent 1be45b0 commit eaf4c00
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Gml.Client
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class ResourceKeysDictionary
public const string InstallingUpdates = "InstallingUpdates";
public const string FailedOs = "FailedOs";
public const string JavaNotFound = "JavaNotFound";
public const string IsDiskFull = "IsDiskFull";
public const string Host = "{{HOST}}";
public const string FolderName = "{{FOLDER_NAME}}";
}
4 changes: 2 additions & 2 deletions src/Gml.Launcher/Assets/Resources/ResourceKeysDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public static class ResourceKeysDictionary
public const string MainPageTitle = "DefaultPageTitle";
public const string DefaultPageTitle = "DefaultPageTitle";
public const string Error = "Error";
public const string GameProfileError = "GameProfileError";
public const string InvalidFolder = "InvalidFolder";
public const string NotSetting = "NotSetting";
public const string Updating = "Updating";
Expand All @@ -23,9 +24,8 @@ public static class ResourceKeysDictionary
public const string CheckUpdates = "CheckUpdates";
public const string InstallingUpdates = "InstallingUpdates";
public const string FailedOs = "FailedOs";

public const string JavaNotFound = "JavaNotFound";

public const string IsDiskFull = "IsDiskFull";
// public const string Host = "https://gmlb.recloud.tech";
public const string Host = "https://gmlb-test.recloud.tech";
public const string FolderName = "GamerVIILacunerhV2";
Expand Down
16 changes: 16 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,10 @@
<data name="InvalidFolder" xml:space="preserve">
<value>Failed to change the installation folder or an error occurred while changing the folder.</value>
</data>
<data name="IsDiskFull" xml:space="preserve">
<value>Not enough disk space</value>
</data>
<data name="GameProfileError" xml:space="preserve">
<value>Error initializing the game profile.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,10 @@
<data name="InvalidFolder" xml:space="preserve">
<value>Failed to change the installation folder or an error occurred while changing the folder.</value>
</data>
<data name="IsDiskFull" xml:space="preserve">
<value>Not enough disk space</value>
</data>
<data name="GameProfileError" xml:space="preserve">
<value>Error initializing the game profile.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,10 @@
<data name="InvalidFolder" xml:space="preserve">
<value>Не получилось сменить папку установки или произошла ошибка при смене папки</value>
</data>
<data name="IsDiskFull" xml:space="preserve">
<value>Недостаточно места на диске</value>
</data>
<data name="GameProfileError" xml:space="preserve">
<value>Ошибка инициализации игрового профиля.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Gml.Launcher/Core/Services/ISystemService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Gml.Launcher.Models;
using Gml.Web.Api.Domains.System;
Expand Down Expand Up @@ -52,4 +53,6 @@ public interface ISystemService
/// </summary>
/// <returns>A task representing the asynchronous operation.</returns>
Task LoadSystemData();

bool IsDiskFull(IOException ioException);
}
8 changes: 8 additions & 0 deletions src/Gml.Launcher/Core/Services/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Gml.Launcher.Models;
using Gml.Web.Api.Domains.System;
Expand All @@ -15,6 +16,7 @@ public class SystemService : ISystemService
{
private const string NotSupportedMessage = "The operating system is not supported.";
private readonly HardwareInfo _hardwareInfo = new();
const int ERROR_DISK_FULL = 0x70;

public ulong GetMaxRam()
{
Expand Down Expand Up @@ -63,6 +65,12 @@ public async Task LoadSystemData()
await Task.WhenAll(refreshDriveListTask, refreshMotherboardListTask, refreshCpuListTask);
}

public bool IsDiskFull(IOException ioException)
{
int hr = Marshal.GetHRForException(ioException);
return (hr & 0xFFFF) == ERROR_DISK_FULL;
}

public OsType GetOsType()
{
if (IsWindows()) return OsType.Windows;
Expand Down
34 changes: 33 additions & 1 deletion src/Gml.Launcher/ViewModels/Pages/OverviewPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ await ExecuteFromNewThread(async () =>
_gameProcess?.Close();
_gameProcess = await GenerateProcess(cancellationToken, profileInfo);
_gameProcess.Start();
_gameProcess.BeginOutputReadLine();
_gameProcess.BeginErrorReadLine();

await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
Dispatcher.UIThread.Invoke(() => _mainViewModel._gameLaunched.OnNext(true));
UpdateProgress(string.Empty, string.Empty, false);
Expand All @@ -178,6 +181,13 @@ await ExecuteFromNewThread(async () =>

Console.WriteLine(exception);
}
catch (IOException ioException) when (_systemService.IsDiskFull(ioException))
{
ShowError(ResourceKeysDictionary.Error,
LocalizationService.GetString(ResourceKeysDictionary.IsDiskFull));

Console.WriteLine(ioException);
}
catch (Exception exception)
{
ShowError(ResourceKeysDictionary.Error, string.Join(". ", exception.Message));
Expand Down Expand Up @@ -207,7 +217,29 @@ private async Task<Process> GenerateProcess(CancellationToken cancellationToken,

await _gmlManager.DownloadNotInstalledFiles(profileInfo.Data, cancellationToken);

var process = await _gmlManager.GetProcess(profileInfo.Data, _systemService.GetOsType());
Process process = await _gmlManager.GetProcess(profileInfo.Data, _systemService.GetOsType());

process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine(e.Data);

// ToDo: Add sentry java logging
// if (e.Data.Contains("log4j:Throwable"))
// {
//
// }
}
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data) && !e.Data.Contains("[gml-patch]"))
{
ShowError(ResourceKeysDictionary.GameProfileError, e.Data);
}
};

await _gmlManager.ClearFiles(profileInfo.Data);

Expand Down
6 changes: 1 addition & 5 deletions src/Gml.Launcher/Views/Components/GmlButton.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
base.OnApplyTemplate(e);

if (this.GetTemplateChildren().First() is Button button)
button.Click += (sender, args) =>
{
RaiseEvent(new RoutedEventArgs(ClickEvent));
Command?.Execute(CommandParameter);
};
button.Click += (_, _) => RaiseEvent(new RoutedEventArgs(ClickEvent));;
}
}

0 comments on commit eaf4c00

Please sign in to comment.