Skip to content

Commit

Permalink
Add some logic for preserving original readOnly flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach committed May 2, 2020
1 parent 3e7fa95 commit 52c1bb7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/systems/crigges/jmpq3/JMpqEditor.java
Expand Up @@ -120,6 +120,8 @@ public class JMpqEditor implements AutoCloseable {

/** If write operations are supported on the archive. */
private boolean canWrite;
/** If the archive was originally read-only */
private boolean openedAsReadOnly;

/**
* Creates a new MPQ editor for the MPQ file at the specified path.
Expand All @@ -138,6 +140,7 @@ public class JMpqEditor implements AutoCloseable {
public JMpqEditor(Path mpqArchive, MPQOpenOption... openOptions) throws JMpqException {
// process open options
canWrite = !Arrays.asList(openOptions).contains(MPQOpenOption.READ_ONLY);
openedAsReadOnly = !canWrite;
legacyCompatibility = Arrays.asList(openOptions).contains(MPQOpenOption.FORCE_V0);
log.debug(mpqArchive.toString());
try {
Expand Down Expand Up @@ -229,10 +232,11 @@ public void addExternalListfile(File externalListfilePath) {
checkListfileEntries();
removeMissingFiles();
// Operation succeeded and added a listfile so we can now write properly.
canWrite = true;
// (as long as it wasn't read-only to begin with)
canWrite = !openedAsReadOnly;
} catch (Exception ex) {
log.warn("Could not apply external listfile: " + externalListfilePath.getAbsolutePath());
canWrite = false;
// The value of canWrite is not changed intentionally
}
}

Expand Down

0 comments on commit 52c1bb7

Please sign in to comment.