Removing ByteArrayImageLayout and the related UniversalDiskImageLayout in favor of Source (FileSource, DiskCopyImage, and UniversalDiskImage).

This commit is contained in:
Rob Greene
2025-08-08 19:22:47 -05:00
parent f1ef40dab1
commit 5beb6f9fa0
26 changed files with 287 additions and 347 deletions
@@ -46,7 +46,6 @@ import com.webcodepro.applecommander.storage.filters.HexDumpFileFilter;
import com.webcodepro.applecommander.storage.os.dos33.DosFormatDisk;
import com.webcodepro.applecommander.storage.os.pascal.PascalFormatDisk;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
@@ -63,6 +62,9 @@ import io.github.applecommander.bastools.api.TokenReader;
import io.github.applecommander.bastools.api.Visitors;
import io.github.applecommander.bastools.api.model.Program;
import io.github.applecommander.bastools.api.model.Token;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
/**
* ac provides a command line interface to key AppleCommander functions. Text
@@ -611,8 +613,8 @@ public class ac {
*/
public static void createDosDisk(String fileName, int imageSize)
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new DosOrder(layout);
Source source = new FileSource(DataBuffer.create(imageSize));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = DosFormatDisk.create(fileName, imageOrder);
disks[0].save();
}
@@ -622,8 +624,8 @@ public class ac {
*/
public static void createPasDisk(String fileName, String volName, int imageSize)
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(imageSize));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(fileName, volName, imageOrder);
disks[0].save();
}
@@ -633,8 +635,8 @@ public class ac {
*/
public static void createProDisk(String fileName, String volName, int imageSize)
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(imageSize));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(fileName, volName, imageOrder);
disks[0].save();
}
@@ -23,11 +23,13 @@ import java.util.function.Function;
import java.util.logging.Logger;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.NibbleOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
public enum OrderType {
DOS(OrderType::createDosImageOrder),
@@ -62,8 +64,8 @@ public enum OrderType {
LOG.warning("Setting image size to 800KB.");
size = Disk.APPLE_800KB_DISK;
}
ByteArrayImageLayout layout = new ByteArrayImageLayout(new byte[size]);
return new DosOrder(layout);
Source source = new FileSource(DataBuffer.create(size));
return new DosOrder(source);
}
/**
* Nibblized disks are always 140K disks (or ~230K on disk).
@@ -72,8 +74,8 @@ public enum OrderType {
if (size != Disk.APPLE_140KB_NIBBLE_DISK && size != Disk.APPLE_140KB_DISK) {
LOG.warning("Setting image size to 140KB");
}
ByteArrayImageLayout layout = new ByteArrayImageLayout(new byte[Disk.APPLE_140KB_NIBBLE_DISK]);
return new NibbleOrder(layout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_NIBBLE_DISK));
return new NibbleOrder(source);
}
/**
* Lock ProDOS into 140K, 800K, or anything between 800K and 32M.
@@ -95,8 +97,7 @@ public enum OrderType {
LOG.warning("Setting image size to 32MB.");
size = Disk.APPLE_32MB_HARDDISK;
}
ByteArrayImageLayout layout = new ByteArrayImageLayout(size);
return new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(size));
return new ProdosOrder(source);
}
}
@@ -33,8 +33,14 @@ import com.webcodepro.applecommander.storage.physical.*;
import com.webcodepro.applecommander.util.AppleUtil;
import com.webcodepro.applecommander.util.StreamUtil;
import com.webcodepro.applecommander.util.TextBundle;
import org.applecommander.image.DiskCopyImage;
import org.applecommander.image.UniversalDiskImage;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import java.io.*;
import java.nio.file.Path;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -75,7 +81,7 @@ public class Disk {
public static final int APPLE_140KB_NIBBLE_DISK = 232960;
public static final int APPLE_800KB_DISK = 819200;
public static final int APPLE_800KB_2IMG_DISK =
APPLE_800KB_DISK + UniversalDiskImageLayout.OFFSET;
APPLE_800KB_DISK + UniversalDiskImage.HEADER_SIZE;
public static final int APPLE_5MB_HARDDISK = 5242880;
public static final int APPLE_10MB_HARDDISK = 10485760;
public static final int APPLE_20MB_HARDDISK = 20971520;
@@ -87,7 +93,7 @@ public class Disk {
private String filename;
private boolean newImage = false;
private boolean isDC42 = false;
private ByteArrayImageLayout diskImageManager;
private Source diskImageManager;
private ImageOrder imageOrder = null;
/**
@@ -233,28 +239,18 @@ public class Disk {
/* Does it have the DiskCopy 4.2 header? */
else if (Disk.isDC42(diskImage)) {
isDC42 = true;
long end = AppleUtil.getLongValue(diskImage,0x40);
if (end < diskImage.length - 83) {
diskImageDC42 = new byte[(int)end];
System.arraycopy(diskImage, 84, diskImageDC42, 0, (int)end); // 84 bytes into the DC42 stream is where the real data starts
diskImageManager = new ByteArrayImageLayout(diskImageDC42);
// Since we don't want to overwrite their dmg or dc42 with a raw ProDOS image,
// add a .po extension to it
this.filename += ".po"; //$NON-NLS-1$
}
else
throw new IllegalArgumentException(textBundle.get("CommandLineDC42Bad")); //$NON-NLS-1$
}
if (is2img == true || diskImage.length == APPLE_800KB_DISK + UniversalDiskImageLayout.OFFSET
|| diskImage.length == APPLE_5MB_HARDDISK + UniversalDiskImageLayout.OFFSET
|| diskImage.length == APPLE_10MB_HARDDISK + UniversalDiskImageLayout.OFFSET
|| diskImage.length == APPLE_20MB_HARDDISK + UniversalDiskImageLayout.OFFSET
|| diskImage.length == APPLE_32MB_HARDDISK + UniversalDiskImageLayout.OFFSET) {
diskImageManager = new UniversalDiskImageLayout(diskImage);
Path sourcePath = Path.of(filename);
if (is2img || diskImage.length == APPLE_800KB_DISK + UniversalDiskImage.HEADER_SIZE
|| diskImage.length == APPLE_5MB_HARDDISK + UniversalDiskImage.HEADER_SIZE
|| diskImage.length == APPLE_10MB_HARDDISK + UniversalDiskImage.HEADER_SIZE
|| diskImage.length == APPLE_20MB_HARDDISK + UniversalDiskImage.HEADER_SIZE
|| diskImage.length == APPLE_32MB_HARDDISK + UniversalDiskImage.HEADER_SIZE) {
diskImageManager = new UniversalDiskImage(new FileSource(sourcePath));
} else if (isDC42) {
diskImageManager = new ByteArrayImageLayout(diskImageDC42);
diskImageManager = new DiskCopyImage(new FileSource(sourcePath));
} else {
diskImageManager = new ByteArrayImageLayout(diskImage);
diskImageManager = new FileSource(sourcePath);
}
ImageOrder dosOrder = new DosOrder(diskImageManager);
@@ -334,7 +330,7 @@ public class Disk {
*/
public int testImageOrder()
{
int rc = (true == isProdosFormat() ? 1 : 0) + (true == isDosFormat() ? 2 : 0) + (true == isCpmFormat() ? 4 : 0) + (true == isUniDosFormat() ? 8 : 0) + (true == isPascalFormat() ? 16 : 0) + (true == isOzDosFormat() ? 32 : 0);
int rc = (isProdosFormat() ? 1 : 0) + (isDosFormat() ? 2 : 0) + (isCpmFormat() ? 4 : 0) + (isUniDosFormat() ? 8 : 0) + (isPascalFormat() ? 16 : 0) + (isOzDosFormat() ? 32 : 0);
if (rc == 0)
rc = -1;
return rc;
@@ -352,9 +348,12 @@ public class Disk {
if (isCompressed()) {
output = new GZIPOutputStream(output);
}
output.write(getDiskImageManager().getDiskImage());
DataBuffer data =getDiskImageManager().readAllBytes();
byte[] fileData = new byte[data.limit()];
data.read(fileData);
output.write(fileData);
output.close();
getDiskImageManager().setChanged(false);
getDiskImageManager().clearChanges();
newImage = false;
}
@@ -411,9 +410,9 @@ public class Disk {
/**
* Returns the diskImageManager.
* @return ByteArrayImageLayout diskImageManager The disk Image Manager of this disk
* @return Source diskImageManager The disk Image Manager of this disk
*/
public ByteArrayImageLayout getDiskImageManager() {
public Source getDiskImageManager() {
if (imageOrder != null) {
return imageOrder.getDiskImageManager();
}
@@ -523,7 +522,7 @@ public class Disk {
return getImageOrder().getPhysicalSize();
}
if (getDiskImageManager() != null) {
return getDiskImageManager().getPhysicalSize();
return getDiskImageManager().getSize();
}
return getImageOrder().getPhysicalSize();
}
@@ -540,10 +539,8 @@ public class Disk {
throw new IllegalArgumentException(
textBundle.get("Disk.ResizeDiskError")); //$NON-NLS-1$
}
byte[] newDiskImage = new byte[newSize];
byte[] oldDiskImage = imageOrder.getDiskImageManager().getDiskImage();
System.arraycopy(oldDiskImage, 0, newDiskImage, 0, oldDiskImage.length);
imageOrder.getDiskImageManager().setDiskImage(newDiskImage);
DataBuffer backingBuffer = imageOrder.getDiskImageManager().get(DataBuffer.class).orElseThrow();
backingBuffer.limit(newSize);
}
/**
@@ -865,32 +862,6 @@ public class Disk {
this.imageOrder = imageOrder;
}
/**
* Change underlying image order to DOS ImageOrder.
* Assumes this is a 140k disk image.
*
* @see ImageOrder
*/
public void makeDosOrder()
{
DosOrder doso = new DosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK));
changeImageOrderByTrackAndSector(getImageOrder(), doso);
setImageOrder(doso);
}
/**
* Change to a different ImageOrder. Remains in ProDOS format but the
* underlying order can change.
*
* @see ImageOrder
*/
public void makeProdosOrder()
{
ProdosOrder pdo = new ProdosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK));
changeImageOrderByBlock(getImageOrder(), pdo);
setImageOrder(pdo);
}
/**
* Find the standard sized disk that will fit the requested number of bytes.
* @return int size of the disk if it will satisfy the request, -1 otherwise
@@ -906,8 +877,6 @@ public class Disk {
return APPLE_10MB_HARDDISK;
} else if (bytes < APPLE_20MB_HARDDISK) {
return APPLE_20MB_HARDDISK;
} else if (bytes < APPLE_32MB_HARDDISK) {
return APPLE_20MB_HARDDISK;
} else if (bytes < APPLE_32MB_HARDDISK) {
return APPLE_32MB_HARDDISK;
}
@@ -101,7 +101,7 @@ public class OzDosFormatDisk extends DosFormatDisk {
final int tracksPerDisk = 50;
final int sectorsPerTrack = 32;
final int firstCatalogSector = 31;
// We can't use the ImageLayout to format this disk since that actually wipes the entire
// We can't use the Source buffer to format this disk since that actually wipes the entire
// 800K volume (that is, both disk1 and disk2 get cleared).
byte[] data = new byte[SECTOR_SIZE];
for (int t = 0; t < tracksPerDisk; t++) {
@@ -100,7 +100,7 @@ public class UniDosFormatDisk extends DosFormatDisk {
final int tracksPerDisk = 50;
final int sectorsPerTrack = 32;
final int firstCatalogSector = 31;
// We can't use the ImageLayout to format this disk since that actually wipes the entire
// We can't use the DataBuffer to wipe this disk since that actually wipes the entire
// 800K volume (that is, both disk1 and disk2 get cleared).
byte[] data = new byte[SECTOR_SIZE];
for (int t = 0; t < tracksPerDisk; t++) {
@@ -1,116 +0,0 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2003-2022 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.storage.physical;
/**
* Manages the layout of the physical disk. This hides implementation details,
* such as if the disk is in 2IMG order.
* <p>
* @author Rob Greene (RobGreene@users.sourceforge.net)
*/
public class ByteArrayImageLayout {
/**
* This is the physical copy of the disk image which a particular
* implementation of ImageOrder will interpret.
*/
private byte[] diskImage;
/**
* Indicates if the disk image has changed.
*/
private boolean changed;
/**
* Construct a ByteArrayImageLayout.
*/
public ByteArrayImageLayout(byte[] diskImage) {
setDiskImage(diskImage);
changed = false; // setDiskImage by default sets to true but we don't want that
}
/**
* Construct a ByteArrayImageLayout.
*/
public ByteArrayImageLayout(byte[] diskImage, boolean changed) {
setDiskImage(diskImage);
this.changed = changed;
}
/**
* Construct a ByteArrayImageLayout.
*/
public ByteArrayImageLayout(int size) {
diskImage = new byte[size];
changed = true;
}
/**
* Get the physical disk image.
*/
public byte[] getDiskImage() {
return diskImage;
}
/**
* Set the physical disk image.
*/
public void setDiskImage(byte[] diskImage) {
this.diskImage = diskImage;
changed = true;
}
/**
* Answer with the physical size of this disk volume.
*/
public int getPhysicalSize() {
return (diskImage != null) ? diskImage.length : 0;
}
/**
* Extract a portion of the disk image.
*/
public byte[] readBytes(int start, int length) {
byte[] buffer = new byte[length];
System.arraycopy(diskImage, start, buffer, 0, length);
return buffer;
}
/**
* Write data to the disk image.
*/
public void writeBytes(int start, byte[] bytes) {
changed = true;
System.arraycopy(bytes, 0, diskImage, start, bytes.length);
}
/**
* Indicates if the disk has changed. Triggered when data is
* written and cleared when data is saved.
*/
public boolean hasChanged() {
return changed;
}
/**
* Set the changed indicator.
*/
public void setChanged(boolean changed) {
this.changed = changed;
}
}
@@ -23,6 +23,7 @@ import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.StorageBundle;
import com.webcodepro.applecommander.storage.os.dos33.DosSectorAddress;
import com.webcodepro.applecommander.util.TextBundle;
import org.applecommander.source.Source;
/**
* Supports disk images stored in DOS physical order.
@@ -34,7 +35,7 @@ public class DosOrder extends ImageOrder {
/**
* Construct a DosOrder.
*/
public DosOrder(ByteArrayImageLayout diskImageManager) {
public DosOrder(Source diskImageManager) {
super(diskImageManager);
}
@@ -20,6 +20,8 @@
package com.webcodepro.applecommander.storage.physical;
import com.webcodepro.applecommander.storage.Disk;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
/**
* Manages the interface between the physical disk image order and the
@@ -57,19 +59,19 @@ public abstract class ImageOrder {
* This is the physical copy of the disk image which a particular
* implementation of ImageOrder will interpret.
*/
private ByteArrayImageLayout diskImageManager;
private Source diskImageManager;
/**
* Construct a ImageOrder.
*/
public ImageOrder(ByteArrayImageLayout diskImageManager) {
public ImageOrder(Source diskImageManager) {
setDiskImageManager(diskImageManager);
}
/**
* Get the physical disk image.
*/
public ByteArrayImageLayout getDiskImageManager() {
public Source getDiskImageManager() {
return diskImageManager;
}
@@ -77,13 +79,13 @@ public abstract class ImageOrder {
* Answer with the physical size of this disk volume.
*/
public int getPhysicalSize() {
return diskImageManager.getPhysicalSize();
return diskImageManager.getSize();
}
/**
* Set the physical disk image.
*/
public void setDiskImageManager(ByteArrayImageLayout diskImageManager) {
public void setDiskImageManager(Source diskImageManager) {
this.diskImageManager = diskImageManager;
}
@@ -91,14 +93,17 @@ public abstract class ImageOrder {
* Extract a portion of the disk image.
*/
public byte[] readBytes(int start, int length) {
return diskImageManager.readBytes(start, length);
DataBuffer data = diskImageManager.readBytes(start, length);
byte[] bytes = new byte[length];
data.get(0, bytes);
return bytes;
}
/**
* Write data to the disk image.
*/
public void writeBytes(int start, byte[] bytes) {
diskImageManager.writeBytes(start, bytes);
diskImageManager.writeBytes(start, DataBuffer.wrap(bytes));
}
/**
@@ -178,8 +183,8 @@ public abstract class ImageOrder {
* sector markers.
*/
public void format() {
int size = diskImageManager.getPhysicalSize();
diskImageManager.setDiskImage(new byte[size]);
int size = diskImageManager.getSize();
diskImageManager.writeBytes(0, DataBuffer.create(size));
}
/**
@@ -19,6 +19,9 @@
*/
package com.webcodepro.applecommander.storage.physical;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import java.util.Arrays;
import static com.webcodepro.applecommander.storage.physical.NibbleCodec.*;
@@ -44,7 +47,7 @@ public class NibbleOrder extends DosOrder {
/**
* Construct a NibbleOrder.
*/
public NibbleOrder(ByteArrayImageLayout diskImageManager) {
public NibbleOrder(Source diskImageManager) {
super(diskImageManager);
// Identify 13-sector vs 16-sector
byte[] trackData = readTrackData(0);
@@ -132,7 +135,7 @@ public class NibbleOrder extends DosOrder {
// pre-fill entire disk with 0xff
byte[] diskImage = new byte[232960]; // 6656 bytes per track
Arrays.fill(diskImage, (byte)0xff);
getDiskImageManager().setDiskImage(diskImage);
getDiskImageManager().writeBytes(0, DataBuffer.wrap(diskImage));
// create initial address and data fields
byte[] addressField = new byte[14];
byte[] dataField = new byte[349];
@@ -22,6 +22,7 @@ package com.webcodepro.applecommander.storage.physical;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.StorageBundle;
import com.webcodepro.applecommander.util.TextBundle;
import org.applecommander.source.Source;
/**
* Supports disk images stored in ProDOS physical order.
@@ -47,7 +48,7 @@ public class ProdosOrder extends ImageOrder {
/**
* Construct a ProdosOrder.
*/
public ProdosOrder(ByteArrayImageLayout diskImageManager) {
public ProdosOrder(Source diskImageManager) {
super(diskImageManager);
}
@@ -1,67 +0,0 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2003-2022 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.storage.physical;
/**
* Manages the physical 2IMG disk.
* @author Rob Greene (RobGreene@users.sourceforge.net)
*/
public class UniversalDiskImageLayout extends ByteArrayImageLayout {
/**
* This is the 2IMG offset.
*/
public static final int OFFSET = 0x40;
/**
* Construct a UniversalDiskImageLayout.
*/
public UniversalDiskImageLayout(byte[] diskImage) {
super(diskImage);
}
/**
* Construct a UniversalDiskImageLayout.
*/
public UniversalDiskImageLayout(byte[] diskImage, boolean changed) {
super(diskImage, changed);
}
/**
* Construct a UniversalDiskImageLayout.
*/
public UniversalDiskImageLayout(int size) {
super(size + OFFSET);
}
/**
* Extract a portion of the disk image.
*/
public byte[] readBytes(int start, int length) {
return super.readBytes(start + OFFSET, length);
}
/**
* Write data to the disk image.
*/
public void writeBytes(int start, byte[] bytes) {
super.writeBytes(start + OFFSET, bytes);
}
}
@@ -22,6 +22,8 @@ package com.webcodepro.applecommander.storage.physical;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.os.dos33.DosSectorAddress;
import com.webcodepro.applecommander.util.AppleUtil;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
@@ -64,14 +66,13 @@ public class WozOrder extends ImageOrder {
private Function<Integer,byte[]> blockReader = this::readBlock525;
private BiFunction<Integer,Integer,byte[]> sectorReader = this::readSector525;
public WozOrder(ByteArrayImageLayout layout) {
super(layout);
public WozOrder(Source source) {
super(source);
ByteBuffer bb = ByteBuffer.wrap(layout.getDiskImage());
bb.order(ByteOrder.LITTLE_ENDIAN);
DataBuffer bb = source.readAllBytes();
int sig = bb.getInt();
int test = bb.getInt();
int sig = bb.readInt();
int test = bb.readInt();
final int testExpected = 0xa0d0aff;
if (sig == WOZ1_MAGIC && test == testExpected) {
this.trackReader = this::readTrackDataWOZ1;
@@ -82,14 +83,14 @@ public class WozOrder extends ImageOrder {
else {
throw new RuntimeException("Not a WOZ1 or WOZ2 format file.");
}
bb.getInt(); // ignoring CRC
bb.readInt(); // ignoring CRC
Consumer<byte[]> tmapReader = this::readTmapChunk525;
while (bb.hasRemaining()) {
int chunkId = bb.getInt();
int chunkSize = bb.getInt();
int chunkId = bb.readInt();
int chunkSize = bb.readInt();
byte[] data = new byte[chunkSize];
bb.get(data);
bb.read(data);
switch (chunkId) {
case INFO_CHUNK_ID:
this.info = new InfoChunk(data);
@@ -28,13 +28,15 @@ import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.storage.StorageBundle;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFileEntry;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
import com.webcodepro.shrinkit.HeaderBlock;
import com.webcodepro.shrinkit.NuFileArchive;
import com.webcodepro.shrinkit.ThreadRecord;
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
/**
* Some higher-level utilities for dealing with a NuFX archive.
@@ -83,8 +85,8 @@ public class ShrinkItUtilities
int newDiskSize = Disk.sizeToFit(a.getArchiveSize());
if (startBlocks > 0)
newDiskSize = startBlocks*512;
ByteArrayImageLayout layout = new ByteArrayImageLayout(newDiskSize);
ImageOrder imageOrder = new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(newDiskSize));
ImageOrder imageOrder = new ProdosOrder(source);
// Create a new disk in anticipation of unpacking files - we don't actually know if we'll need it yet, though.
FormattedDisk[] disks = ProdosFormatDisk.create(fileName, "APPLECOMMANDER", imageOrder); //$NON-NLS-1$
// Make some typing easier... get a handle to the disk we created, with ProdosFormatDisk extensions.
@@ -4,6 +4,8 @@ import org.applecommander.capability.Capability;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import java.util.Optional;
public class DiskCopyImage implements Source {
public static final int HEADER_SIZE = 84;
@@ -33,10 +35,28 @@ public class DiskCopyImage implements Source {
return false;
}
@Override
public <T> Optional<T> get(Class<T> iface) {
if (iface.isInstance(source)) {
return Optional.of(iface.cast(source));
}
else if (iface.isInstance(info)) {
return Optional.of(iface.cast(info));
}
else {
return source.get(iface);
}
}
public Info getInfo() {
return info;
}
@Override
public int getSize() {
return source.getSize() - HEADER_SIZE;
}
@Override
public DataBuffer readAllBytes() {
return this.source.readBytes(HEADER_SIZE, getInfo().dataSize());
@@ -52,6 +72,16 @@ public class DiskCopyImage implements Source {
this.source.writeBytes(HEADER_SIZE+offset, data);
}
@Override
public boolean hasChanged() {
return source.hasChanged();
}
@Override
public void clearChanges() {
source.clearChanges();
}
public record Info(String diskName, int dataSize, int tagSize, int dataChecksum, int tagChecksum,
int diskFormat, int formatByte) {
}
@@ -4,6 +4,8 @@ import org.applecommander.capability.Capability;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import java.util.Optional;
public class UniversalDiskImage implements Source {
public static final int MAGIC = 0x32494d47; // "2IMG" marker
public static final int HEADER_SIZE = 0x40; // documented header size
@@ -56,6 +58,24 @@ public class UniversalDiskImage implements Source {
return false;
}
@Override
public int getSize() {
return source.getSize() - HEADER_SIZE;
}
@Override
public <T> Optional<T> get(Class<T> iface) {
if (iface.isInstance(source)) {
return Optional.of(iface.cast(source));
}
else if (iface.isInstance(info)) {
return Optional.of(iface.cast(info));
}
else {
return source.get(iface);
}
}
@Override
public DataBuffer readAllBytes() {
return source.readBytes(this.info.dataOffset, this.info.dataLength);
@@ -71,6 +91,16 @@ public class UniversalDiskImage implements Source {
source.writeBytes(this.info.dataOffset + offset, data);
}
@Override
public boolean hasChanged() {
return source.hasChanged();
}
@Override
public void clearChanges() {
source.clearChanges();
}
public record Info(String creator, int headerSize, int version, int imageFormat, int flags,
int prodosBlocks, int dataOffset, int dataLength, String comment, DataBuffer creatorData) {
public boolean isDOSOrdered() {
@@ -7,17 +7,25 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
public class FileSource implements Source {
private Path path;
private DataBuffer buffer;
private boolean changed;
public FileSource(Path path) {
try {
this.path = path;
this.buffer = DataBuffer.wrap(Files.readAllBytes(path));
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
// TODO should this be separate or is "FileSource" a misnomer?
public FileSource(DataBuffer buffer) {
this.buffer = buffer;
}
@Override
public boolean can(Capability capability) {
@@ -25,6 +33,19 @@ public class FileSource implements Source {
return false;
}
@Override
public <T> Optional<T> get(Class<T> iface) {
if (iface.isInstance(buffer)) {
return Optional.of(iface.cast(this));
}
return Optional.empty();
}
@Override
public int getSize() {
return buffer.limit();
}
@Override
public DataBuffer readAllBytes() {
return buffer;
@@ -38,5 +59,16 @@ public class FileSource implements Source {
@Override
public void writeBytes(int offset, DataBuffer data) {
buffer.put(offset, data);
changed = true;
}
@Override
public boolean hasChanged() {
return changed;
}
@Override
public void clearChanges() {
changed = false;
}
}
@@ -1,13 +1,17 @@
package org.applecommander.source;
import org.applecommander.capability.CapabilityProvider;
import org.applecommander.util.Container;
import org.applecommander.util.DataBuffer;
/**
* Source for an archive or disk in AppleCommander.
*/
public interface Source extends CapabilityProvider {
public interface Source extends CapabilityProvider, Container {
int getSize();
DataBuffer readAllBytes();
DataBuffer readBytes(int offset, int length);
void writeBytes(int offset, DataBuffer data);
boolean hasChanged();
void clearChanges();
}
@@ -0,0 +1,18 @@
package org.applecommander.util;
import java.util.Optional;
/**
* Container marks an object that contains other objects for retrieval.
* Experimental - the idea is to no longer expose everything that *might*
* apply, but instead test if it's there and react accordingly.
* <p/>
* The end goal is to be able to retrieve the various devices - than have to
* be handled distinctly anyway - and work from that. A DOS disk won't be backed
* by a BlockDevice (most of the time), so it's counterintuitive that the DOS
* file system has block level access. Vice versa for ProDOS/Pascal/RDOS/CPM.
* Not to mention that it doesn't apply to Shrinkit or Zip archives at all.
*/
public interface Container {
<T> Optional<T> get(Class<T> iface);
}
@@ -49,6 +49,9 @@ public class DataBuffer {
public int limit() {
return this.buffer.limit();
}
public void limit(int newLimit) {
this.buffer.limit(newLimit);
}
// GET/PUT RELATED FUNCTIONS
@@ -58,6 +61,11 @@ public class DataBuffer {
public int getUnsignedShort(int index) {
return Short.toUnsignedInt(this.buffer.getShort(index));
}
public void get(int position, byte[] data) {
// Hopefully this is a bridge method and can be removed over time
this.buffer.get(position, data);
}
public String getFixedLengthString(int index, int length) {
byte[] s = new byte[length];
this.buffer.get(index, s);
@@ -105,6 +113,9 @@ public class DataBuffer {
this.buffer.order(ByteOrder.LITTLE_ENDIAN);
return value;
}
public void read(byte[] data) {
this.buffer.get(data);
}
public int readInt() {
return this.buffer.getInt();
}
@@ -25,6 +25,9 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.List;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import org.junit.Test;
import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage;
@@ -33,7 +36,6 @@ import com.webcodepro.applecommander.storage.os.dos33.OzDosFormatDisk;
import com.webcodepro.applecommander.storage.os.dos33.UniDosFormatDisk;
import com.webcodepro.applecommander.storage.os.pascal.PascalFormatDisk;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.NibbleOrder;
@@ -57,8 +59,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToDos33() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.dsk", imageOrder); //$NON-NLS-1$
writeFiles(disks, "B", "T", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
@@ -69,8 +71,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToDos33Nibble() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_NIBBLE_DISK);
ImageOrder imageOrder = new NibbleOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_NIBBLE_DISK));
ImageOrder imageOrder = new NibbleOrder(source);
FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.nib", imageOrder); //$NON-NLS-1$
writeFiles(disks, "B", "T", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
@@ -81,8 +83,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToPascal140kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(
"write-test-pascal-140k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "code", "text", false); //$NON-NLS-1$ //$NON-NLS-2$
@@ -94,8 +96,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToPascal800kDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(
"write-test-pascal-800k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
//writeFiles(disks, "code", "text", false); //$NON-NLS-1$ //$NON-NLS-2$
@@ -107,8 +109,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToProdos140kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-140k.dsk", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
@@ -120,8 +122,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToProdos800kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-800k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
@@ -133,8 +135,8 @@ public class DiskWriterTest {
*/
@Test
public void testWriteToProdos5mbDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_5MB_HARDDISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_5MB_HARDDISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-5mb.hdv", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
@@ -146,8 +148,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeleteDos33() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = DosFormatDisk.create(
"createanddelete-test-dos33.dsk", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
@@ -159,8 +161,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeleteOzDos() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = OzDosFormatDisk.create(
"createanddelete-test-ozdos.po", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
@@ -172,8 +174,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeleteUniDos() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = UniDosFormatDisk.create(
"createanddelete-test-unidos.dsk", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
@@ -185,8 +187,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeletePascal140kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(
"createanddelete-test-pascal-140k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -199,8 +201,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeletePascal800kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(
"createanddelete-test-pascal-800k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -213,8 +215,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeleteProdos140kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createanddelete-test-prodos-140k.dsk", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -227,8 +229,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateAndDeleteProdos800kDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createanddelete-test-prodos-800k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -242,8 +244,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateDeleteCreateDosDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = DosFormatDisk.create(
"createdeletecreate-test-dos-140k.dsk", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
@@ -256,8 +258,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateDeleteCreateOzdosDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = OzDosFormatDisk.create(
"createdeletecreate-test-ozdos-800k.po", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
@@ -270,8 +272,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateDeleteCreateUnidosDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_800KB_DISK));
ImageOrder imageOrder = new DosOrder(source);
FormattedDisk[] disks = UniDosFormatDisk.create(
"createdeletecreate-test-unidos-800k.dsk", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
@@ -284,8 +286,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateDeleteCreatePascalDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = PascalFormatDisk.create(
"createdeletecreate-test-pascal-140k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -299,8 +301,8 @@ public class DiskWriterTest {
*/
@Test
public void testCreateDeleteCreateProdosDisk() throws IOException, DiskException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder imageOrder = new ProdosOrder(source);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createdeletecreate-test-prodos-140k.dsk", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
@@ -21,19 +21,21 @@ package com.webcodepro.applecommander.storage.os.dos33;
import static org.junit.Assert.assertEquals;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import org.junit.Test;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.DiskFullException;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
public class DosFormatDiskTest {
@Test
public void testSanitizeFilename() throws DiskFullException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder order = new DosOrder(layout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder order = new DosOrder(source);
DosFormatDisk[] disks = DosFormatDisk.create("deleteme.do", order);
DosFormatDisk disk = disks[0];
@@ -21,19 +21,21 @@ package com.webcodepro.applecommander.storage.os.pascal;
import static org.junit.Assert.assertEquals;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import org.junit.Test;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.DiskFullException;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
public class PascalFormatDiskTest {
@Test
public void testSanitizeFilename() throws DiskFullException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder order = new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder order = new ProdosOrder(source);
PascalFormatDisk[] disks = PascalFormatDisk.create("deleteme.po", "TEST", order);
PascalFormatDisk disk = disks[0];
@@ -21,19 +21,21 @@ package com.webcodepro.applecommander.storage.os.prodos;
import static org.junit.Assert.*;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import org.junit.Test;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.DiskFullException;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
public class ProdosFormatDiskTest {
@Test
public void testSanitizeFilename() throws DiskFullException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder order = new ProdosOrder(layout);
Source source = new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK));
ImageOrder order = new ProdosOrder(source);
ProdosFormatDisk[] disks = ProdosFormatDisk.create("deleteme.po", "nothere", order);
ProdosFormatDisk disk = disks[0];
@@ -26,10 +26,11 @@ import com.webcodepro.applecommander.storage.compare.ComparisonResult;
import com.webcodepro.applecommander.storage.compare.DiskDiff;
import com.webcodepro.applecommander.storage.os.dos33.DosFormatDisk;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.NibbleOrder;
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
import org.applecommander.source.FileSource;
import org.applecommander.util.DataBuffer;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -80,14 +81,14 @@ public class AppleUtilTest {
public void testChangeDosImageOrder() throws DiskFullException {
// Straight DOS disk in standard DOS order
DosFormatDisk dosDiskDosOrder = DosFormatDisk.create("dostemp.dsk", //$NON-NLS-1$
new DosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0];
new DosOrder(new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK))))[0];
FileEntry fileEntry = dosDiskDosOrder.createFile();
fileEntry.setFilename("TESTFILE"); //$NON-NLS-1$
fileEntry.setFiletype("T"); //$NON-NLS-1$
fileEntry.setFileData("This is a test file.".getBytes()); //$NON-NLS-1$
// A duplicate - then we change it to a NIB disk image...
DosFormatDisk dosDiskNibbleOrder = DosFormatDisk.create("dostemp2.nib", //$NON-NLS-1$
new NibbleOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0];
new NibbleOrder(new FileSource(DataBuffer.create(Disk.APPLE_140KB_NIBBLE_DISK))))[0];
AppleUtil.changeImageOrderByTrackAndSector(dosDiskDosOrder.getImageOrder(),
dosDiskNibbleOrder.getImageOrder());
// Confirm that these disks are identical:
@@ -101,7 +102,7 @@ public class AppleUtilTest {
// Straight ProDOS disk in standard ProDOS block order
ProdosFormatDisk prodosDiskDosOrder = ProdosFormatDisk.create("prodostemp.po", //$NON-NLS-1$
"prodostemp", //$NON-NLS-1$
new ProdosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0];
new ProdosOrder(new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK))))[0];
FileEntry fileEntry = prodosDiskDosOrder.createFile();
fileEntry.setFilename("TESTFILE"); //$NON-NLS-1$
fileEntry.setFiletype("TXT"); //$NON-NLS-1$
@@ -109,7 +110,7 @@ public class AppleUtilTest {
// A duplicate - then we change it to a NIB disk image...
ProdosFormatDisk prodosDiskNibbleOrder = ProdosFormatDisk.create("prodostemp2.nib", //$NON-NLS-1$
"prodostemp2", //$NON-NLS-1$
new NibbleOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0];
new NibbleOrder(new FileSource(DataBuffer.create(Disk.APPLE_140KB_NIBBLE_DISK))))[0];
AppleUtil.changeImageOrderByBlock(prodosDiskDosOrder.getImageOrder(),
prodosDiskNibbleOrder.getImageOrder());
// Confirm that these disks are identical:
@@ -41,6 +41,8 @@ import com.webcodepro.applecommander.util.Host;
import com.webcodepro.applecommander.util.StreamUtil;
import com.webcodepro.applecommander.util.TextBundle;
import io.github.applecommander.applesingle.AppleSingle;
import org.applecommander.source.FileSource;
import org.applecommander.util.DataBuffer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
@@ -1953,7 +1955,7 @@ public class DiskExplorerTab {
public void widgetSelected(SelectionEvent event) {
if (!getDisk(0).isNibbleOrder()) {
NibbleOrder nibbleOrder = new NibbleOrder(
new ByteArrayImageLayout(Disk.APPLE_140KB_NIBBLE_DISK));
new FileSource(DataBuffer.create(Disk.APPLE_140KB_NIBBLE_DISK)));
nibbleOrder.format();
changeImageOrder("nib", nibbleOrder); //$NON-NLS-1$
}
@@ -1966,7 +1968,7 @@ public class DiskExplorerTab {
public void widgetSelected(SelectionEvent event) {
if (!getDisk(0).isDosOrder()) {
changeImageOrder("dsk", new DosOrder( //$NON-NLS-1$
new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)));
new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK))));
}
}
});
@@ -1977,7 +1979,7 @@ public class DiskExplorerTab {
public void widgetSelected(SelectionEvent event) {
if (!getDisk(0).isProdosOrder()) {
changeImageOrder("po", new ProdosOrder( //$NON-NLS-1$
new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)));
new FileSource(DataBuffer.create(Disk.APPLE_140KB_DISK))));
}
}
});
@@ -19,6 +19,9 @@
*/
package com.webcodepro.applecommander.ui.swt.wizard.diskimage;
import org.applecommander.source.FileSource;
import org.applecommander.source.Source;
import org.applecommander.util.DataBuffer;
import org.eclipse.swt.widgets.Shell;
import com.webcodepro.applecommander.storage.Disk;
@@ -30,7 +33,6 @@ import com.webcodepro.applecommander.storage.os.dos33.UniDosFormatDisk;
import com.webcodepro.applecommander.storage.os.pascal.PascalFormatDisk;
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
import com.webcodepro.applecommander.storage.os.rdos.RdosFormatDisk;
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
import com.webcodepro.applecommander.storage.physical.DosOrder;
import com.webcodepro.applecommander.storage.physical.ImageOrder;
import com.webcodepro.applecommander.storage.physical.NibbleOrder;
@@ -92,17 +94,17 @@ public class DiskImageWizard extends Wizard {
if (isCompressed()) {
name.append(".gz"); //$NON-NLS-1$
}
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(getSize());
Source source = new FileSource(DataBuffer.create(getSize()));
ImageOrder imageOrder = null;
switch (getOrder()) {
case ORDER_DOS:
imageOrder = new DosOrder(imageLayout);
imageOrder = new DosOrder(source);
break;
case ORDER_NIBBLE:
imageOrder = new NibbleOrder(imageLayout);
imageOrder = new NibbleOrder(source);
break;
case ORDER_PRODOS:
imageOrder = new ProdosOrder(imageLayout);
imageOrder = new ProdosOrder(source);
break;
}
switch (format) {