Skip to content

Commit

Permalink
Merge pull request #148 from yueyinqiu/evil
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed May 29, 2024
2 parents 85432fc + 19610dd commit 2c0b53e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 4 additions & 3 deletions ProjBobcat/ProjBobcat/Class/Helper/ArchiveHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using SharpCompress.Archives;

Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -303,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;
Expand Down Expand Up @@ -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;

Expand All @@ -374,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<GameShaderPackResolvedInfo> ResolveShaderPack(
Expand Down

0 comments on commit 2c0b53e

Please sign in to comment.