diff --git a/build/build-testacant.xml b/build/build-testacant.xml index 29ed366..ae9e730 100644 --- a/build/build-testacant.xml +++ b/build/build-testacant.xml @@ -41,9 +41,9 @@ - + - + @@ -81,10 +81,8 @@ - - + + diff --git a/src/com/webcodepro/applecommander/storage/Disk.java b/src/com/webcodepro/applecommander/storage/Disk.java index 9128f4f..081f0ef 100644 --- a/src/com/webcodepro/applecommander/storage/Disk.java +++ b/src/com/webcodepro/applecommander/storage/Disk.java @@ -94,6 +94,7 @@ public class Disk { private TextBundle textBundle = StorageBundle.getInstance(); private String filename; private boolean newImage = false; + private boolean isDC42 = false; private ByteArrayImageLayout diskImageManager; private ImageOrder imageOrder = null; @@ -196,15 +197,13 @@ public class Disk { diskImage = diskImageByteArray.toByteArray(); } int offset = 0; - boolean is2img = false, isDC42 = false; + boolean is2img = false; /* Does it have the 2IMG header? */ - if ((diskImage[00] == 0x32) && (diskImage[01] == 0x49) && (diskImage[02] == 0x4D) && (diskImage[03]) == 0x47) { + if ((diskImage[0] == 0x32) && (diskImage[1] == 0x49) && (diskImage[2] == 0x4D) && (diskImage[3]) == 0x47) { is2img = true; - offset = UniversalDiskImageLayout.OFFSET; } /* Does it have the DiskCopy 4.2 header? */ - else if (((diskImage[0x52] == 0x01) && (diskImage[0x53] == 0x00)) && - ((diskImage[0x51] == 0x02) || (diskImage[0x51] == 0x22) || (diskImage[0x51] == 0x24))) { + else if (Disk.isDC42(diskImage)) { isDC42 = true; offset = 84; long end = AppleUtil.getLongValue(diskImage,0x40); @@ -214,9 +213,13 @@ public class Disk { diskImageManager = new ByteArrayImageLayout(diskImageDC42); } else - throw new IllegalArgumentException(textBundle.get("Disk.ResizeDiskError")); // FIXME - need a better explanation of this + throw new IllegalArgumentException(textBundle.get("CommandLineDC42Bad")); //$NON-NLS-1$ } - if (is2img == true || diskImage.length == APPLE_800KB_DISK + offset || diskImage.length == APPLE_5MB_HARDDISK + offset || diskImage.length == APPLE_10MB_HARDDISK + offset || diskImage.length == APPLE_20MB_HARDDISK + offset || diskImage.length == APPLE_32MB_HARDDISK + offset) { + 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); } else if (isDC42) { diskImageManager = new ByteArrayImageLayout(diskImageDC42); @@ -360,8 +363,8 @@ public class Disk { } /** - * Returns the diskImage. - * @return byte[] + * Returns the diskImageManager. + * @return ByteArrayImageLayout diskImageManager The disk Image Manager of this disk */ public ByteArrayImageLayout getDiskImageManager() { if (imageOrder != null) { @@ -748,7 +751,21 @@ public class Disk { && vtoc[0x01] == 7 // expect catalog to start on sector 7 && vtoc[0x0f] == -115; // expect 0x8d's every 16 bytes } - + + /** + * Indicates if a given byte sequence is likely to be a DiskCopy 42 stream. + * + * @return boolean liklihood it is a DC42 stream + */ + private static boolean isDC42(byte[] buffer) { + boolean truth = ((buffer[0x52] == 0x01) && (buffer[0x53] == 0x00)) && + ((buffer[0x51] == 0x02) || (buffer[0x51] == 0x22) || (buffer[0x51] == 0x24)); + return (((buffer[0x52] == 0x01) && (buffer[0x53] == 0x00)) && + ((buffer[0x51] == 0x02) || (buffer[0x51] == 0x22) || (buffer[0x51] == 0x24))); + } + public boolean isDC42() { + return isDC42; + } /** * Indicates if the disk has changed. Triggered when data is * written and cleared when data is saved. @@ -766,7 +783,7 @@ public class Disk { } /** - * Answer with the phyiscal ordering of the disk. + * Answer with the physical ordering of the disk. */ public ImageOrder getImageOrder() { return imageOrder; diff --git a/src/com/webcodepro/applecommander/ui/AntTask.java b/src/com/webcodepro/applecommander/ui/AntTask.java index cdd84ed..d26a6c4 100644 --- a/src/com/webcodepro/applecommander/ui/AntTask.java +++ b/src/com/webcodepro/applecommander/ui/AntTask.java @@ -45,7 +45,7 @@ public class AntTask extends Task * dos140: * pro140/pro800: * pas140/pas800: - * unshrink: + * convert: */ if (_command.equals("i")) { @@ -81,7 +81,9 @@ public class AntTask extends Task try { if (_command.equals("p")) + { com.webcodepro.applecommander.ui.ac.putFile(_input, _imageName, _fileName, _type, _address); + } else com.webcodepro.applecommander.ui.ac.putCC65(_input, _imageName, _fileName, _type); } @@ -220,11 +222,11 @@ public class AntTask extends Task System.out.println(io.getMessage()); } } - else if (_command.equals("unshrink")) + else if (_command.equals("convert")) { try { - com.webcodepro.applecommander.ui.ac.unshrink(_fileName, _imageName); + com.webcodepro.applecommander.ui.ac.convert(_fileName, _imageName); } catch (IOException io) { diff --git a/src/com/webcodepro/applecommander/ui/UiBundle.properties b/src/com/webcodepro/applecommander/ui/UiBundle.properties index 3d5c9ca..be7899e 100644 --- a/src/com/webcodepro/applecommander/ui/UiBundle.properties +++ b/src/com/webcodepro/applecommander/ui/UiBundle.properties @@ -102,8 +102,9 @@ CreateDirectoryMenuItem=Create Directory... CommandLineErrorMessage = Error: {0} CommandLineNoMatchMessage = {0}: No match. CommandLineStatus = {0} format; {1} bytes free; {2} bytes used. -CommandLineHelp = AppleCommander command line options [{0}]:\n-i [] display information about image(s).\n-ls [] list brief directory of image(s).\n-l [] list directory of image(s).\n-ll [] list detailed directory of image(s).\n-e export file from image to stdout.\n-x [] extract all files from image to directory.\n-g get raw file from image to stdout.\n-p [[$|0x]] put stdin\n in filename on image, using file type and address [0x2000].\n-d delete file from image.\n-k lock file on image.\n-u unlock file on image.\n-n change volume name (ProDOS or Pascal).\n-cc65 put stdin with cc65 header\n in filename on image, using file type and address from header.\n-geos interpret stdin as a GEOS conversion file and\n place it on image (ProDOS only).\n-dos140 create a 140K DOS 3.3 image.\n-pro140 create a 140K ProDOS image.\n-pro800 create an 800K ProDOS image.\n-pas140 create a 140K Pascal image.\n-pas800 create an 800K Pascal image.\n-unshrink uncompress a ShrinkIt disk image\n into a normal disk image. -CommandLineSDKReadOnly = SDK files are read-only +CommandLineHelp = AppleCommander command line options [{0}]:\n-i [] display information about image(s).\n-ls [] list brief directory of image(s).\n-l [] list directory of image(s).\n-ll [] list detailed directory of image(s).\n-e export file from image to stdout.\n-x [] extract all files from image to directory.\n-g get raw file from image to stdout.\n-p [[$|0x]] put stdin\n in filename on image, using file type and address [0x2000].\n-d delete file from image.\n-k lock file on image.\n-u unlock file on image.\n-n change volume name (ProDOS or Pascal).\n-cc65 put stdin with cc65 header\n in filename on image, using file type and address from header.\n-geos interpret stdin as a GEOS conversion file and\n place it on image (ProDOS only).\n-dos140 create a 140K DOS 3.3 image.\n-pro140 create a 140K ProDOS image.\n-pro800 create an 800K ProDOS image.\n-pas140 create a 140K Pascal image.\n-pas800 create an 800K Pascal image.\n-convert uncompress a ShrinkIt file or disk image\n or convert a DiskCopy 4.2 image into a ProDOS disk image. +CommandLineSDKReadOnly = SDK, SHK, and DC42 files are read-only. Use the convert option on them first. +CommandLineDC42Bad = Unable to interpret this DiskCopy 42 image. # UserPreferences UserPreferencesComment = AppleCommander user preferences diff --git a/src/com/webcodepro/applecommander/ui/ac.java b/src/com/webcodepro/applecommander/ui/ac.java index 59ae2df..5e00900 100644 --- a/src/com/webcodepro/applecommander/ui/ac.java +++ b/src/com/webcodepro/applecommander/ui/ac.java @@ -77,8 +77,8 @@ import com.webcodepro.applecommander.util.TextBundle; * -pro800 <imagename> <volname> create an 800K ProDOS image. * -pas140 <imagename> <volname> create a 140K Pascal image. * -pas800 <imagename> <volname> create an 800K Pascal image. - * -unshrink <shrinksdk> <imagename> uncompress a ShrinkIt disk image - * into a normal disk image. + * -convert <filename> <imagename> uncompress a ShrinkIt file or disk image + * or convert a DiskCopy 4.2 image into a ProDOS disk image. * * * @author John B. Matthews @@ -129,8 +129,8 @@ public class ac { createProDisk(args[1], args[2], Disk.APPLE_140KB_DISK); } else if ("-pro800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ createProDisk(args[1], args[2], Disk.APPLE_800KB_DISK); - } else if ("-unshrink".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ - unshrink(args[1], args[2]); + } else if ("-convert".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ + convert(args[1], args[2]); } else { help(); } @@ -176,7 +176,7 @@ public class ac { } /** - * Put <stdin> into the file named fileName on the disk named imageName; + * Put <stdin>. into the file named fileName on the disk named imageName; * Note: only volume level supported; input size unlimited. */ static void putFile(String imageName, Name name, String fileType, @@ -189,9 +189,11 @@ public class ac { buf.write(inb, 0, byteCount); } Disk disk = new Disk(imageName); - if (!disk.isSDK()) { - FormattedDisk[] formattedDisks = disk.getFormattedDisks(); - FormattedDisk formattedDisk = formattedDisks[0]; + FormattedDisk[] formattedDisks = disk.getFormattedDisks(); + if (formattedDisks == null) + System.out.println("Dude, formattedDisks is null!"); + FormattedDisk formattedDisk = formattedDisks[0]; + if (!disk.isSDK() && !disk.isDC42()) { FileEntry entry = name.createEntry(formattedDisk); if (entry != null) { entry.setFiletype(fileType); @@ -251,7 +253,7 @@ public class ac { throws IOException { Disk disk = new Disk(imageName); Name name = new Name(fileName); - if (!disk.isSDK()) { + if (!disk.isSDK() && !disk.isDC42()) { FormattedDisk[] formattedDisks = disk.getFormattedDisks(); for (int i = 0; i < formattedDisks.length; i++) { FormattedDisk formattedDisk = formattedDisks[i]; @@ -456,7 +458,7 @@ public class ac { static void setFileLocked(String imageName, Name name, boolean lockState) throws IOException { Disk disk = new Disk(imageName); - if (!disk.isSDK()) { + if (!disk.isSDK() && !disk.isDC42()) { FormattedDisk[] formattedDisks = disk.getFormattedDisks(); for (int i = 0; i < formattedDisks.length; i++) { FormattedDisk formattedDisk = formattedDisks[i]; @@ -481,7 +483,7 @@ public class ac { public static void setDiskName(String imageName, String volName) throws IOException { Disk disk = new Disk(imageName); - if (!disk.isSDK()) { + if (!disk.isSDK() && !disk.isDC42()) { FormattedDisk[] formattedDisks = disk.getFormattedDisks(); FormattedDisk formattedDisk = formattedDisks[0]; formattedDisk.setDiskName(volName); @@ -525,23 +527,25 @@ public class ac { } /** - * Unshrink the ShrinkIt data depending on what kind it is: + * Unshrink or otherwise interpret incoming data depending on what kind it is: * + * 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 */ - static void unshrink(String shrinkName, String imageName) + static void convert(String shrinkName, String imageName) throws IOException { - unshrink(shrinkName, imageName, 0); + convert(shrinkName, imageName, 0); } /** - * Unshrink the ShrinkIt data depending on what kind it is: + * Unshrink or otherwise interpret incoming data depending on what kind it is: * + * 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 of requested size + * ShrinkIt file bundle [future] - unpack files onto a disk image sized to fit */ - static void unshrink(String shrinkName, String imageName, int imageSize) + static void convert(String shrinkName, String imageName, int imageSize) throws IOException { Disk disk = new Disk(shrinkName); disk.setFilename(imageName);