mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-08-13 16:25:25 +00:00
Adjusting order to allow auxtype and create/mod date to override the
`setFileData` behavior; fixed bug in the override capability.
This commit is contained in:
@@ -109,9 +109,6 @@ public class FileUtils {
|
|||||||
source.isLocked().ifPresent(target::setLocked);
|
source.isLocked().ifPresent(target::setLocked);
|
||||||
source.getBinaryAddress().ifPresent(target::setBinaryAddress);
|
source.getBinaryAddress().ifPresent(target::setBinaryAddress);
|
||||||
source.getBinaryLength().ifPresent(target::setBinaryLength);
|
source.getBinaryLength().ifPresent(target::setBinaryLength);
|
||||||
source.getAuxiliaryType().ifPresent(target::setAuxiliaryType);
|
|
||||||
source.getCreationDate().ifPresent(target::setCreationDate);
|
|
||||||
source.getLastModificationDate().ifPresent(target::setLastModificationDate);
|
|
||||||
|
|
||||||
if (source.getFileData().isPresent() && source.getResourceData().isPresent()) {
|
if (source.getFileData().isPresent() && source.getResourceData().isPresent()) {
|
||||||
LOG.finest(() -> String.format("Setting data fork to %d bytes and resource fork to %d bytes.",
|
LOG.finest(() -> String.format("Setting data fork to %d bytes and resource fork to %d bytes.",
|
||||||
@@ -121,5 +118,10 @@ public class FileUtils {
|
|||||||
LOG.finest(() -> String.format("Setting data fork to %d bytes.", source.getFileData().get().length));
|
LOG.finest(() -> String.format("Setting data fork to %d bytes.", source.getFileData().get().length));
|
||||||
source.getFileData().ifPresent(target::setFileData);
|
source.getFileData().ifPresent(target::setFileData);
|
||||||
}
|
}
|
||||||
|
// These come after the set of data because the API will possibly set the auxtype
|
||||||
|
// and the updated date.
|
||||||
|
source.getAuxiliaryType().ifPresent(target::setAuxiliaryType);
|
||||||
|
source.getCreationDate().ifPresent(target::setCreationDate);
|
||||||
|
source.getLastModificationDate().ifPresent(target::setLastModificationDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ public class OverrideFileEntryReader implements FileEntryReader {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Optional<Integer> getAuxiliaryType() {
|
public Optional<Integer> getAuxiliaryType() {
|
||||||
return auxiliaryType.or(() -> parent.map(FileEntryReader::getBinaryLength).filter(Optional::isPresent).map(Optional::get));
|
return auxiliaryType.or(() -> parent.map(FileEntryReader::getAuxiliaryType).filter(Optional::isPresent).map(Optional::get));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Optional<Date> getCreationDate() {
|
public Optional<Date> getCreationDate() {
|
||||||
|
@@ -21,11 +21,14 @@ package com.webcodepro.applecommander.util.readerwriter;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.webcodepro.applecommander.storage.DiskFullException;
|
import com.webcodepro.applecommander.storage.DiskFullException;
|
||||||
import com.webcodepro.applecommander.storage.os.prodos.ProdosFileEntry;
|
import com.webcodepro.applecommander.storage.os.prodos.ProdosFileEntry;
|
||||||
|
|
||||||
public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWriter {
|
public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWriter {
|
||||||
|
private static Logger LOG = Logger.getLogger(ProdosFileEntryReaderWriter.class.getName());
|
||||||
|
|
||||||
private ProdosFileEntry fileEntry;
|
private ProdosFileEntry fileEntry;
|
||||||
|
|
||||||
public ProdosFileEntryReaderWriter(ProdosFileEntry fileEntry) {
|
public ProdosFileEntryReaderWriter(ProdosFileEntry fileEntry) {
|
||||||
@@ -38,6 +41,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setFilename(String filename) {
|
public void setFilename(String filename) {
|
||||||
|
LOG.finest(() -> String.format("Setting name to '%s'.", filename));
|
||||||
fileEntry.setFilename(filename);
|
fileEntry.setFilename(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +51,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setProdosFiletype(String filetype) {
|
public void setProdosFiletype(String filetype) {
|
||||||
|
LOG.finest(() -> String.format("Setting file type to '%s'.", filetype));
|
||||||
fileEntry.setFiletype(filetype);
|
fileEntry.setFiletype(filetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +61,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setLocked(boolean flag) {
|
public void setLocked(boolean flag) {
|
||||||
|
LOG.finest(() -> String.format("Setting locked to '%b'.", flag));
|
||||||
fileEntry.setLocked(flag);
|
fileEntry.setLocked(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +72,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
@Override
|
@Override
|
||||||
public void setFileData(byte[] data) {
|
public void setFileData(byte[] data) {
|
||||||
try {
|
try {
|
||||||
|
LOG.finest(() -> String.format("Setting file data to %d bytes.", data.length));
|
||||||
fileEntry.setFileData(data);
|
fileEntry.setFileData(data);
|
||||||
} catch (DiskFullException e) {
|
} catch (DiskFullException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -76,6 +83,8 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
try {
|
try {
|
||||||
// If we have a resource fork in addition to a data fork,
|
// If we have a resource fork in addition to a data fork,
|
||||||
// then we've got a GSOS extended storage type $5.
|
// then we've got a GSOS extended storage type $5.
|
||||||
|
LOG.finest(() -> String.format("Setting data fork to %d bytes, resource fork to %d bytes.",
|
||||||
|
data.length, resource.length));
|
||||||
fileEntry.setFileData(data, resource);
|
fileEntry.setFileData(data, resource);
|
||||||
fileEntry.setExtendedFile();
|
fileEntry.setExtendedFile();
|
||||||
} catch (DiskFullException e) {
|
} catch (DiskFullException e) {
|
||||||
@@ -93,7 +102,10 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
@Override
|
@Override
|
||||||
public void setBinaryAddress(int address) {
|
public void setBinaryAddress(int address) {
|
||||||
if (fileEntry.needsAddress()) {
|
if (fileEntry.needsAddress()) {
|
||||||
|
LOG.finest(() -> String.format("Setting address to $%04X.", address));
|
||||||
fileEntry.setAddress(address);
|
fileEntry.setAddress(address);
|
||||||
|
} else {
|
||||||
|
LOG.finest(() -> String.format("NOT SETTING ADDRESS, wrong type: $%04X", address));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +115,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setBinaryLength(int length) {
|
public void setBinaryLength(int length) {
|
||||||
|
LOG.finest("Skipping set of binary length.");
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +125,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setAuxiliaryType(int auxType) {
|
public void setAuxiliaryType(int auxType) {
|
||||||
|
LOG.finest(() -> String.format("Setting auxtype to $%04X.", auxType));
|
||||||
fileEntry.setAuxiliaryType(auxType);
|
fileEntry.setAuxiliaryType(auxType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +135,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setCreationDate(Date date) {
|
public void setCreationDate(Date date) {
|
||||||
|
LOG.finest(() -> String.format("Setting create date to '%s'.", date));
|
||||||
fileEntry.setCreationDate(date);
|
fileEntry.setCreationDate(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +145,7 @@ public class ProdosFileEntryReaderWriter implements FileEntryReader, FileEntryWr
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setLastModificationDate(Date date) {
|
public void setLastModificationDate(Date date) {
|
||||||
|
LOG.finest(() -> String.format("Setting modification date to '%s'.", date));
|
||||||
fileEntry.setLastModificationDate(date);
|
fileEntry.setLastModificationDate(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user