Skip to content

Commit

Permalink
为部分类添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Jul 8, 2024
1 parent 74b5ea5 commit 72be0cd
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 47 deletions.
17 changes: 2 additions & 15 deletions MinecraftLaunch/Components/Analyzer/GameLogAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MinecraftLaunch.Components.Analyzer;
// Reference: https://github.com/Corona-Studio/ProjBobcat

/// <summary>
/// 游戏崩溃分析器
/// Game crash analyzer.
/// </summary>
public sealed partial class GameCrashAnalyzer(GameEntry gameEntry, bool isIndependencyCore) {
private IEnumerable<string> _gameLogs;
Expand Down Expand Up @@ -160,7 +160,7 @@ public sealed partial class GameCrashAnalyzer(GameEntry gameEntry, bool isIndepe
#endregion

/// <summary>
/// 分析日志
/// Analyzes logs.
/// </summary>
public IEnumerable<CrashReport> AnalysisLogs() {
GetAllLogs();
Expand All @@ -176,9 +176,6 @@ public IEnumerable<CrashReport> AnalysisLogs() {
}
}

/// <summary>
/// 获取所有日志
/// </summary>
private void GetAllLogs() {
var gamePath = Path.Combine(_isIndependencyCore
? _gameEntry.OfVersionDirectoryPath(_isIndependencyCore)
Expand All @@ -201,9 +198,6 @@ string[] ReadAllLine(FileInfo file) {
}
}

/// <summary>
/// 模糊处理日志
/// </summary>
private IEnumerable<CrashReport> FuzzyProcessLogs() {
var allLogs = _gameLogs.Union(_crashLogs).ToImmutableArray();
return allLogs.SelectMany(log => _logCrashCauses, (log, item) => new { log, item })
Expand All @@ -214,9 +208,6 @@ private IEnumerable<CrashReport> FuzzyProcessLogs() {
});
}

/// <summary>
/// 精确处理游戏日志
/// </summary>
private IEnumerable<CrashReport> SpecificProcessGameLogs() {
foreach (var log in _gameLogs.ToImmutableArray()) {
if (MainClassMatch1().IsMatch(log) || (MainClassMatch2().IsMatch(log) && !log.Contains("at net."))) {
Expand Down Expand Up @@ -347,10 +338,6 @@ private IEnumerable<CrashReport> SpecificProcessGameLogs() {
}
}

/// <summary>
/// 精确处理崩溃日志
/// </summary>
/// <returns></returns>
private IEnumerable<CrashReport> SpecificProcessCrashLogs() {
foreach (var log in _crashLogs.ToImmutableArray()) {
if (log.Contains("-- MOD ")) {
Expand Down
17 changes: 17 additions & 0 deletions MinecraftLaunch/Components/Authenticator/MicrosoftAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ public sealed class MicrosoftAuthenticator(string clientId, bool isCheckOwnershi

public bool IsCheckOwnership { get; set; } = isCheckOwnership;

/// <summary>
/// Authenticator for Microsoft accounts.
/// </summary>
public MicrosoftAuthenticator(MicrosoftAccount account, string clientId, bool isCheckOwnership)
: this(clientId, isCheckOwnership) {
_account = account;
}

/// <summary>
/// Authenticates the Microsoft account.
/// </summary>
/// <returns>The authenticated Microsoft account.</returns>
public MicrosoftAccount Authenticate() {
var task = AuthenticateAsync();
if (task is { IsFaulted: false, IsCompleted: true }) {
Expand All @@ -28,6 +35,10 @@ public MicrosoftAccount Authenticate() {
return null;
}

/// <summary>
/// Asynchronously authenticates the Microsoft account.
/// </summary>
/// <returns>A ValueTask that represents the asynchronous operation. The task result contains the authenticated Microsoft account.</returns>
public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
/*
* Refresh token
Expand Down Expand Up @@ -140,6 +151,12 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
};
}

/// <summary>
/// Asynchronously authenticates the Microsoft account using device flow authentication.
/// </summary>
/// <param name="deviceCode">The action to be performed with the device code response.</param>
/// <param name="source">The cancellation token source to be used to cancel the operation.</param>
/// <returns>A Task that represents the asynchronous operation. The task result contains the OAuth2 token response.</returns>
public async Task<OAuth2TokenResponse> DeviceFlowAuthAsync(Action<DeviceCodeResponse> deviceCode,
CancellationTokenSource source = default) {
if (string.IsNullOrEmpty(_clientId)) {
Expand Down
10 changes: 7 additions & 3 deletions MinecraftLaunch/Components/Authenticator/OfflineAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
namespace MinecraftLaunch.Components.Authenticator;

/// <summary>
/// 离线账户身份验证器
/// Authenticator for offline accounts.
/// </summary>
/// <param name="name"></param>
/// <param name="uuid"></param>
/// <param name="name">The name of the account.</param>
/// <param name="uuid">The UUID of the account. If not provided, a new UUID will be generated based on the account name.</param>
public sealed class OfflineAuthenticator(string name, Guid? uuid = default) : IAuthenticator<OfflineAccount> {
/// <summary>
/// Authenticates the offline account.
/// </summary>
/// <returns>The authenticated offline account.</returns>
public OfflineAccount Authenticate() {
return new() {
AccessToken = Guid.NewGuid().ToString("N"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
using Flurl.Http;
using MinecraftLaunch.Extensions;
using MinecraftLaunch.Classes.Interfaces;
using MinecraftLaunch.Classes.Models.Auth;
using MinecraftLaunch.Extensions;

namespace MinecraftLaunch.Components.Authenticator;

/// <summary>
/// Authenticator for UnifiedPass accounts.
/// </summary>
/// <param name="serverId">The server ID for the account.</param>
/// <param name="userName">The username of the account.</param>
/// <param name="passWord">The password of the account.</param>
public sealed class UnifiedPassAuthenticator(string serverId, string userName, string passWord) : IAuthenticator<UnifiedPassAccount> {
private const string BASE_URL = "https://auth.mc-user.com:233/";

private string _serverId = serverId;
private string _userName = userName;
private string _passWord = passWord;
private readonly string _baseUrl = "https://auth.mc-user.com:233/";

/// <summary>
/// Refreshes the information of the account.
/// </summary>
/// <param name="serverId">The new server ID for the account.</param>
/// <param name="userName">The new username of the account.</param>
/// <param name="passWord">The new password of the account.</param>
public void RefreshInformation(string serverId, string userName, string passWord) {
_serverId = serverId;
_passWord = passWord;
_userName = userName;
}


/// <summary>
/// Authenticates the UnifiedPass account.
/// </summary>
/// <returns>The authenticated UnifiedPass account.</returns>
public UnifiedPassAccount Authenticate() {
return AuthenticateAsync()
.GetAwaiter()
.GetResult();
}

/// <summary>
/// Asynchronously authenticates the UnifiedPass account.
/// </summary>
/// <returns>A ValueTask that represents the asynchronous operation. The task result contains the authenticated UnifiedPass account.</returns>
public async ValueTask<UnifiedPassAccount> AuthenticateAsync() {
string authUrl = $"{_baseUrl}{_serverId}/authserver/authenticate";
string authUrl = $"{BASE_URL}{_serverId}/authserver/authenticate";
var content = new {
agent = new {
name = "MinecraftLaunch",
Expand Down
18 changes: 18 additions & 0 deletions MinecraftLaunch/Components/Authenticator/YggdrasilAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@

namespace MinecraftLaunch.Components.Authenticator;

/// <summary>
/// Authenticator for Yggdrasil accounts.
/// </summary>
/// <param name="account">The old Yggdrasil account to authenticate.</param>
public sealed class YggdrasilAuthenticator(YggdrasilAccount account) : IAuthenticator<IEnumerable<YggdrasilAccount>> {
private readonly string _email;
private readonly string _password;
private readonly YggdrasilAccount _account = account;
private readonly string _url = account?.YggdrasilServerUrl;

/// <summary>
/// Constructor for YggdrasilAuthenticator.
/// </summary>
/// <param name="url">The URL for authentication.</param>
/// <param name="email">The email of the account.</param>
/// <param name="password">The password of the account.</param>
public YggdrasilAuthenticator(string url, string email, string password) : this(default) {
_url = url;
_email = email;
_password = password;
}

/// <summary>
/// Authenticates the Yggdrasil account.
/// </summary>
/// <returns>The authenticated Yggdrasil account.</returns>
public IEnumerable<YggdrasilAccount> Authenticate() {
return AuthenticateAsync().GetAwaiter().GetResult();
}

/// <summary>
/// Asynchronously authenticates the Yggdrasil account.
/// </summary>
/// <returns>A ValueTask that represents the asynchronous operation. The task result contains the authenticated Yggdrasil account.</returns>
public async ValueTask<IEnumerable<YggdrasilAccount>> AuthenticateAsync() {
object payload = string.Empty;
string url = _url;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace MinecraftLaunch.Components.Resolver;

public sealed class CurseforgeModpacksResolver {

}
43 changes: 38 additions & 5 deletions MinecraftLaunch/Extensions/DownloadExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

namespace MinecraftLaunch.Extensions;

/// <summary>
/// 下载扩展类
/// </summary>
public static class DownloadExtension {
//public static BatchDownloader DefaultDownloader { get; set; } = new();

/// <summary>
/// Applies the mirror source to the download entry if the use of mirror download source is enabled.
/// </summary>
/// <param name="entry">The download entry to which the mirror source is to be applied.</param>
/// <param name="source">The mirror download source to be applied.</param>
/// <returns>The download entry with the applied mirror source.</returns>
public static IDownloadEntry OfMirrorSource(this IDownloadEntry entry,
MirrorDownloadSource source) {
if (MirrorDownloadManager.IsUseMirrorDownloadSource && source is not null) {
Expand All @@ -32,18 +33,38 @@ public static IDownloadEntry OfMirrorSource(this IDownloadEntry entry,
return entry;
}

/// <summary>
/// Initiates an asynchronous download operation for the specified download request.
/// </summary>
/// <param name="request">The download request to be processed.</param>
/// <param name="action">The action to be performed during the download operation.</param>
/// <returns>A ValueTask that represents the asynchronous download operation. The task result contains a boolean value that indicates whether the download operation was successful.</returns>
public static ValueTask<bool> DownloadAsync(
this DownloadRequest request,
Action<double> action = default!) {
return DownloadUitl.DownloadAsync(request, default, action);
}

/// <summary>
/// Initiates an asynchronous download operation for the specified download entry.
/// </summary>
/// <param name="downloadEntry">The download entry to be downloaded.</param>
/// <param name="source">The mirror download source to be used.</param>
/// <returns>A ValueTask that represents the asynchronous download operation. The task result contains a boolean value that indicates whether the download operation was successful.</returns>
public static ValueTask<bool> DownloadResourceEntryAsync(this
IDownloadEntry downloadEntry,
MirrorDownloadSource source = default!) {
return DownloadUitl.DownloadAsync(downloadEntry, DownloadUitl.DefaultDownloadRequest,default,x=>{});
}

/// <summary>
/// Initiates an asynchronous download operation for the specified collection of download entries.
/// </summary>
/// <param name="entries">The collection of download entries to be downloaded.</param>
/// <param name="source">The mirror download source to be used.</param>
/// <param name="action">The action to be performed during the download operation.</param>
/// <param name="downloadRequest">The download request to be processed.</param>
/// <returns>A ValueTask that represents the asynchronous download operation. The task result contains a boolean value that indicates whether the download operation was successful.</returns>
public static ValueTask<bool> DownloadResourceEntrysAsync(this
IEnumerable<IDownloadEntry> entries,
MirrorDownloadSource source = default!,
Expand Down Expand Up @@ -71,10 +92,22 @@ public static ValueTask<bool> DownloadResourceEntrysAsync(this
return downloader.DownloadAsync();
}

/// <summary>
/// Converts the download progress to a percentage.
/// </summary>
/// <param name="args">The download progress arguments.</param>
/// <returns>The download progress as a percentage.</returns>
public static double ToPercentage(this DownloadProgressChangedEventArgs args) {
return (double)args.CompletedCount / (double)args.TotalCount;
}

/// <summary>
/// Converts the specified progress value to a percentage within the specified range.
/// </summary>
/// <param name="progress">The progress value to be converted.</param>
/// <param name="mini">The minimum value of the range.</param>
/// <param name="max">The maximum value of the range.</param>
/// <returns>The progress value as a percentage within the specified range.</returns>
public static double ToPercentage(this double progress, double mini, double max) {
return mini + (max - mini) * progress;
}
Expand Down
64 changes: 47 additions & 17 deletions MinecraftLaunch/Extensions/GameEntryExtension.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
using MinecraftLaunch.Classes.Models.Game;

namespace MinecraftLaunch.Extensions {
public static class GameEntryExtension {
public static string OfLauncherProfilePath(this string root) =>
Path.Combine(root, "launcher_profiles.json");

public static string OfLauncherAccountPath(this string root) =>
Path.Combine(root, "launcher_accounts.json");

public static string OfVersionJsonPath(this GameEntry entry) =>
Path.Combine(entry.GameFolderPath, "versions", entry.Id, $"{entry.Id}.json");
namespace MinecraftLaunch.Extensions;

public static string OfVersionDirectoryPath(this GameEntry entry, bool Isolate = true) => Isolate
? Path.Combine(entry.GameFolderPath, "versions", entry.Id)
: entry.GameFolderPath;
/// <summary>
/// Provides extension methods for game entries.
/// </summary>
public static class GameEntryExtension {
/// <summary>
/// Gets the path of the launcher profile.
/// </summary>
/// <param name="root">The root directory.</param>
/// <returns>The path of the launcher profile.</returns>
public static string OfLauncherProfilePath(this string root) =>
Path.Combine(root, "launcher_profiles.json");

public static string OfModDirectorypath(this GameEntry entry, bool Isolate = true) => Path
.Combine(entry.OfVersionDirectoryPath(Isolate), "mods");
}
}
/// <summary>
/// Gets the path of the launcher account.
/// </summary>
/// <param name="root">The root directory.</param>
/// <returns>The path of the launcher account.</returns>
public static string OfLauncherAccountPath(this string root) =>
Path.Combine(root, "launcher_accounts.json");

/// <summary>
/// Gets the path of the version JSON file.
/// </summary>
/// <param name="entry">The game entry.</param>
/// <returns>The path of the version JSON file.</returns>
public static string OfVersionJsonPath(this GameEntry entry) =>
Path.Combine(entry.GameFolderPath, "versions", entry.Id, $"{entry.Id}.json");

/// <summary>
/// Gets the path of the version directory.
/// </summary>
/// <param name="entry">The game entry.</param>
/// <param name="Isolate">A value indicating whether to isolate the version directory.</param>
/// <returns>The path of the version directory.</returns>
public static string OfVersionDirectoryPath(this GameEntry entry, bool Isolate = true) => Isolate
? Path.Combine(entry.GameFolderPath, "versions", entry.Id)
: entry.GameFolderPath;

/// <summary>
/// Gets the path of the mod directory.
/// </summary>
/// <param name="entry">The game entry.</param>
/// <param name="Isolate">A value indicating whether to isolate the mod directory.</param>
/// <returns>The path of the mod directory.</returns>
public static string OfModDirectorypath(this GameEntry entry, bool Isolate = true) => Path
.Combine(entry.OfVersionDirectoryPath(Isolate), "mods");
}
Loading

0 comments on commit 72be0cd

Please sign in to comment.