mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-11-22 18:25:20 +00:00
Adding label support to the FileStore as well.
This commit is contained in:
1 parent
e450580043
commit
07653b486b
3 files changed
+29
-2
No files matched your search
@@ -129,7 +129,11 @@ public class USDOSFileStore extends ChangeRegistry<FileStore.FileStoreChangeEven
|
||||
/// different labels such as "Disk 1" and "Disk 2".
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "US-DOS";
|
||||
String label = bitmap.getZeroTerminatedString(LABEL_OFFSET, LABEL_MAX_LENGTH);
|
||||
if (label.isEmpty()) {
|
||||
return "<NO LABEL>";
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
/// All FileStores support a "root" directory that references all files.
|
||||
@@ -179,6 +183,7 @@ public class USDOSFileStore extends ChangeRegistry<FileStore.FileStoreChangeEven
|
||||
@Override
|
||||
public List<InformationGroup> information() {
|
||||
return InformationGroup.builder("US-DOS")
|
||||
.item("Label").value(getLabel())
|
||||
.item("Total Files").value(rootDirectory.getTotalFileCount())
|
||||
.merge(usage)
|
||||
.get(device);
|
||||
|
||||
@@ -136,7 +136,7 @@ public class USDOSFileStoreFactory implements FileStoreFactory, USDOSConstants {
|
||||
bitmap.putBytes(BITMAP_OFFSET + track*2, 0xff, 0xff);
|
||||
}
|
||||
String label = getValidatedValue(options, DISK_LABEL, "");
|
||||
bitmap.putFixedLengthString(LABEL_OFFSET, Math.min(label.length(), LABEL_MAX_LENGTH), label, false);
|
||||
bitmap.putZeroTerminatedString(LABEL_OFFSET, LABEL_MAX_LENGTH, label);
|
||||
device.writeSector(BITMAP_TRACK, BITMAP_SECTOR, bitmap);
|
||||
USDOSFileStore fileStore = new USDOSFileStore(device);
|
||||
USDOSDirectory rootDirectory = fileStore.getRootDirectory();
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.applecommander.util;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.*;
|
||||
@@ -277,6 +278,27 @@ public class DataBuffer {
|
||||
}
|
||||
putFixedLengthString(index+1, value.length(), value, setHighBit);
|
||||
}
|
||||
/// Read a zero terminated string with a maximum length.
|
||||
public String getZeroTerminatedString(int offset, int maxLength) {
|
||||
StringWriter sw = new StringWriter();
|
||||
for (int i=0; i<maxLength; i++) {
|
||||
int ch = getUnsignedByte(offset+i);
|
||||
if (ch == 0) break;
|
||||
sw.write(ch);
|
||||
}
|
||||
return sw.toString();
|
||||
}
|
||||
/// Set a zero terminated string and blank out all data up to the `maxLength`.
|
||||
public void putZeroTerminatedString(int offset, int maxLength, String value) {
|
||||
for (int i=0; i<maxLength; i++) {
|
||||
if (i < value.length()) {
|
||||
putByte(offset+i, value.charAt(i));
|
||||
}
|
||||
else {
|
||||
putByte(offset+i, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Extract a Pascal date. If the date is not set (all zeroes)
|
||||
/// this returns a `null`.
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user