From 5de34cc5370a8431018d2b3111fb51101fffaf38 Mon Sep 17 00:00:00 2001 From: yueyinqiu Date: Sat, 11 May 2024 00:37:04 +0800 Subject: [PATCH 1/2] archive is not null --- ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs | 7 ++++--- .../ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs index d9d513a..aa522b5 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using SharpCompress.Archives; @@ -8,7 +9,7 @@ namespace ProjBobcat.Class.Helper; public static class ArchiveHelper { - public static bool TryOpen(string path, out IArchive? archive) + public static bool TryOpen(string path, [MaybeNullWhen(false)] out IArchive archive) { try { @@ -23,7 +24,7 @@ public static bool TryOpen(string path, out IArchive? archive) return true; } - public static bool TryOpen(FileInfo path, out IArchive? archive) + public static bool TryOpen(FileInfo path, [MaybeNullWhen(false)] out IArchive archive) { try { @@ -38,7 +39,7 @@ public static bool TryOpen(FileInfo path, out IArchive? archive) return true; } - public static bool TryOpen(Stream path, out IArchive? archive) + public static bool TryOpen(Stream path, [MaybeNullWhen(false)] out IArchive archive) { try { diff --git a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs index c47ca55..10beacf 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs @@ -181,7 +181,6 @@ public static ModLoaderType GetModLoaderType(IArchive archive) continue; if (!ArchiveHelper.TryOpen(file, out var archive)) continue; - if (archive == null) continue; var modInfoEntry = archive.Entries.FirstOrDefault(e => @@ -248,7 +247,6 @@ public static ModLoaderType GetModLoaderType(IArchive archive) if (!ext.Equals(".zip", StringComparison.OrdinalIgnoreCase)) return null; if (!ArchiveHelper.TryOpen(file, out var archive)) return null; - if (archive == null) return null; var packIconEntry = archive.Entries.FirstOrDefault(e => e.Key.Equals("pack.png", StringComparison.OrdinalIgnoreCase)); @@ -359,7 +357,6 @@ public static ModLoaderType GetModLoaderType(IArchive archive) static GameShaderPackResolvedInfo? ResolveShaderPackFile(string file) { 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))) return null; From 19610dd03959fb4f6977b66c7b93c34ee59e798e Mon Sep 17 00:00:00 2001 From: yueyinqiu Date: Sat, 11 May 2024 00:44:25 +0800 Subject: [PATCH 2/2] what is dir.Split('\\').Last() ??? --- .../ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs index 10beacf..cc29791 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs @@ -301,7 +301,7 @@ public static ModLoaderType GetModLoaderType(IArchive archive) if (!File.Exists(iconPath)) return null; - var fileName = dir.Split('\\').Last(); + var fileName = Path.GetFileName(dir); var imageBytes = await File.ReadAllBytesAsync(iconPath, ct); string? description = null; var version = -1; @@ -371,7 +371,7 @@ public static ModLoaderType GetModLoaderType(IArchive archive) if (!Directory.Exists(shaderPath)) return null; - return new GameShaderPackResolvedInfo(dir.Split('\\').Last(), true); + return new GameShaderPackResolvedInfo(Path.GetFileName(dir), true); } public static IEnumerable ResolveShaderPack(