Protect ourselves from writing SDKs back out

Add the ability to uncompress SDK
This commit is contained in:
2012-07-23 21:20:49 +00:00
parent 4ab21617fa
commit a79df8f3bc
2 changed files with 80 additions and 35 deletions

View File

@ -102,7 +102,8 @@ 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 <imagename> [<imagename>] display information about image(s).\n-ls <imagename> [<imagename>] list brief directory of image(s).\n-l <imagename> [<imagename>] list directory of image(s).\n-ll <imagename> [<imagename>] list detailed directory of image(s).\n-e <imagename> <filename> export file from image to stdout.\n-x <imagename> [<directory>] extract all files from image to directory.\n-g <imagename> <filename> get raw file from image to stdout.\n-p <imagename> <filename> <type> [[$|0x]<addr>] put stdin\n in filename on image, using file type and address [0x2000].\n-d <imagename> <filename> delete file from image.\n-k <imagename> <filename> lock file on image.\n-u <imagename> <filename> unlock file on image.\n-n <imagename> <volname> change volume name (ProDOS or Pascal).\n-cc65 <imagename> <filename> <type> put stdin with cc65 header\n in filename on image, using file type and address from header.\n-geos <imagename> interpret stdin as a GEOS conversion file and\n place it on image (ProDOS only).\n-dos140 <imagename> create a 140K DOS 3.3 image.\n-pro140 <imagename> <volname> create a 140K ProDOS image.\n-pro800 <imagename> <volname> create an 800K ProDOS image.\n-pas140 <imagename> <volname> create a 140K Pascal image.\n-pas800 <imagename> <volname> create an 800K Pascal image.
CommandLineHelp = AppleCommander command line options [{0}]:\n-i <imagename> [<imagename>] display information about image(s).\n-ls <imagename> [<imagename>] list brief directory of image(s).\n-l <imagename> [<imagename>] list directory of image(s).\n-ll <imagename> [<imagename>] list detailed directory of image(s).\n-e <imagename> <filename> export file from image to stdout.\n-x <imagename> [<directory>] extract all files from image to directory.\n-g <imagename> <filename> get raw file from image to stdout.\n-p <imagename> <filename> <type> [[$|0x]<addr>] put stdin\n in filename on image, using file type and address [0x2000].\n-d <imagename> <filename> delete file from image.\n-k <imagename> <filename> lock file on image.\n-u <imagename> <filename> unlock file on image.\n-n <imagename> <volname> change volume name (ProDOS or Pascal).\n-cc65 <imagename> <filename> <type> put stdin with cc65 header\n in filename on image, using file type and address from header.\n-geos <imagename> interpret stdin as a GEOS conversion file and\n place it on image (ProDOS only).\n-dos140 <imagename> create a 140K DOS 3.3 image.\n-pro140 <imagename> <volname> create a 140K ProDOS image.\n-pro800 <imagename> <volname> create an 800K ProDOS image.\n-pas140 <imagename> <volname> create a 140K Pascal image.\n-pas800 <imagename> <volname> create an 800K Pascal image.\n-unshrink <shrinksdk> <imagename> uncompress a ShrinkIt disk image\n into a normal disk image.
CommandLineSDKReadOnly = SDK files are read-only
# UserPreferences
UserPreferencesComment = AppleCommander user preferences

View File

@ -77,6 +77,8 @@ import com.webcodepro.applecommander.util.TextBundle;
* -pro800 &lt;imagename&gt; &lt;volname&gt; create an 800K ProDOS image.
* -pas140 &lt;imagename&gt; &lt;volname&gt; create a 140K Pascal image.
* -pas800 &lt;imagename&gt; &lt;volname&gt; create an 800K Pascal image.
* -unshrink &lt;shrinksdk&gt; &lt;imagename&gt; uncompress a ShrinkIt disk image
* into a normal disk image.
* </pre>
*
* @author John B. Matthews
@ -127,6 +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 {
help();
}
@ -185,18 +189,22 @@ public class ac {
buf.write(inb, 0, byteCount);
}
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
FileEntry entry = name.createEntry(formattedDisk);
if (entry != null) {
entry.setFiletype(fileType);
entry.setFilename(name.name);
entry.setFileData(buf.toByteArray());
if (entry.needsAddress()) {
entry.setAddress(stringToInt(address));
if (!disk.isSDK()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
FileEntry entry = name.createEntry(formattedDisk);
if (entry != null) {
entry.setFiletype(fileType);
entry.setFilename(name.name);
entry.setFileData(buf.toByteArray());
if (entry.needsAddress()) {
entry.setAddress(stringToInt(address));
}
formattedDisk.save();
}
formattedDisk.save();
}
else
throw new IOException(textBundle.get("CommandLineSDKReadOnly"));
}
/**
@ -242,18 +250,22 @@ public class ac {
static void deleteFile(String imageName, Name name)
throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
FileEntry entry = name.getEntry(formattedDisk);
if (entry != null) {
entry.delete();
disk.save();
} else {
System.err.println(textBundle.format(
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
if (!disk.isSDK()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
FileEntry entry = name.getEntry(formattedDisk);
if (entry != null) {
entry.delete();
disk.save();
} else {
System.err.println(textBundle.format(
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
}
}
}
else
throw new IOException(textBundle.get("CommandLineSDKReadOnly"));
}
/**
@ -431,18 +443,22 @@ public class ac {
static void setFileLocked(String imageName, Name name,
boolean lockState) throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
FileEntry entry = name.getEntry(formattedDisk);
if (entry != null) {
entry.setLocked(lockState);
disk.save();
} else {
System.err.println(textBundle.format(
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
if (!disk.isSDK()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
FileEntry entry = name.getEntry(formattedDisk);
if (entry != null) {
entry.setLocked(lockState);
disk.save();
} else {
System.err.println(textBundle.format(
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
}
}
}
else
throw new IOException(textBundle.get("CommandLineSDKReadOnly"));
}
/**
@ -452,10 +468,14 @@ public class ac {
public static void setDiskName(String imageName, String volName)
throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
formattedDisk.setDiskName(volName);
formattedDisks[0].save();
if (!disk.isSDK()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
formattedDisk.setDiskName(volName);
formattedDisks[0].save();
}
else
throw new IOException(textBundle.get("CommandLineSDKReadOnly"));
}
/**
@ -491,6 +511,30 @@ public class ac {
disks[0].save();
}
/**
* Unshrink the ShrinkIt data depending on what kind it is:
*
* 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)
throws IOException {
unshrink(shrinkName, imageName, 0);
}
/**
* Unshrink the ShrinkIt data depending on what kind it is:
*
* SDK disk image - unpack it to a disk image
* ShrinkIt file bundle [future] - unpack files onto a disk image of reqeusted size
*/
static void unshrink(String shrinkName, String imageName, int imageSize)
throws IOException {
Disk disk = new Disk(shrinkName);
disk.setFilename(imageName);
disk.save();
}
static int stringToInt(String s) {
int i = 0;
try {