Skip to content

Commit

Permalink
CLI: Only loop through list once and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxEG committed Mar 29, 2022
1 parent 18254d3 commit 1c42eb2
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions BSA Browser CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ static void ExtractFiles(List<string> archives, string destination, bool overwri
int skipped = 0;
var files = archive.Files.Where(x => Filter(x.FullPath)).ToList();

HandleUnsupportedTextures(files);

// Some Console properties might not be available in certain situations,
// e.g. when redirecting stdout. To prevent crashing, setting the cursor position should only
// be done if there actually is a cursor to be set.
Expand All @@ -231,8 +233,6 @@ static void ExtractFiles(List<string> archives, string destination, bool overwri
}
catch (IOException) { }

HandleUnsupportedTextures(files);

foreach (var entry in files)
{
string output = $"Extracting: {++count}/{files.Count} - {entry.FullPath}".PadRight(prevLength);
Expand Down Expand Up @@ -311,23 +311,14 @@ static Archive OpenArchive(string file)

static void HandleUnsupportedTextures(List<ArchiveEntry> files)
{
if (files.All(x => (x as BA2TextureEntry)?.IsFormatSupported() != false))
return;

if (_arguments.NoHeaders)
for (int i = files.Count; i-- > 0;)
{
foreach (var fe in files.Where(x => (x as BA2TextureEntry)?.IsFormatSupported() == false))
if (files[i] is BA2TextureEntry tex && tex.IsFormatSupported() == false)
{
(fe as BA2TextureEntry).GenerateTextureHeader = false;
}
}
else
{
// Remove unsupported textures to skip them
for (int i = files.Count; i-- > 0;)
{
if ((files[i] as BA2TextureEntry)?.IsFormatSupported() == false)
files.RemoveAt(i);
if (_arguments.NoHeaders)
tex.GenerateTextureHeader = false;
else
files.RemoveAt(i); // Remove unsupported textures to skip them
}
}
}
Expand Down

0 comments on commit 1c42eb2

Please sign in to comment.