Skip to content

Commit

Permalink
just show warning when there are more blocks than listfile entries
Browse files Browse the repository at this point in the history
allowing onw still to build. Dirty fix since we have to free space detection 💊
  • Loading branch information
Frotty committed Nov 8, 2018
1 parent a0b14d4 commit 447581e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main/java/systems/crigges/jmpq3/JMpqEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public JMpqEditor(Path mpqArchive, MPQOpenOption... openOptions) throws JMpqExce
// process open options
canWrite = !Arrays.asList(openOptions).contains(MPQOpenOption.READ_ONLY);
legacyCompatibility = Arrays.asList(openOptions).contains(MPQOpenOption.FORCE_V0);

log.debug(mpqArchive.toString());
try {
setupTempDir();

Expand Down Expand Up @@ -218,18 +218,17 @@ private void readListFile() {
tempFile.deleteOnExit();
extractFile("(listfile)", tempFile);
listFile = new Listfile(Files.readAllBytes(tempFile.toPath()));
int hiddenFiles = (hasFile("(attributes)") ? 2 : 1) + (hasFile("(signature)") ? 1 : 0);
if (canWrite) {
if (listFile.getFiles().size() >= blockTable.getAllVaildBlocks().size() - 2) {
for (String fileName : listFile.getFiles()) {
if (!hasFile(fileName)) {
canWrite = false;
log.warn("mpq's listfile is incomplete, switching to readonly.");
return;
}
if (listFile.getFiles().size() >= blockTable.getAllVaildBlocks().size() - hiddenFiles) {
log.warn("mpq's listfile is incomplete. Blocks without listfile entry will be discarded");
}
for (String fileName : listFile.getFiles()) {
if (!hasFile(fileName)) {
canWrite = false;
log.warn("mpq's listfile is incomplete: " + fileName + " exists in listfile but not in archive.");
return;
}
} else {
log.warn("mpq's listfile is incomplete, switching to readonly.");
canWrite = false;
}
}
} catch (Exception e) {
Expand Down

0 comments on commit 447581e

Please sign in to comment.