Skip to content

Commit

Permalink
Fix extraction from shortname
Browse files Browse the repository at this point in the history
  • Loading branch information
danwilkins committed Oct 1, 2023
1 parent 9456353 commit 5f96c49
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions LanternExtractor/EqFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public static class EqFileHelper
public static List<string> GetValidEqFilePaths(string directory, string archiveName)
{
archiveName = archiveName.ToLower();

if (!Directory.Exists(directory))
{
return new List<string>();
}

var eqFiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories);
List<string> validFiles;

Expand Down Expand Up @@ -77,7 +83,8 @@ private static List<string> GetValidFiles(string archiveName, string directory)
}
else
{
string archivePath = Path.Combine(directory, archiveName, LanternStrings.PfsFormatExtension);
string archivePath =
Path.Combine(directory, string.Concat(archiveName, LanternStrings.PfsFormatExtension));

if (File.Exists(archivePath))
{
Expand All @@ -86,33 +93,37 @@ private static List<string> GetValidFiles(string archiveName, string directory)
}

var archiveExtension = LanternStrings.S3dFormatExtension;
if (Directory.EnumerateFiles(directory, $"*{LanternStrings.T3dFormatExtension}", SearchOption.AllDirectories).Any())
if (Directory.EnumerateFiles(directory, $"*{LanternStrings.T3dFormatExtension}",
SearchOption.AllDirectories).Any())
{
archiveExtension = LanternStrings.T3dFormatExtension;
}

// Try and find all associated files with the shortname - can theoretically be a non-zone file
string mainArchivePath = Path.Combine(directory, archiveName, archiveExtension);
string mainArchivePath = Path.Combine(directory, string.Concat(archiveName, archiveExtension));
if (File.Exists(mainArchivePath))
{
validFiles.Add(mainArchivePath);
}

// Some zones have additional object archives for things added past their initial release
// No archives contain cross archive fragment references
string extensionObjectsArchivePath = Path.Combine(directory, $"{archiveName}_2_obj", archiveExtension);
string extensionObjectsArchivePath =
Path.Combine(directory, string.Concat($"{archiveName}_2_obj", archiveExtension));
if (File.Exists(extensionObjectsArchivePath))
{
validFiles.Add(extensionObjectsArchivePath);
}

string objectsArchivePath = Path.Combine(directory, $"{archiveName}_obj", archiveExtension);
string objectsArchivePath =
Path.Combine(directory, string.Concat($"{archiveName}_obj", archiveExtension));
if (File.Exists(objectsArchivePath))
{
validFiles.Add(objectsArchivePath);
}

string charactersArchivePath = Path.Combine(directory, $"{archiveName}_chr", archiveExtension);
string charactersArchivePath =
Path.Combine(directory, string.Concat($"{archiveName}_chr", archiveExtension));
if (File.Exists(charactersArchivePath))
{
validFiles.Add(charactersArchivePath);
Expand All @@ -121,7 +132,8 @@ private static List<string> GetValidFiles(string archiveName, string directory)
// Some zones have additional character archives for things added past their initial release
// None of them contain fragments that are linked to other related archives.
// "qeynos" must be excluded because both qeynos and qeynos2 are used as shortnames
string extensionCharactersArchivePath = Path.Combine(directory, $"{archiveName}2_chr", archiveExtension);
string extensionCharactersArchivePath =
Path.Combine(directory, string.Concat($"{archiveName}2_chr", archiveExtension));
if (File.Exists(extensionCharactersArchivePath) && archiveName != "qeynos")
{
validFiles.Add(extensionCharactersArchivePath);
Expand Down Expand Up @@ -164,7 +176,7 @@ public static bool IsEquipmentArchive(string archiveName)
public static bool IsCharacterArchive(string archiveName)
{
return archiveName.Contains("_chr") || archiveName.StartsWith("chequip") ||
archiveName.Contains("_amr");
archiveName.Contains("_amr");
}

public static bool IsObjectsArchive(string archiveName)
Expand Down

0 comments on commit 5f96c49

Please sign in to comment.