Skip to content

Commit

Permalink
archive is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyinqiu committed May 10, 2024
1 parent 85432fc commit 5de34cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 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 async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(
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 async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(

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 @@ -359,7 +357,6 @@ public static async IAsyncEnumerable<GameResourcePackResolvedInfo> ResolveResour
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 Down

0 comments on commit 5de34cc

Please sign in to comment.