Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix #147

Merged
merged 8 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 10 additions & 10 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 @@ -185,13 +185,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 @@ -251,9 +251,9 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(
if (archive == null) 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 @@ -360,7 +360,7 @@ public static async IAsyncEnumerable<GameResourcePackResolvedInfo> ResolveResour
{
if (!ArchiveHelper.TryOpen(file, out var archive)) return null;
if (archive == null) return null;
if (!archive.Entries.Any(e => e.Key.StartsWith("shaders/", StringComparison.OrdinalIgnoreCase)))
if (!archive.Entries.Any(e => e.Key?.StartsWith("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 @@ -24,9 +24,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 @@ -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 @@ -585,26 +587,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