Skip to content

Commit

Permalink
Merge pull request #147 from Corona-Studio/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
laolarou726 authored Jun 8, 2024
2 parents cfd8e3a + ecc8b6c commit 4a897de
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 65 deletions.
4 changes: 2 additions & 2 deletions ProjBobcat/ProjBobcat/Class/Helper/FileTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static async Task<AssetFileType> TryDetectFileTypeAsync(string filePath)
await using var fs = File.OpenRead(filePath);
using var archive = ArchiveFactory.Open(fs);

if (archive.Entries.Any(e => e.Key.Equals("manifest.json", StringComparison.OrdinalIgnoreCase)))
if (archive.Entries.Any(e => e.Key?.Equals("manifest.json", StringComparison.OrdinalIgnoreCase) ?? false))
return AssetFileType.CurseForgeModPack;
if (archive.Entries.Any(e => e.Key.Equals("modrinth.index.json", StringComparison.OrdinalIgnoreCase)))
if (archive.Entries.Any(e => e.Key?.Equals("modrinth.index.json", StringComparison.OrdinalIgnoreCase) ?? false))
return AssetFileType.ModrinthModPack;
break;
}
Expand Down
25 changes: 14 additions & 11 deletions ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ static async Task<GameModResolvedInfo> GetFabricModInfo(
public static ModLoaderType GetModLoaderType(IArchive archive)
{
var fabricEntry = archive.Entries.Any(e =>
e.Key.EndsWith("fabric.mod.json", StringComparison.OrdinalIgnoreCase));
e.Key?.EndsWith("fabric.mod.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (fabricEntry) return ModLoaderType.Fabric;

var neoforgeEntry = archive.Entries.Any(e =>
e.Key.EndsWith("_neoforge.mixins.json", StringComparison.OrdinalIgnoreCase));
e.Key?.EndsWith("_neoforge.mixins.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (neoforgeEntry) return ModLoaderType.NeoForge;

var forgeEntry = archive.Entries.Any(e =>
e.Key.EndsWith("META-INF/mods.toml", StringComparison.OrdinalIgnoreCase));
e.Key?.EndsWith("META-INF/mods.toml", StringComparison.OrdinalIgnoreCase) ?? false);
var forgeNewEntry = archive.Entries.Any(e =>
e.Key.EndsWith("mcmod.info", StringComparison.OrdinalIgnoreCase));
e.Key?.EndsWith("mcmod.info", StringComparison.OrdinalIgnoreCase) ?? false);

if (forgeEntry || forgeNewEntry) return ModLoaderType.Forge;

Expand All @@ -184,13 +184,13 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(

var modInfoEntry =
archive.Entries.FirstOrDefault(e =>
e.Key.Equals("mcmod.info", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("mcmod.info", StringComparison.OrdinalIgnoreCase) ?? false);
var fabricModInfoEntry =
archive.Entries.FirstOrDefault(e =>
e.Key.Equals("fabric.mod.json", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("fabric.mod.json", StringComparison.OrdinalIgnoreCase) ?? false);
var tomlInfoEntry =
archive.Entries.FirstOrDefault(e =>
e.Key.Equals("META-INF/mods.toml", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("META-INF/mods.toml", StringComparison.OrdinalIgnoreCase) ?? false);

var isEnabled = ext.Equals(".jar", StringComparison.OrdinalIgnoreCase);

Expand Down Expand Up @@ -249,9 +249,9 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(
if (!ArchiveHelper.TryOpen(file, out var archive)) return null;

var packIconEntry =
archive.Entries.FirstOrDefault(e => e.Key.Equals("pack.png", StringComparison.OrdinalIgnoreCase));
archive.Entries.FirstOrDefault(e => e.Key?.Equals("pack.png", StringComparison.OrdinalIgnoreCase) ?? false);
var packInfoEntry = archive.Entries.FirstOrDefault(e =>
e.Key.Equals("pack.mcmeta", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("pack.mcmeta", StringComparison.OrdinalIgnoreCase) ?? false);

var fileName = Path.GetFileName(file);
byte[]? imageBytes;
Expand Down Expand Up @@ -357,8 +357,11 @@ public static async IAsyncEnumerable<GameResourcePackResolvedInfo> ResolveResour
static GameShaderPackResolvedInfo? ResolveShaderPackFile(string file)
{
if (!ArchiveHelper.TryOpen(file, out var archive)) return null;
if (!archive.Entries.Any(e => e.Key.StartsWith("shaders/", StringComparison.OrdinalIgnoreCase)))
return null;
if (archive == null) return null;
if (!archive.Entries.Any(e =>
Path.GetFileName(e.Key?.TrimEnd(Path.DirectorySeparatorChar))
?.Equals("shaders", StringComparison.OrdinalIgnoreCase) ?? false))
return null;

var model = new GameShaderPackResolvedInfo(Path.GetFileName(file), false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings)
GraphAuthResultModel? result;
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(deviceTokenResModel.Interval));
await Task.Delay(TimeSpan.FromSeconds(deviceTokenResModel.Interval + 2));

using var userAuthResultReq = new HttpRequestMessage(HttpMethod.Post, MSDeviceTokenStatusUrl)
{
Expand Down Expand Up @@ -482,15 +482,6 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings)
return result;
}

public static string GetLoginUri(string clientId, string redirectUri)
{
return Uri.EscapeDataString("https://login.live.com/oauth20_authorize.srf"
+ $"?client_id={clientId}"
+ "&response_type=code"
+ $"&scope={MSAuthScope}"
+ $"&redirect_uri={redirectUri}");
}

static async Task<T?> SendRequest<T, TReq>(string url, TReq model, JsonTypeInfo<T> typeInfo,
JsonTypeInfo<TReq> reqTypeInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static bool IsLegacyForgeInstaller(string forgeExecutable, string forgeVe
using var archive = ArchiveFactory.Open(Path.GetFullPath(forgeExecutable));

var legacyUniversalJar =
archive.Entries.Any(entry => entry.Key.Equals($"forge-{forgeVersion}-universal.jar"));
archive.Entries.Any(entry => entry.Key?.Equals($"forge-{forgeVersion}-universal.jar") ?? false);
var installProfileJson = archive.Entries.Any(entry =>
entry.Key.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase));
entry.Key?.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase) ?? false);

return legacyUniversalJar && installProfileJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()
InvokeStatusChangedEvent("解析 Version.json", 0.1);

var versionJsonEntry =
archive.Entries.FirstOrDefault(e => e.Key.Equals("version.json", StringComparison.OrdinalIgnoreCase));
archive.Entries.FirstOrDefault(e => e.Key?.Equals("version.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (versionJsonEntry == default)
return GetCorruptedFileResult();
Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()

var installProfileEntry =
archive.Entries.FirstOrDefault(e =>
e.Key.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (installProfileEntry == default)
return GetCorruptedFileResult();
Expand All @@ -145,9 +145,9 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()
InvokeStatusChangedEvent("解析 Lzma", 0.4);

var serverLzma = archive.Entries.FirstOrDefault(e =>
e.Key.Equals("data/server.lzma", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("data/server.lzma", StringComparison.OrdinalIgnoreCase) ?? false);
var clientLzma = archive.Entries.FirstOrDefault(e =>
e.Key.Equals("data/client.lzma", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("data/client.lzma", StringComparison.OrdinalIgnoreCase) ?? false);

if (serverLzma != default)
{
Expand Down Expand Up @@ -195,17 +195,17 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()
InvokeStatusChangedEvent("解压 Forge Jar", 0.5);

var forgeJar = archive.Entries.FirstOrDefault(e =>
e.Key.Equals($"maven/net/minecraftforge/forge/{forgeVersion}/forge-{forgeVersion}.jar",
StringComparison.OrdinalIgnoreCase));
e.Key?.Equals($"maven/net/minecraftforge/forge/{forgeVersion}/forge-{forgeVersion}.jar",
StringComparison.OrdinalIgnoreCase) ?? false);
var forgeUniversalJar = archive.Entries.FirstOrDefault(e =>
e.Key.Equals($"maven/net/minecraftforge/forge/{forgeVersion}/forge-{forgeVersion}-universal.jar",
StringComparison.OrdinalIgnoreCase));
e.Key?.Equals($"maven/net/minecraftforge/forge/{forgeVersion}/forge-{forgeVersion}-universal.jar",
StringComparison.OrdinalIgnoreCase) ?? false);

if (forgeJar != default)
{
if (forgeUniversalJar != default)
{
var forgeUniversalSubPath = forgeUniversalJar.Key[(forgeUniversalJar.Key.IndexOf('/') + 1)..];
var forgeUniversalSubPath = forgeUniversalJar.Key![(forgeUniversalJar.Key!.IndexOf('/') + 1)..];
var forgeUniversalLibPath = Path.Combine(RootPath,
GamePathHelper.GetLibraryPath(forgeUniversalSubPath));

Expand All @@ -228,7 +228,7 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()
forgeUniversalJar.WriteTo(forgeUniversalFs);
}

var forgeSubPath = forgeJar.Key[(forgeJar.Key.IndexOf('/') + 1)..];
var forgeSubPath = forgeJar.Key![(forgeJar.Key!.IndexOf('/') + 1)..];
var forgeLibPath =
Path.Combine(RootPath, GamePathHelper.GetLibraryPath(forgeSubPath));

Expand Down Expand Up @@ -493,7 +493,7 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()
using var libArchive = ArchiveFactory.Open(Path.GetFullPath(libPath));
var libEntry =
libArchive.Entries.FirstOrDefault(e =>
e.Key.Equals("META-INF/MANIFEST.MF", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals("META-INF/MANIFEST.MF", StringComparison.OrdinalIgnoreCase) ?? false);

if (libEntry == null)
return GetCorruptedFileResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public async Task<ForgeInstallResult> InstallForgeTaskAsync()

using var reader = ArchiveFactory.Open(ForgeExecutablePath);
var profileEntry =
reader.Entries.FirstOrDefault(e => e.Key.Equals("install_profile.json", StringComparison.Ordinal));
reader.Entries.FirstOrDefault(e =>
e.Key?.Equals("install_profile.json", StringComparison.Ordinal) ?? false);
var legacyJarEntry =
reader.Entries.FirstOrDefault(e =>
e.Key.Equals($"forge-{ForgeVersion}-universal.jar", StringComparison.OrdinalIgnoreCase));
e.Key?.Equals($"forge-{ForgeVersion}-universal.jar", StringComparison.OrdinalIgnoreCase) ?? false);

if (profileEntry == default)
return new ForgeInstallResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public async Task InstallTaskAsync()

foreach (var entry in archive.Entries)
{
if (string.IsNullOrEmpty(entry.Key)) continue;
if (string.IsNullOrEmpty(manifest.Overrides) ||
!entry.Key.StartsWith(manifest.Overrides, StringComparison.OrdinalIgnoreCase)) continue;

Expand Down Expand Up @@ -258,7 +259,7 @@ public async Task InstallTaskAsync()
{
using var archive = ArchiveFactory.Open(Path.GetFullPath(ModPackPath));
var manifestEntry =
archive.Entries.FirstOrDefault(x => x.Key.Equals("manifest.json", StringComparison.OrdinalIgnoreCase));
archive.Entries.FirstOrDefault(x => x.Key?.Equals("manifest.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (manifestEntry == default)
return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class ModrinthInstaller : ModPackInstallerBase, IModrinthInstaller
using var archive = ArchiveFactory.Open(Path.GetFullPath(ModPackPath));
var manifestEntry =
archive.Entries.FirstOrDefault(x =>
x.Key.Equals("modrinth.index.json", StringComparison.OrdinalIgnoreCase));
x.Key?.Equals("modrinth.index.json", StringComparison.OrdinalIgnoreCase) ?? false);

if (manifestEntry == default)
return default;
Expand Down Expand Up @@ -111,6 +111,7 @@ public async Task InstallTaskAsync()

foreach (var entry in archive.Entries)
{
if (string.IsNullOrEmpty(entry.Key)) continue;
if (!entry.Key.StartsWith(decompressPrefix, StringComparison.OrdinalIgnoreCase)) continue;

var subPath = entry.Key[(decompressPrefix.Length + 1)..];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<string> InstallTaskAsync()

var launchWrapperVersion = "1.12";
var launchWrapperOfEntry =
entries.FirstOrDefault(e => e.Key.Equals("launchwrapper-of.txt", StringComparison.OrdinalIgnoreCase));
entries.FirstOrDefault(e => e.Key?.Equals("launchwrapper-of.txt", StringComparison.OrdinalIgnoreCase) ?? false);

if (launchWrapperOfEntry != null)
{
Expand All @@ -67,7 +67,7 @@ public async Task<string> InstallTaskAsync()
}

var launchWrapperEntry =
entries.FirstOrDefault(x => x.Key.Equals($"launchwrapper-of-{launchWrapperVersion}.jar"));
entries.FirstOrDefault(x => x.Key?.Equals($"launchwrapper-of-{launchWrapperVersion}.jar") ?? false);

InvokeStatusChangedEvent("生成版本总成", 40);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ public IEnumerable<string> ParseJvmArguments()
{
foreach (var jvmArg in VersionInfo.JvmArguments)
{
yield return StringHelper.ReplaceByDic(jvmArg, jvmArgumentsDic);
var arg = jvmArg;

// Patch for PCL2
if (jvmArg?.Equals("-DFabricMcEmu= net.minecraft.client.main.Main ", StringComparison.OrdinalIgnoreCase) ?? false)
arg = "-DFabricMcEmu=net.minecraft.client.main.Main";

yield return StringHelper.ReplaceByDic(arg, jvmArgumentsDic);
}

yield break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public sealed class DefaultVersionLocator : VersionLocatorBase
{
public NativeReplacementPolicy NativeReplacementPolicy { get; init; } = NativeReplacementPolicy.LegacyOnly;

readonly object _lock = new();

/// <summary>
/// 构造函数。
/// Constructor.
Expand Down Expand Up @@ -587,26 +589,29 @@ void ProcessProfile(VersionInfo result, string id)
var gameId = id.ToGuidHash().ToString("N");
var gamePath = Path.Combine(RootPath, GamePathHelper.GetGamePath(id));

if (LauncherProfileParser.LauncherProfile.Profiles!.TryGetValue(gameId, out var oldProfileModel))
lock (_lock)
{
result.Name = oldProfileModel.Name!;
oldProfileModel.GameDir = gamePath;
oldProfileModel.LastVersionId = id;
LauncherProfileParser.LauncherProfile.Profiles![gameId] = oldProfileModel;
LauncherProfileParser.SaveProfile();
if (LauncherProfileParser.LauncherProfile.Profiles!.TryGetValue(gameId, out var oldProfileModel))
{
result.Name = oldProfileModel.Name!;
oldProfileModel.GameDir = gamePath;
oldProfileModel.LastVersionId = id;
LauncherProfileParser.LauncherProfile.Profiles![gameId] = oldProfileModel;
LauncherProfileParser.SaveProfile();

return;
}
return;
}

var gameProfile = new GameProfileModel
{
GameDir = gamePath,
LastVersionId = id,
Name = id,
Created = DateTime.Now
};
var gameProfile = new GameProfileModel
{
GameDir = gamePath,
LastVersionId = id,
Name = id,
Created = DateTime.Now
};

LauncherProfileParser.LauncherProfile.Profiles!.Add(gameId, gameProfile);
LauncherProfileParser.SaveProfile();
LauncherProfileParser.LauncherProfile.Profiles!.Add(gameId, gameProfile);
LauncherProfileParser.SaveProfile();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public override async Task<LaunchResult> LaunchTaskAsync(LaunchSettings settings
using var archive = ArchiveFactory.Open(path);
foreach (var entry in archive.Entries)
{
if (string.IsNullOrEmpty(entry.Key)) continue;
if (n.Extract?.Exclude?.Any(entry.Key.StartsWith) ?? false) continue;

var extractPath = Path.Combine(nativeRootPath, entry.Key);
Expand Down
Loading

0 comments on commit 4a897de

Please sign in to comment.