mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-02-07 12:30:33 +00:00
Add the ability to extract everything from an image using its preferred export method.
This commit is contained in:
parent
1b50de52d3
commit
4358c86618
@ -22,7 +22,10 @@
|
||||
package com.webcodepro.applecommander.ui;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -56,6 +59,7 @@ import com.webcodepro.applecommander.util.TextBundle;
|
||||
* -l <imagename> [<imagename>] list directory of image(s).
|
||||
* -ll <imagename> [<imagename>] list detailed directory of image(s).
|
||||
* -e <imagename> <filename> export file from image to stdout.
|
||||
* -x <imagename> [<directory>] export all files from image to directory.
|
||||
* -g <imagename> <filename> get raw file from image to stdout.
|
||||
* -p <imagename> <filename> <type> [[$|0x]<addr>] put stdin
|
||||
* in filename on image, using file type and address [0x2000].
|
||||
@ -91,6 +95,8 @@ public class ac {
|
||||
showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL);
|
||||
} else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
||||
getFile(args[1], args[2], true);
|
||||
} else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
||||
getFiles(args[1], (args.length > 2 ? args[2] : ""));
|
||||
} else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
||||
getFile(args[1], args[2], false);
|
||||
} else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
||||
@ -218,6 +224,38 @@ public class ac {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract all files in the image according to their respective filetype.
|
||||
*/
|
||||
static void getFiles(String imageName, String directory) throws IOException {
|
||||
Disk disk = new Disk(imageName);
|
||||
if (directory.length() > 0) {
|
||||
// Add a final directory separator if the user didn't supply one
|
||||
if (!directory.endsWith(System.getProperty("file.separator")))
|
||||
directory = directory + System.getProperty("file.separator");
|
||||
}
|
||||
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
||||
for (int i = 0; i < formattedDisks.length; i++) {
|
||||
FormattedDisk formattedDisk = formattedDisks[i];
|
||||
List files = formattedDisk.getFiles();
|
||||
Iterator it = files.iterator();
|
||||
while (it.hasNext()) {
|
||||
FileEntry entry = (FileEntry) it.next();
|
||||
if ((entry != null) && (!entry.isDeleted())) {
|
||||
FileFilter ff = entry.getSuggestedFilter();
|
||||
if (ff instanceof BinaryFileFilter)
|
||||
ff = new HexDumpFileFilter();
|
||||
byte[] buf = ff.filter(entry);
|
||||
String filename = ff.getSuggestedFileName(entry);
|
||||
File file = new File(directory + filename);
|
||||
OutputStream output = new FileOutputStream(file);
|
||||
output.write(buf, 0, buf.length);
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive routine to locate a specific file by filename; In the instance
|
||||
* of a system with directories (e.g. ProDOS), this really returns the first
|
||||
|
Loading…
x
Reference in New Issue
Block a user