Extending hints to include origin of source (2IMG, DiskCopy, or the magical SHK unpack routine). Used in 'ac' to determine writability (?).

This commit is contained in:
Rob Greene
2025-08-22 16:02:47 -05:00
parent 670738c7ca
commit a4747bebbb
7 changed files with 29 additions and 25 deletions
@@ -316,8 +316,7 @@ public class ac {
if (formattedDisks == null)
System.out.println("Dude, formattedDisks is null!");
FormattedDisk formattedDisk = formattedDisks[0];
boolean isDC42 = disk.getDiskImageManager() instanceof DiskCopyImage;
if (!disk.isSDK() && !isDC42) {
if (!disk.getDiskImageManager().isAny(Hint.DISK_COPY_IMAGE, Hint.ORIGIN_SHRINKIT, Hint.UNIVERSAL_DISK_IMAGE)) {
FileEntry entry = name.createEntry(formattedDisk);
if (entry != null) {
entry.setFiletype(fileType);
@@ -412,8 +411,7 @@ public class ac {
throws IOException, DiskException {
Disk disk = new Disk(imageName);
Name name = new Name(fileName);
boolean isDC42 = disk.getDiskImageManager() instanceof DiskCopyImage;
if (!disk.isSDK() && !isDC42) {
if (!disk.getDiskImageManager().isAny(Hint.DISK_COPY_IMAGE, Hint.ORIGIN_SHRINKIT, Hint.UNIVERSAL_DISK_IMAGE)) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
@@ -582,8 +580,7 @@ public class ac {
static void setFileLocked(String imageName, Name name,
boolean lockState) throws IOException, DiskException {
Disk disk = new Disk(imageName);
boolean isDC42 = disk.getDiskImageManager() instanceof DiskCopyImage;
if (!disk.isSDK() && !isDC42) {
if (!disk.getDiskImageManager().isAny(Hint.DISK_COPY_IMAGE, Hint.ORIGIN_SHRINKIT, Hint.UNIVERSAL_DISK_IMAGE)) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
@@ -608,8 +605,7 @@ public class ac {
public static void setDiskName(String imageName, String volName)
throws IOException, DiskException {
Disk disk = new Disk(imageName);
boolean isDC42 = disk.getDiskImageManager() instanceof DiskCopyImage;
if (!disk.isSDK() && !isDC42) {
if (!disk.getDiskImageManager().isAny(Hint.DISK_COPY_IMAGE, Hint.ORIGIN_SHRINKIT, Hint.UNIVERSAL_DISK_IMAGE)) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
formattedDisk.setDiskName(volName);
@@ -201,14 +201,6 @@ public class Disk {
return (imageOrder == null) ? textBundle.get("FormattedDisk.Unknown") : imageOrder.getName();
}
/**
* Indicate if this disk is a ShrinkIt-compressed disk image.
*/
public boolean isSDK()
{
return filename.toLowerCase().endsWith(".sdk"); //$NON-NLS-1$
}
/**
* Identify the size of this disk.
*/
@@ -56,7 +56,7 @@ public class ShrinkitSourceFactory implements Source.Factory {
try {
byte[] imageData = unpackSHKFile(source.getName(), source, 0);
Source shkSource = DataBufferSource.create(imageData, source.getName() + ".po")
.hints(Hint.PRODOS_BLOCK_ORDER)
.hints(Hint.PRODOS_BLOCK_ORDER, Hint.ORIGIN_SHRINKIT)
.information(Information.builder("Original name").value(source.getName()),
Information.builder("Original type").value(bxy ? "Binary II" : "Shrinkit"))
.get();
@@ -22,5 +22,8 @@ package org.applecommander.hint;
public enum Hint {
NIBBLE_SECTOR_ORDER,
DOS_SECTOR_ORDER,
PRODOS_BLOCK_ORDER
PRODOS_BLOCK_ORDER,
ORIGIN_SHRINKIT,
UNIVERSAL_DISK_IMAGE,
DISK_COPY_IMAGE
}
@@ -21,4 +21,11 @@ package org.applecommander.hint;
public interface HintProvider {
boolean is(Hint hint);
default boolean isAny(Hint... hints) {
boolean good = true;
for (Hint hint : hints) {
good &= is(hint);
}
return good;
}
}
@@ -29,6 +29,7 @@ import org.applecommander.util.Information;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
public class DiskCopyImage implements Source {
@@ -36,6 +37,7 @@ public class DiskCopyImage implements Source {
private final Source source;
private final Info info;
private final Set<Hint> hints = Set.of(Hint.PRODOS_BLOCK_ORDER, Hint.DISK_COPY_IMAGE);
public DiskCopyImage(Source source) {
this.source = source;
@@ -91,7 +93,7 @@ public class DiskCopyImage implements Source {
@Override
public boolean is(Hint hint) {
return hint == Hint.PRODOS_BLOCK_ORDER;
return hints.contains(hint);
}
public Info getInfo() {
@@ -28,6 +28,7 @@ import org.applecommander.util.Information;
import java.util.List;
import java.util.Optional;
import java.util.Set;
public class UniversalDiskImage implements Source {
public static final int MAGIC = 0x32494d47; // "2IMG" marker
@@ -36,6 +37,7 @@ public class UniversalDiskImage implements Source {
private final Source source;
private final Info info;
private final Set<Hint> hints;
public UniversalDiskImage(Source source) {
this.source = source;
@@ -70,6 +72,13 @@ public class UniversalDiskImage implements Source {
}
this.info = new Info(creator, headerSize, version, imageFormat, flags, prodosBlocks,
dataOffset, dataLength, comment, creatorData);
Hint order = switch(info.imageFormat()) {
case 0 -> Hint.DOS_SECTOR_ORDER;
case 1 -> Hint.PRODOS_BLOCK_ORDER;
case 2 -> Hint.NIBBLE_SECTOR_ORDER;
default -> throw new RuntimeException("unexpected 2IMG image format: " + info.imageFormat());
};
this.hints = Set.of(order, Hint.UNIVERSAL_DISK_IMAGE);
}
public Info getInfo() {
@@ -99,12 +108,7 @@ public class UniversalDiskImage implements Source {
@Override
public boolean is(Hint hint) {
return switch (hint) {
case DOS_SECTOR_ORDER -> info.imageFormat() == 0;
case PRODOS_BLOCK_ORDER -> info.imageFormat() == 1;
case NIBBLE_SECTOR_ORDER -> info.imageFormat() == 2;
default -> false;
};
return hints.contains(hint);
}
@Override