Fail harder when files don't unshrink well

Allow size specification on unshrink image
This commit is contained in:
2012-08-12 17:30:52 +00:00
parent 2fac776ed3
commit 9fa4abe3f3
3 changed files with 34 additions and 6 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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)