From 9fa4abe3f3e97f5d6e65d9693647628ca93889b2 Mon Sep 17 00:00:00 2001 From: Date: Sun, 12 Aug 2012 17:30:52 +0000 Subject: [PATCH] Fail harder when files don't unshrink well Allow size specification on unshrink image --- .../applecommander/storage/Disk.java | 10 ++++++++- src/com/webcodepro/applecommander/ui/ac.java | 9 +++++--- src/com/webcodepro/shrinkit/Utilities.java | 21 +++++++++++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/Disk.java b/src/com/webcodepro/applecommander/storage/Disk.java index 7de2a2c..14dee5a 100644 --- a/src/com/webcodepro/applecommander/storage/Disk.java +++ b/src/com/webcodepro/applecommander/storage/Disk.java @@ -176,6 +176,14 @@ public class Disk { * Read in the entire contents of the file. */ public Disk(String filename) throws IOException { + this(filename, 0); + } + + /** + * Construct a Disk and load the specified file. + * Read in the entire contents of the file. + */ + public Disk(String filename, int startBlocks) throws IOException { this.filename = filename; int diskSize = 0; byte[] diskImage = null; @@ -184,7 +192,7 @@ public class Disk { if (isSDK() || isSHK() || isBXY()) { // If we have an SDK, unpack it and send along the byte array // If we have a SHK, build a new disk and unpack the contents on to it - diskImage = com.webcodepro.shrinkit.Utilities.unpackSHKFile(filename); + diskImage = com.webcodepro.shrinkit.Utilities.unpackSHKFile(filename, startBlocks); diskSize = diskImage.length; // Since we don't want to overwrite their shrinkit with a raw ProDOS image, // add a .po extension to it diff --git a/src/com/webcodepro/applecommander/ui/ac.java b/src/com/webcodepro/applecommander/ui/ac.java index 47c999f..e7b78be 100644 --- a/src/com/webcodepro/applecommander/ui/ac.java +++ b/src/com/webcodepro/applecommander/ui/ac.java @@ -130,7 +130,10 @@ public class ac { } else if ("-pro800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ createProDisk(args[1], args[2], Disk.APPLE_800KB_DISK); } else if ("-convert".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ - convert(args[1], args[2]); + if (args.length > 3) + convert(args[1], args[2], Integer.parseInt(args[3])); + else + convert(args[1], args[2]); } else { help(); } @@ -543,11 +546,11 @@ public class ac { * * DiskCopy 4.2 image - convert it to a ProDOS image * SDK disk image - unpack it to a disk image - * ShrinkIt file bundle [future] - unpack files onto a disk image sized to fit + * ShrinkIt file bundle - unpack files onto a disk image sized to fit */ static void convert(String shrinkName, String imageName, int imageSize) throws IOException { - Disk disk = new Disk(shrinkName); + Disk disk = new Disk(shrinkName, imageSize); disk.setFilename(imageName); disk.save(); } diff --git a/src/com/webcodepro/shrinkit/Utilities.java b/src/com/webcodepro/shrinkit/Utilities.java index d30db9a..df70c94 100644 --- a/src/com/webcodepro/shrinkit/Utilities.java +++ b/src/com/webcodepro/shrinkit/Utilities.java @@ -55,6 +55,21 @@ public class Utilities * the file has some malformed-ness about it */ public static byte[] unpackSHKFile(String fileName) throws IOException + { + return unpackSHKFile(fileName, 0); + } + + /** + * Interpret a NuFile/NuFX/Shrinkit archive as a full disk image. + * + * @return byte[] buffer containing full disk of data; null if unable to + * read + * @throws IllegalArgumentException + * if the filename is not able to be read + * @throws IOException + * the file has some malformed-ness about it + */ + public static byte[] unpackSHKFile(String fileName, int startBlocks) throws IOException { TextBundle textBundle = StorageBundle.getInstance(); byte dmgBuffer[] = null; @@ -67,6 +82,8 @@ public class Utilities NuFileArchive a = new NuFileArchive(is); // If we need to build a disk to hold files (i.e. .shk vs. .sdk), how big would that disk need to be? int newDiskSize = Disk.sizeToFit(a.getArchiveSize()); + if (startBlocks > 0) + newDiskSize = startBlocks*512; ByteArrayImageLayout layout = new ByteArrayImageLayout(newDiskSize); ImageOrder imageOrder = new ProdosOrder(layout); // Create a new disk in anticipation of unpacking files - we don't actually know if we'll need it yet, though. @@ -113,7 +130,7 @@ public class Utilities } catch (Exception ex) { - System.out.println(ex); + throw new IOException(ex.getMessage()); } } try @@ -148,7 +165,7 @@ public class Utilities } catch (Exception ex) { - System.out.println(ex); + throw new IOException(ex.getMessage()); } } if (dmgBuffer != null)