Continue listing after encountering unreadable disk .

This commit is contained in:
John B. Matthews 2008-06-08 21:40:06 +00:00
parent 4130b3626d
commit 2658e3eb82

View File

@ -46,30 +46,32 @@ import com.webcodepro.applecommander.util.AppleUtil;
import com.webcodepro.applecommander.util.TextBundle;
/**
* ac provides a command line interface to key AppleCommander functions.
* Text similar to this is produced in response to the -h option.
* ac provides a command line interface to key AppleCommander functions. Text
* similar to this is produced in response to the -h option.
*
* <pre>
* CommandLineHelp = AppleCommander command line options [{0}]:
* -i &lt;imagename> [&lt;imagename>] display information about image(s).
* -ls &lt;imagename> [&lt;imagename>] list brief directory of image(s).
* -l &lt;imagename> [&lt;imagename>] list directory of image(s).
* -ll &lt;imagename> [&lt;imagename>] list detailed directory of image(s).
* -e &lt;imagename> &lt;filename> export file from image to stdout.
* -g &lt;imagename> &lt;filename> get raw file from image to stdout.
* -p &lt;imagename> &lt;filename> &lt;type> [[$|0x]&lt;addr>] put stdin
* -i &lt;imagename&gt; [&lt;imagename&gt;] display information about image(s).
* -ls &lt;imagename&gt; [&lt;imagename&gt;] list brief directory of image(s).
* -l &lt;imagename&gt; [&lt;imagename&gt;] list directory of image(s).
* -ll &lt;imagename&gt; [&lt;imagename&gt;] list detailed directory of image(s).
* -e &lt;imagename&gt; &lt;filename&gt; export file from image to stdout.
* -g &lt;imagename&gt; &lt;filename&gt; get raw file from image to stdout.
* -p &lt;imagename&gt; &lt;filename&gt; &lt;type&gt; [[$|0x]&lt;addr&gt;] put stdin
* in filename on image, using file type and address [0x2000].
* -d &lt;imagename> &lt;filename> delete file from image.
* -k &lt;imagename> &lt;filename> lock file on image.
* -u &lt;imagename> &lt;filename> unlock file on image.
* -n &lt;imagename> &lt;volname> change volume name (ProDOS or Pascal).
* -cc65 &lt;imagename> &lt;filename> &lt;type> put stdin with cc65 header
* -d &lt;imagename&gt; &lt;filename&gt; delete file from image.
* -k &lt;imagename&gt; &lt;filename&gt; lock file on image.
* -u &lt;imagename&gt; &lt;filename&gt; unlock file on image.
* -n &lt;imagename&gt; &lt;volname&gt; change volume name (ProDOS or Pascal).
* -cc65 &lt;imagename&gt; &lt;filename&gt; &lt;type&gt; put stdin with cc65 header
* in filename on image, using file type and address from header.
* -dos140 &lt;imagename> create a 140K DOS 3.3 image.
* -pro140 &lt;imagename> &lt;volname> create a 140K ProDOS image.
* -pro800 &lt;imagename> &lt;volname> create an 800K ProDOS image.
* -pas140 &lt;imagename> &lt;volname> create a 140K Pascal image.
* -pas800 &lt;imagename> &lt;volname> create an 800K Pascal image.
* -dos140 &lt;imagename&gt; create a 140K DOS 3.3 image.
* -pro140 &lt;imagename&gt; &lt;volname&gt; create a 140K ProDOS image.
* -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.
* </pre>
*
* @author John B. Matthews
*/
public class ac {
@ -129,8 +131,8 @@ public class ac {
* Put &lt;stdin> into the file named fileName on the disk named imageName;
* Note: only volume level supported; input size unlimited.
*/
static void putFile(String imageName, String fileName, String fileType, String address)
throws IOException, DiskFullException {
static void putFile(String imageName, String fileName, String fileType,
String address) throws IOException, DiskFullException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
byte[] inb = new byte[1024];
@ -168,7 +170,8 @@ public class ac {
/**
* Delete the file named fileName from the disk named imageName.
*/
static void deleteFile(String imageName, String fileName) throws IOException {
static void deleteFile(String imageName, String fileName)
throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
@ -186,10 +189,11 @@ public class ac {
}
/**
* Get the file named filename from the disk named imageName;
* the file is filtered according to its type and sent to &lt;stdout>.
* Get the file named filename from the disk named imageName; the file is
* filtered according to its type and sent to &lt;stdout>.
*/
static void getFile(String imageName, String fileName, boolean filter) throws IOException {
static void getFile(String imageName, String fileName, boolean filter)
throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
@ -215,9 +219,9 @@ public class ac {
}
/**
* 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 file with the given filename.
* 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
* file with the given filename.
*/
static FileEntry getEntry(List files, String fileName) {
FileEntry theEntry = null;
@ -225,14 +229,14 @@ public class ac {
for (int i = 0; i < files.size(); i++) {
FileEntry entry = (FileEntry) files.get(i);
String entryName = entry.getFilename();
if (!entry.isDeleted() &&
fileName.equalsIgnoreCase(entryName)) {
if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) {
return entry;
}
if (entry.isDirectory()) {
theEntry = getEntry(((DirectoryEntry) entry).
getFiles(), fileName);
if (theEntry != null) {return theEntry;}
theEntry = getEntry(((DirectoryEntry) entry).getFiles(), fileName);
if (theEntry != null) {
return theEntry;
}
}
}
}
@ -244,6 +248,7 @@ public class ac {
*/
static void showDirectory(String[] args, int display) throws IOException {
for (int d = 1; d < args.length; d++) {
try {
Disk disk = new Disk(args[d]);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
@ -254,22 +259,23 @@ public class ac {
if (files != null) {
showFiles(files, "", display); //$NON-NLS-1$
}
System.out.println(textBundle.format(
"CommandLineStatus", //$NON-NLS-1$
new Object[] {
formattedDisk.getFormat(),
System.out.println(textBundle.format("CommandLineStatus", //$NON-NLS-1$
new Object[] { formattedDisk.getFormat(),
new Integer(formattedDisk.getFreeSpace()),
new Integer(formattedDisk.getUsedSpace())
}));
new Integer(formattedDisk.getUsedSpace()) }));
System.out.println();
}
} catch (RuntimeException e) {
System.out.println(args[d] + ": " + e.getMessage()); //$NON-NLS-1$
System.out.println();
}
}
}
/**
* Recursive routine to display directory entries.
* In the instance of a system with directories (e.g. ProDOS),
* this really returns the first file with the given filename.
* Recursive routine to display directory entries. In the instance of a
* system with directories (e.g. ProDOS), this really returns the first file
* with the given filename.
*/
static void showFiles(List files, String indent, int display) {
for (int i = 0; i < files.size(); i++) {
@ -284,7 +290,7 @@ public class ac {
System.out.println();
}
if (entry.isDirectory()) {
showFiles(((DirectoryEntry)entry).getFiles(),
showFiles(((DirectoryEntry) entry).getFiles(),
indent + " ", display); //$NON-NLS-1$
}
}
@ -299,7 +305,8 @@ public class ac {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
Iterator iterator = formattedDisk.getDiskInformation().iterator();
Iterator iterator = formattedDisk.getDiskInformation()
.iterator();
while (iterator.hasNext()) {
DiskInformation diskinfo = (DiskInformation) iterator.next();
System.out.println(diskinfo.getLabel() + ": " + diskinfo.getValue());
@ -313,8 +320,8 @@ public class ac {
* Set the lockState of the file named fileName on the disk named imageName.
* Proposed by David Schmidt.
*/
static void setFileLocked(String imageName, String fileName, boolean lockState)
throws IOException {
static void setFileLocked(String imageName, String fileName,
boolean lockState) throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
@ -332,9 +339,8 @@ public class ac {
}
/**
* Set the volume name for a given disk image.
* Only effective for ProDOS or Pascal disks; others ignored.
* Proposed by David Schmidt.
* Set the volume name for a given disk image. Only effective for ProDOS or
* Pascal disks; others ignored. Proposed by David Schmidt.
*/
static void setDiskName(String imageName, String volName)
throws IOException {
@ -352,8 +358,7 @@ public class ac {
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new DosOrder(layout);
FormattedDisk[] disks =
DosFormatDisk.create(fileName, imageOrder);
FormattedDisk[] disks = DosFormatDisk.create(fileName, imageOrder);
disks[0].save();
}
@ -364,8 +369,7 @@ public class ac {
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new ProdosOrder(layout);
FormattedDisk[] disks =
PascalFormatDisk.create(fileName, volName, imageOrder);
FormattedDisk[] disks = PascalFormatDisk.create(fileName, volName, imageOrder);
disks[0].save();
}
@ -376,8 +380,7 @@ public class ac {
throws IOException {
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
ImageOrder imageOrder = new ProdosOrder(layout);
FormattedDisk[] disks =
ProdosFormatDisk.create(fileName, volName, imageOrder);
FormattedDisk[] disks = ProdosFormatDisk.create(fileName, volName, imageOrder);
disks[0].save();
}
@ -399,7 +402,8 @@ public class ac {
}
static void help() {
System.err.println(textBundle.format("CommandLineHelp", AppleCommander.VERSION)); //$NON-NLS-1$
System.err.println(textBundle.format(
"CommandLineHelp", AppleCommander.VERSION)); //$NON-NLS-1$
}
}