Skip to content

Commit

Permalink
Update to v0.1.0-rc2 (#53)
Browse files Browse the repository at this point in the history
* Add LogHandler service for improved log processing

Introduced a new LogHandler class to manage and process log data more effectively. Integrated LogHandler into OverviewPageViewModel and ServiceLocator for better error handling and logging capabilities.

* Add detailed installation instructions to README.md

This update includes prerequisites, step-by-step installation commands, troubleshooting tips, updating instructions, and uninstallation steps for the GamerVII Launcher. These additions aim to provide clear, comprehensive guidance for users to correctly install, update, and uninstall the launcher.

* Add README.md to Gml.Client project in solution

This commit updates the solution file to include the README.md for the Gml.Client project. The addition helps in documenting the project directly within the solution, providing better context and guidance for developers.

* Update submodule link Gml.Client

* Prevent further processing of error data

Added a return statement at the beginning of the HandleErrorData method to immediately exit the function. This ensures that no additional code is executed within this method when it is called.

---------

Co-authored-by: GamerVII-NET <[email protected]>
  • Loading branch information
GamerVII-NET and Gamer-VII authored Oct 12, 2024
1 parent f999ab8 commit bc23fb4
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 78 deletions.
1 change: 1 addition & 0 deletions Gml.Launcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{09A802
load-repositories.bat = load-repositories.bat
load-repositories.sh = load-repositories.sh
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
src\Gml.Client\README.md = src\Gml.Client\README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gml.Launcher", "src\Gml.Launcher\Gml.Launcher.csproj", "{F2771E71-C782-4713-862F-217694DDDFF5}"
Expand Down
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,69 @@
GamerVII Launcher
=======
The Minecraft Launcher is a user-friendly application designed to streamline the process of launching Minecraft and managing game settings. It provides an intuitive interface and essential features to enhance the Minecraft gaming experience.

## Installation

### Prerequisites

Before installing the GamerVII Launcher, ensure you have the following prerequisites:

- **.NET 8.0 SDK:** You need to have .NET 8.0 SDK installed on your system. You can download it
from [Microsoft's official website](https://dotnet.microsoft.com/download/dotnet/8.0) or use a package manager
suitable for your operating system.

- **Git:** Ensure Git is installed on your system. You can download it from
the [Git website](https://git-scm.com/downloads) or use a package manager.

### Steps to Install GamerVII Launcher

1. **Clone the Repository:**
Open a terminal and clone the repository using Git with the `--recursive` option:
```bash
git clone --recursive https://github.com/GamerVII-NET/minecraft-launcher.git
cd minecraft-launcher
```

2. **Build the Project:**
Restore the dependencies and build the project using the .NET CLI:
```bash
dotnet restore
dotnet build
```

3. **Run the Launcher:**
Once the project is built, you can run the launcher using the following command:
```bash
dotnet run --project path/to/your/project
```

### Troubleshooting

If you encounter any issues during the installation, ensure the following:

- Ensure the .NET SDK is correctly installed and the `DOTNET_HOME` environment variable is set.
- Ensure Git is correctly installed and available in the terminal.
- Make sure you have the necessary permissions to run the build and execute the application.

For additional help, check the project's issue tracker or community forums.

### Updating

To update the GamerVII Launcher to the latest version, navigate to the project directory and pull the latest changes
from the repository:

```bash
git pull origin main
git submodule update --recursive --remote
dotnet build
```

Then, run the launcher again using the command mentioned earlier.

### Uninstallation

To uninstall the GamerVII Launcher, simply delete the project directory:

```bash
rm -rf minecraft-launcher
```
2 changes: 1 addition & 1 deletion src/Gml.Client
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class ResourceKeysDictionary
public const string ProfileNotConfigured = "ProfileNotConfigured";
public const string UpdatingDescription = "UpdatingDescription";
public const string InvalidAuthData = "InvalidAuthData";
public const string InvalidSession = "InvalidSession";
public const string Reconnecting = "Reconnecting";
public const string LostConnection = "LostConnection";
public const string CheckUpdates = "CheckUpdates";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class ResourceKeysDictionary
public const string ProfileNotConfigured = "ProfileNotConfigured";
public const string UpdatingDescription = "UpdatingDescription";
public const string InvalidAuthData = "InvalidAuthData";
public const string InvalidSession = "InvalidSession";
public const string Reconnecting = "Reconnecting";
public const string LostConnection = "LostConnection";
public const string CheckUpdates = "CheckUpdates";
Expand Down
8 changes: 8 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.

3 changes: 3 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@
<data name="GameProfileError" xml:space="preserve">
<value>Error initializing the game profile.</value>
</data>
<data name="InvalidSession" xml:space="preserve">
<value>Your game session in the launcher has expired, please log in again.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@
<data name="GameProfileError" xml:space="preserve">
<value>Error initializing the game profile.</value>
</data>
<data name="InvalidSession" xml:space="preserve">
<value>Your game session in the launcher has expired, please log in again.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Gml.Launcher/Assets/Resources/Resources.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@
<data name="GameProfileError" xml:space="preserve">
<value>Ошибка инициализации игрового профиля.</value>
</data>
<data name="InvalidSession" xml:space="preserve">
<value>Ваша игровая сессия в лаунчере истекла, авторизуйтесь заново</value>
</data>
</root>
6 changes: 4 additions & 2 deletions src/Gml.Launcher/Core/Converters/AsyncSkinRenderLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Avalonia.Media.Imaging;
using Gml.Client;
using Gml.Launcher.Core.Services;
using Sentry;

namespace Gml.Launcher.Core.Converters;

Expand Down Expand Up @@ -63,9 +64,10 @@ private static async void OnSourceChanged(Image sender, AvaloniaPropertyChangedE

if (!cts.Token.IsCancellationRequested) sender.Source = bitmap;
}
catch (Exception e)
catch (Exception exception)
{
Console.WriteLine(e);
Console.WriteLine(exception);
SentrySdk.CaptureException(exception);
}
finally
{
Expand Down
25 changes: 3 additions & 22 deletions src/Gml.Launcher/Core/Extensions/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public static AppBuilder RegisterServices(this AppBuilder builder)

RegisterLocalizationService();
RegisterSystemService(systemService);
RegisterLogHelper(systemService);
var manager = RegisterGmlManager(systemService, installationDirectory);
var storageService = RegisterStorage();

CheckAndChangeInstallationFolder(storageService, manager);
CheckAndChangeLanguage(storageService, systemService);
InitializeSentry();

AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
Expand All @@ -39,28 +39,9 @@ public static AppBuilder RegisterServices(this AppBuilder builder)
return builder;
}

private static void InitializeSentry()
private static void RegisterLogHelper(SystemService systemService)
{
var sentryUrl = GmlClientManager.GetSentryLink(ResourceKeysDictionary.Host).Result;

try
{
if (!string.IsNullOrEmpty(sentryUrl))
SentrySdk.Init(options =>
{
options.Dsn = sentryUrl;
options.Debug = true;
options.TracesSampleRate = 1.0;
options.DiagnosticLevel = SentryLevel.Debug;
options.IsGlobalModeEnabled = true;
options.SendDefaultPii = true;
options.MaxAttachmentSize = 10 * 1024 * 1024;
});
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
Locator.CurrentMutable.RegisterConstant(new LogHandler());
}

private static void CheckAndChangeLanguage(LocalStorageService storageService, SystemService systemService)
Expand Down
76 changes: 76 additions & 0 deletions src/Gml.Launcher/Core/Services/LogHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text.RegularExpressions;
using Sentry;

namespace Gml.Launcher.Core.Services;

public class LogHandler
{
private readonly Subject<string> _errorDataSubject = new();


public LogHandler()
{
var errorDataObservable = _errorDataSubject
.Where(data => !string.IsNullOrEmpty(data))
.Buffer(() => _errorDataSubject.Where(data => data.Contains("</log4j:Event>")))
.Select(lines => string.Join(Environment.NewLine, lines));

errorDataObservable.Subscribe(HandleErrorData);
}

private void HandleErrorData(string data)
{
return;
Debug.WriteLine(data);

if (data.Contains("Exception", StringComparison.OrdinalIgnoreCase) ||
data.Contains("<log4j:Throwable>", StringComparison.OrdinalIgnoreCase))
{
var exception = ExtractException(data);
ShowError(ResourceKeysDictionary.GameProfileError, data);
SentrySdk.CaptureException(exception);
}

if (data.Contains("[gml-patch]", StringComparison.OrdinalIgnoreCase))
{
}
else
{
ShowError(ResourceKeysDictionary.GameProfileError, data);
SentrySdk.CaptureException(new Exception(data));
}
}

private Exception ExtractException(string data)
{
var throwableRegex = new Regex(@"<log4j:Throwable><!\[CDATA\[(.*?)\]\]></log4j:Throwable>", RegexOptions.Singleline);
var match = throwableRegex.Match(data);

if (match.Success)
{
var stackTrace = match.Groups[1].Value;
return new Exception(stackTrace);
}

return new Exception(data);
}

private void ShowError(string key, string message)
{
// Реализуйте здесь показ ошибок пользователю
}

private static class ResourceKeysDictionary
{
public static string GameProfileError = "GameProfileError";
}

public void ProcessLogs(string data)
{
_errorDataSubject.OnNext(data);
}
}
34 changes: 32 additions & 2 deletions src/Gml.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Reactive;
using Avalonia;
using Avalonia.ReactiveUI;
using Gml.Client;
using Gml.Launcher.Assets;
using Gml.Launcher.Core.Extensions;
using ReactiveUI;
using Sentry;
Expand All @@ -15,13 +17,15 @@ public static void Main(string[] args)
{
try
{
InitializeSentry();
RxApp.DefaultExceptionHandler = Observer.Create<Exception>(GlobalExceptionHandler);
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
catch (Exception exception)
{
Console.WriteLine(e);
SentrySdk.CaptureException(exception);
Console.WriteLine(exception);
}
}

Expand All @@ -39,4 +43,30 @@ public static AppBuilder BuildAvaloniaApp()
.LogToTrace()
.UseReactiveUI();
}



private static void InitializeSentry()
{
var sentryUrl = GmlClientManager.GetSentryLink(ResourceKeysDictionary.Host).Result;

try
{
if (!string.IsNullOrEmpty(sentryUrl))
SentrySdk.Init(options =>
{
options.Dsn = sentryUrl;
options.Debug = true;
options.TracesSampleRate = 1.0;
options.DiagnosticLevel = SentryLevel.Debug;
options.IsGlobalModeEnabled = true;
options.SendDefaultPii = true;
options.MaxAttachmentSize = 10 * 1024 * 1024;
});
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
}
6 changes: 4 additions & 2 deletions src/Gml.Launcher/ViewModels/Base/PageViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Gml.Launcher.Core.Exceptions;
using Gml.Launcher.Core.Services;
using ReactiveUI;
using Sentry;
using Splat;

namespace Gml.Launcher.ViewModels.Base;
Expand Down Expand Up @@ -71,9 +72,10 @@ async void RunThreadTask()
await func();
tcs.SetResult(null);
}
catch (Exception ex)
catch (Exception exception)
{
tcs.SetException(ex);
tcs.SetException(exception);
SentrySdk.CaptureException(exception);
}
}

Expand Down
Loading

0 comments on commit bc23fb4

Please sign in to comment.