diff --git a/src/com/webcodepro/applecommander/storage/Disk.java b/src/com/webcodepro/applecommander/storage/Disk.java index d96e9a4..8f6b2ec 100644 --- a/src/com/webcodepro/applecommander/storage/Disk.java +++ b/src/com/webcodepro/applecommander/storage/Disk.java @@ -266,6 +266,23 @@ public class Disk { return diskImage.length; } + /** + * Resize a disk image up to a larger size. The primary intention is to + * "fix" disk images that have been created too small. The primary culprit + * is ApplePC HDV images which dynamically grow. Since AppleCommander + * works with a byte array, the image must grow to its full size. + * @param newSize + */ + protected void resizeDiskImage(int newSize) { + if (newSize < diskImage.length) { + throw new IllegalArgumentException( + "Cannot resize a disk to be smaller than the current size!"); + } + byte[] newDiskImage = new byte[newSize]; + System.arraycopy(diskImage, 0, newDiskImage, 0, diskImage.length); + diskImage = newDiskImage; + } + /** * Read the block from the disk image. */ diff --git a/src/com/webcodepro/applecommander/storage/FormattedDisk.java b/src/com/webcodepro/applecommander/storage/FormattedDisk.java index 58b2c94..bac898a 100644 --- a/src/com/webcodepro/applecommander/storage/FormattedDisk.java +++ b/src/com/webcodepro/applecommander/storage/FormattedDisk.java @@ -354,4 +354,12 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry { public FormattedDisk getFormattedDisk() { return this; } + + /** + * Resize the disk image to be its full size. Only invole this + * method if a size does not match exception is thrown. + */ + public void resizeDiskImage() { + resizeDiskImage(getFreeSpace() + getUsedSpace()); + } }