Revising the DiskException handling. I was wrongly handling it as a user warning on some places where this is not viable (as a Ant Task!!).

This commit is contained in:
Lisias 2018-01-08 09:21:45 -02:00
parent 144841a296
commit d2199f0792
4 changed files with 24 additions and 48 deletions

View File

@ -369,10 +369,10 @@ public class Disk {
/** /**
* Determine type of disk, and return the appropriate * Determine type of disk, and return the appropriate
* FormattedDisk object. Returns null if none are * FormattedDisk object. Throws an Exception if none is recognized.
* recognized. * @throws DiskUnrecognizedException
*/ */
public FormattedDisk[] getFormattedDisks() { public FormattedDisk[] getFormattedDisks() throws DiskUnrecognizedException {
if (isProdosFormat()) { if (isProdosFormat()) {
return new FormattedDisk[] return new FormattedDisk[]
{ new ProdosFormatDisk(filename, imageOrder) }; { new ProdosFormatDisk(filename, imageOrder) };
@ -407,7 +407,7 @@ public class Disk {
return new FormattedDisk[] return new FormattedDisk[]
{ new GutenbergFormatDisk(filename, imageOrder) }; { new GutenbergFormatDisk(filename, imageOrder) };
} }
return null; throw new DiskUnrecognizedException(filename);
} }
/** /**

View File

@ -267,14 +267,8 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
* Locate a specific file by filename. * Locate a specific file by filename.
* Returns a null if specific filename is not located. * Returns a null if specific filename is not located.
*/ */
public FileEntry getFile(String filename) { public FileEntry getFile(String filename) throws DiskException {
List files; List files = getFiles();
try {
files = getFiles();
} catch (DiskException e) {
// FIXME how to warn the User about this?
files = new ArrayList<>();
}
return getFile(files, filename.trim()); return getFile(files, filename.trim());
} }
@ -283,19 +277,15 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
* Note that in the instance of a system with directories (ie, ProDOS), * Note that in the instance of a system with directories (ie, ProDOS),
* this really returns the first file with the given filename. * this really returns the first file with the given filename.
*/ */
protected FileEntry getFile(List files, String filename) { protected FileEntry getFile(List files, String filename) throws DiskException {
FileEntry theFileEntry = null; FileEntry theFileEntry = null;
if (files != null) { if (files != null) {
for (int i=0; i<files.size(); i++) { for (int i=0; i<files.size(); i++) {
FileEntry entry = (FileEntry) files.get(i); FileEntry entry = (FileEntry) files.get(i);
if (entry.isDirectory()) { if (entry.isDirectory()) {
try { theFileEntry = getFile(
theFileEntry = getFile( ((DirectoryEntry)entry).getFiles(), filename);
((DirectoryEntry)entry).getFiles(), filename); if (theFileEntry != null) break;
if (theFileEntry != null) break;
} catch (DiskException e) {
// FIXME how to warn the User about this?
}
} }
String otherFilename = entry.getFilename(); String otherFilename = entry.getFilename();
if (otherFilename != null) otherFilename = otherFilename.trim(); if (otherFilename != null) otherFilename = otherFilename.trim();

View File

@ -122,7 +122,7 @@ public class AntTask extends Task
{ {
com.webcodepro.applecommander.ui.ac.setDiskName(_imageName, _volName); com.webcodepro.applecommander.ui.ac.setDiskName(_imageName, _volName);
} }
catch (IOException io) catch (IOException|DiskException io)
{ {
if (_failonerror) if (_failonerror)
throw new BuildException(io); throw new BuildException(io);
@ -221,7 +221,7 @@ public class AntTask extends Task
{ {
com.webcodepro.applecommander.ui.ac.getFiles(_imageName, _outputPath); com.webcodepro.applecommander.ui.ac.getFiles(_imageName, _outputPath);
} }
catch (IOException io) catch (IOException|DiskException io)
{ {
if (_failonerror) if (_failonerror)
throw new BuildException(io); throw new BuildException(io);

View File

@ -320,7 +320,7 @@ public class ac {
/** /**
* Extract all files in the image according to their respective filetype. * Extract all files in the image according to their respective filetype.
*/ */
static void getFiles(String imageName, String directory) throws IOException { static void getFiles(String imageName, String directory) throws IOException, DiskException {
Disk disk = new Disk(imageName); Disk disk = new Disk(imageName);
if ((directory != null) && (directory.length() > 0)) { if ((directory != null) && (directory.length() > 0)) {
// Add a final directory separator if the user didn't supply one // Add a final directory separator if the user didn't supply one
@ -331,19 +331,15 @@ public class ac {
} }
FormattedDisk[] formattedDisks = disk.getFormattedDisks(); FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) { for (int i = 0; i < formattedDisks.length; i++) {
try { FormattedDisk formattedDisk = formattedDisks[i];
FormattedDisk formattedDisk = formattedDisks[i]; writeFiles(formattedDisk.getFiles(), directory);
writeFiles(formattedDisk.getFiles(), directory);
} catch (DiskException e) {
// FIXME How to warn user about the problem?
}
} }
} }
/** /**
* Recursive routine to write directory and file entries. * Recursive routine to write directory and file entries.
*/ */
static void writeFiles(List files, String directory) throws IOException { static void writeFiles(List files, String directory) throws IOException, DiskException {
Iterator it = files.iterator(); Iterator it = files.iterator();
while (it.hasNext()) { while (it.hasNext()) {
FileEntry entry = (FileEntry) it.next(); FileEntry entry = (FileEntry) it.next();
@ -360,11 +356,7 @@ public class ac {
output.write(buf, 0, buf.length); output.write(buf, 0, buf.length);
output.close(); output.close();
} else if (entry.isDirectory()) { } else if (entry.isDirectory()) {
try { writeFiles(((DirectoryEntry) entry).getFiles(),directory+entry.getFilename()+File.separator);
writeFiles(((DirectoryEntry) entry).getFiles(),directory+entry.getFilename()+File.separator);
} catch (DiskException e) {
// FIXME How to warn user about the problem?
}
} }
} }
} }
@ -375,7 +367,7 @@ public class ac {
* file with the given filename. * file with the given filename.
* @deprecated * @deprecated
*/ */
static FileEntry getEntry(List files, String fileName) { static FileEntry getEntry(List files, String fileName) throws DiskException {
FileEntry entry = null; FileEntry entry = null;
if (files != null) { if (files != null) {
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
@ -384,13 +376,11 @@ public class ac {
if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) { if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) {
return entry; return entry;
} }
if (entry.isDirectory()) try { if (entry.isDirectory()) {
entry = getEntry(((DirectoryEntry) entry).getFiles(), fileName); entry = getEntry(((DirectoryEntry) entry).getFiles(), fileName);
if (entry != null) { if (entry != null) {
return entry; return entry;
} }
} catch (DiskException e) {
// FIXME How to warn user about the problem?
} }
} }
} }
@ -433,7 +423,7 @@ public class ac {
* system with directories (e.g. ProDOS), this really returns the first file * system with directories (e.g. ProDOS), this really returns the first file
* with the given filename. * with the given filename.
*/ */
static void showFiles(List files, String indent, int display) { static void showFiles(List files, String indent, int display) throws DiskException {
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
FileEntry entry = (FileEntry) files.get(i); FileEntry entry = (FileEntry) files.get(i);
if (!entry.isDeleted()) { if (!entry.isDeleted()) {
@ -446,12 +436,8 @@ public class ac {
System.out.println(); System.out.println();
} }
if (entry.isDirectory()) { if (entry.isDirectory()) {
try { showFiles(((DirectoryEntry) entry).getFiles(),
showFiles(((DirectoryEntry) entry).getFiles(), indent + " ", display); //$NON-NLS-1$
indent + " ", display); //$NON-NLS-1$
} catch (DiskException e) {
// FIXME How to warn user about the problem?
}
} }
} }
} }
@ -459,7 +445,7 @@ public class ac {
/** /**
* Display information about each disk in args. * Display information about each disk in args.
*/ */
static void getDiskInfo(String[] args) throws IOException { static void getDiskInfo(String[] args) throws IOException, DiskException {
for (int d = 1; d < args.length; d++) { for (int d = 1; d < args.length; d++) {
Disk disk = new Disk(args[d]); Disk disk = new Disk(args[d]);
FormattedDisk[] formattedDisks = disk.getFormattedDisks(); FormattedDisk[] formattedDisks = disk.getFormattedDisks();
@ -513,7 +499,7 @@ public class ac {
* Pascal disks; others ignored. Proposed by David Schmidt. * Pascal disks; others ignored. Proposed by David Schmidt.
*/ */
public static void setDiskName(String imageName, String volName) public static void setDiskName(String imageName, String volName)
throws IOException { throws IOException, DiskException {
Disk disk = new Disk(imageName); Disk disk = new Disk(imageName);
if (!disk.isSDK() && !disk.isDC42()) { if (!disk.isSDK() && !disk.isDC42()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks(); FormattedDisk[] formattedDisks = disk.getFormattedDisks();