mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-05-29 02:41:30 +00:00
Fail harder when files don't unshrink well
Allow size specification on unshrink image
This commit is contained in:
parent
2fac776ed3
commit
9fa4abe3f3
|
@ -176,6 +176,14 @@ public class Disk {
|
||||||
* Read in the entire contents of the file.
|
* Read in the entire contents of the file.
|
||||||
*/
|
*/
|
||||||
public Disk(String filename) throws IOException {
|
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;
|
this.filename = filename;
|
||||||
int diskSize = 0;
|
int diskSize = 0;
|
||||||
byte[] diskImage = null;
|
byte[] diskImage = null;
|
||||||
|
@ -184,7 +192,7 @@ public class Disk {
|
||||||
if (isSDK() || isSHK() || isBXY()) {
|
if (isSDK() || isSHK() || isBXY()) {
|
||||||
// If we have an SDK, unpack it and send along the byte array
|
// 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
|
// 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;
|
diskSize = diskImage.length;
|
||||||
// Since we don't want to overwrite their shrinkit with a raw ProDOS image,
|
// Since we don't want to overwrite their shrinkit with a raw ProDOS image,
|
||||||
// add a .po extension to it
|
// add a .po extension to it
|
||||||
|
|
|
@ -130,7 +130,10 @@ public class ac {
|
||||||
} else if ("-pro800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
} else if ("-pro800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
||||||
createProDisk(args[1], args[2], Disk.APPLE_800KB_DISK);
|
createProDisk(args[1], args[2], Disk.APPLE_800KB_DISK);
|
||||||
} else if ("-convert".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
} 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 {
|
} else {
|
||||||
help();
|
help();
|
||||||
}
|
}
|
||||||
|
@ -543,11 +546,11 @@ public class ac {
|
||||||
*
|
*
|
||||||
* DiskCopy 4.2 image - convert it to a ProDOS image
|
* DiskCopy 4.2 image - convert it to a ProDOS image
|
||||||
* SDK disk image - unpack it to a disk 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)
|
static void convert(String shrinkName, String imageName, int imageSize)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Disk disk = new Disk(shrinkName);
|
Disk disk = new Disk(shrinkName, imageSize);
|
||||||
disk.setFilename(imageName);
|
disk.setFilename(imageName);
|
||||||
disk.save();
|
disk.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,21 @@ public class Utilities
|
||||||
* the file has some malformed-ness about it
|
* the file has some malformed-ness about it
|
||||||
*/
|
*/
|
||||||
public static byte[] unpackSHKFile(String fileName) throws IOException
|
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();
|
TextBundle textBundle = StorageBundle.getInstance();
|
||||||
byte dmgBuffer[] = null;
|
byte dmgBuffer[] = null;
|
||||||
|
@ -67,6 +82,8 @@ public class Utilities
|
||||||
NuFileArchive a = new NuFileArchive(is);
|
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?
|
// 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());
|
int newDiskSize = Disk.sizeToFit(a.getArchiveSize());
|
||||||
|
if (startBlocks > 0)
|
||||||
|
newDiskSize = startBlocks*512;
|
||||||
ByteArrayImageLayout layout = new ByteArrayImageLayout(newDiskSize);
|
ByteArrayImageLayout layout = new ByteArrayImageLayout(newDiskSize);
|
||||||
ImageOrder imageOrder = new ProdosOrder(layout);
|
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.
|
// 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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.out.println(ex);
|
throw new IOException(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
@ -148,7 +165,7 @@ public class Utilities
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.out.println(ex);
|
throw new IOException(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dmgBuffer != null)
|
if (dmgBuffer != null)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user