mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-06-02 12:41:32 +00:00
Added needsAddress and setAddress along with ProDOS-specific
setAuxiliaryType. Moved ProdosFileType inner class to ProdosFormattedDisk.
This commit is contained in:
parent
ee700cf995
commit
b52fca61a8
|
@ -19,14 +19,11 @@
|
||||||
*/
|
*/
|
||||||
package com.webcodepro.applecommander.storage;
|
package com.webcodepro.applecommander.storage;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a ProDOS file entry on disk.
|
* Represents a ProDOS file entry on disk.
|
||||||
|
@ -35,58 +32,14 @@ import java.util.Properties;
|
||||||
* @author: Rob Greene
|
* @author: Rob Greene
|
||||||
*/
|
*/
|
||||||
public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
|
public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
|
||||||
private static ProdosFileType[] fileTypes;
|
|
||||||
private List files;
|
private List files;
|
||||||
private ProdosSubdirectoryHeader subdirectoryHeader;
|
private ProdosSubdirectoryHeader subdirectoryHeader;
|
||||||
|
|
||||||
/**
|
|
||||||
* This class holds filetype mappings.
|
|
||||||
*/
|
|
||||||
private class ProdosFileType {
|
|
||||||
private byte type;
|
|
||||||
private String string;
|
|
||||||
public ProdosFileType(byte type, String string) {
|
|
||||||
this.type = type;
|
|
||||||
this.string = string;
|
|
||||||
}
|
|
||||||
public byte getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
public String getString() {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for ProdosFileEntry.
|
* Constructor for ProdosFileEntry.
|
||||||
*/
|
*/
|
||||||
public ProdosFileEntry(ProdosFormatDisk disk, int block, int offset) {
|
public ProdosFileEntry(ProdosFormatDisk disk, int block, int offset) {
|
||||||
super(disk, block, offset);
|
super(disk, block, offset);
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize all file types.
|
|
||||||
*/
|
|
||||||
protected void initialize() {
|
|
||||||
if (fileTypes != null) return;
|
|
||||||
|
|
||||||
fileTypes = new ProdosFileType[256];
|
|
||||||
InputStream inputStream =
|
|
||||||
getClass().getResourceAsStream("ProdosFileTypes.properties");
|
|
||||||
Properties properties = new Properties();
|
|
||||||
try {
|
|
||||||
properties.load(inputStream);
|
|
||||||
for (int i=0; i<256; i++) {
|
|
||||||
String byt = AppleUtil.getFormattedByte(i).toLowerCase();
|
|
||||||
String string = (String) properties.get("filetype." + byt);
|
|
||||||
if (string == null || string.length() == 0) {
|
|
||||||
string = "$" + byt.toUpperCase();
|
|
||||||
}
|
|
||||||
fileTypes[i] = new ProdosFileType((byte)i, string);
|
|
||||||
}
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,22 +132,16 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
|
||||||
*/
|
*/
|
||||||
public String getFiletype() {
|
public String getFiletype() {
|
||||||
int filetype = AppleUtil.getUnsignedByte(readFileEntry()[0x10]);
|
int filetype = AppleUtil.getUnsignedByte(readFileEntry()[0x10]);
|
||||||
ProdosFileType prodostype = fileTypes[filetype];
|
return getDisk().getFiletype(filetype);
|
||||||
return prodostype.getString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the filetype.
|
* Set the filetype.
|
||||||
*/
|
*/
|
||||||
public void setFiletype(String filetype) {
|
public void setFiletype(String filetype) {
|
||||||
for (int i=0; i<fileTypes.length; i++) {
|
byte[] entry = readFileEntry();
|
||||||
if (filetype.equalsIgnoreCase(fileTypes[i].getString())) {
|
entry[0x10] = getDisk().getFiletype(filetype);
|
||||||
byte[] entry = readFileEntry();
|
writeFileEntry(entry);
|
||||||
entry[0x10] = fileTypes[i].getType();
|
|
||||||
writeFileEntry(entry);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,6 +223,14 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
|
||||||
entry[0x1f] = low;
|
entry[0x1f] = low;
|
||||||
entry[0x20] = high;
|
entry[0x20] = high;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the auxiliary type for this file.
|
||||||
|
*/
|
||||||
|
public void setAuxiliaryType(byte[] entry, int auxiliaryType) {
|
||||||
|
setAuxiliaryType(entry, (byte)(auxiliaryType%256),
|
||||||
|
(byte)(auxiliaryType/256));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the last modification date.
|
* Get the last modification date.
|
||||||
|
@ -520,4 +475,23 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
|
||||||
}
|
}
|
||||||
return new BinaryFileFilter();
|
return new BinaryFileFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if this filetype requires an address component.
|
||||||
|
* Note that the FormattedDisk also has this method - normally,
|
||||||
|
* this will defer to the method on FormattedDisk, as it will be
|
||||||
|
* more generic.
|
||||||
|
*/
|
||||||
|
public boolean needsAddress() {
|
||||||
|
return getDisk().needsAddress(getFiletype());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the address that this file loads at.
|
||||||
|
*/
|
||||||
|
public void setAddress(int address) {
|
||||||
|
byte[] fileEntry = readFileEntry();
|
||||||
|
setAuxiliaryType(fileEntry, address);
|
||||||
|
writeFileEntry(fileEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user