Skip to content

Commit

Permalink
Merge pull request #5000 from SJuliez/msc-file-extensions
Browse files Browse the repository at this point in the history
MechSummaryCache: load only known file extensions, also in ZIP files
  • Loading branch information
SJuliez authored Jan 3, 2024
2 parents 12d7b95 + 51850c4 commit 5f45b0a
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions megamek/src/megamek/common/MechSummaryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public interface Listener {
private static final String FILENAME_UNITS_CACHE = "units.cache";
public static final String FILENAME_LOOKUP = "name_changes.txt";

private static final List<String> SUPPORTED_FILE_EXTENSIONS =
List.of(".mtf", ".blk", ".mep", ".hmv", ".tdb", ".hmp", ".zip");

private static MechSummaryCache instance;
private static boolean disposeInstance = false;
private static boolean interrupted = false;
Expand Down Expand Up @@ -764,50 +767,18 @@ private boolean loadMechsFromDirectory(Vector<MechSummary> vMechs,
continue;
}
// recursion is fun
bNeedsUpdate |= loadMechsFromDirectory(vMechs, sKnownFiles,
lLastCheck, f, ignoreUnofficial);
continue;
}
if (!f.getName().toLowerCase().endsWith(".mtf") && !f.getName().toLowerCase().endsWith(".blk")
&& !f.getName().toLowerCase().endsWith(".hmp") && !f.getName().toLowerCase().endsWith(".hmv")
&& !f.getName().toLowerCase().endsWith(".mep") && !f.getName().toLowerCase().endsWith(".tdb")
&& !f.getName().toLowerCase().endsWith(".zip")) {
continue;
}
if (f.getName().indexOf('.') == -1) {
continue;
}
if (f.getName().toLowerCase().endsWith(".gitignore")) {
continue;
}
if (f.getName().toLowerCase().endsWith(".txt")) {
continue;
}
if (f.getName().toLowerCase().endsWith(".log")) {
bNeedsUpdate |= loadMechsFromDirectory(vMechs, sKnownFiles, lLastCheck, f, ignoreUnofficial);
continue;
}
if (f.getName().toLowerCase().endsWith(".svn-base")) {
String lowerCaseName = f.getName().toLowerCase();
if (SUPPORTED_FILE_EXTENSIONS.stream().noneMatch(lowerCaseName::endsWith)) {
continue;
}
if (f.getName().toLowerCase().endsWith(".svn-work")) {
if (lowerCaseName.endsWith(".zip")) {
bNeedsUpdate |= loadMechsFromZipFile(vMechs, sKnownFiles, lLastCheck, f);
continue;
}
if (f.getName().toLowerCase().endsWith(".ds_store")) {
continue;
}
if (f.getName().toLowerCase().endsWith(".yml")) {
continue;
}
if (f.getName().equals("UnitVerifierOptions.xml")) {
continue;
}
if (f.getName().toLowerCase().endsWith(".zip")) {
bNeedsUpdate |= loadMechsFromZipFile(vMechs, sKnownFiles,
lLastCheck, f);
continue;
}
if ((f.lastModified() < lLastCheck)
&& sKnownFiles.contains(f.toString())) {
if ((f.lastModified() < lLastCheck) && sKnownFiles.contains(f.toString())) {
continue;
}
try {
Expand Down Expand Up @@ -885,10 +856,8 @@ private boolean loadMechsFromZipFile(Vector<MechSummary> vMechs,
}
continue;
}
if (zEntry.getName().toLowerCase().endsWith(".txt")) {
continue;
}
if (zEntry.getName().toLowerCase().endsWith(".yml")) {
String lowerCaseName = zEntry.getName().toLowerCase();
if (SUPPORTED_FILE_EXTENSIONS.stream().noneMatch(lowerCaseName::endsWith)) {
continue;
}
if ((Math.max(fZipFile.lastModified(), zEntry.getTime()) < lLastCheck)
Expand Down

0 comments on commit 5f45b0a

Please sign in to comment.