Using a new Exception for handling unknown disk formats. This will make handling errors easier.

This commit is contained in:
Lisias 2018-01-08 11:51:23 -02:00
parent 2872d93acc
commit d20056380e
3 changed files with 59 additions and 8 deletions

View File

@ -0,0 +1,38 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2002 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.storage;
/**
* A DiskUnrecognizedException is thrown when the Disk Image being opened is not recognized by any image handler.
* <br>
* Created at: Jan 8, 2018
* @author Lisias Toledo
*/
public class DiskUnrecognizedException extends DiskException {
private static final long serialVersionUID = 0xFFFFFFFF80000000L;
/**
* Constructor for DiskFullException.
*/
public DiskUnrecognizedException(final String imagepath) {
super("DiskUnrecognizedException", imagepath);
}
}

View File

@ -39,6 +39,7 @@ import org.eclipse.swt.widgets.ToolItem;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.storage.Disk.FilenameFilter;
import com.webcodepro.applecommander.storage.DiskUnrecognizedException;
import com.webcodepro.applecommander.ui.AppleCommander;
import com.webcodepro.applecommander.ui.UiBundle;
import com.webcodepro.applecommander.ui.UserPreferences;
@ -171,19 +172,31 @@ public class SwtAppleCommander implements Listener {
try {
Disk disk = new Disk(fullpath);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
if (formattedDisks != null) {
DiskWindow window = new DiskWindow(shell, formattedDisks, imageManager);
window.open();
} else {
showUnrecognizedDiskFormatMessage(fullpath);
}
DiskWindow window = new DiskWindow(shell, formattedDisks, imageManager);
window.open();
} catch (DiskUnrecognizedException e) {
showUnrecognizedDiskFormatMessage(fullpath);
} catch (Exception ignored) {
ignored.printStackTrace();
showUnrecognizedDiskFormatMessage(fullpath);
showUnexpectedErrorMessage(fullpath);
}
}
}
/**
* Displays the unrecognized disk format message.
* @param fullpath
*/
protected void showUnexpectedErrorMessage(String fullpath) {
Shell finalShell = shell;
MessageBox box = new MessageBox(finalShell, SWT.ICON_ERROR | SWT.OK);
box.setText(textBundle.get("SwtAppleCommander.UnexpectedErrorTitle")); //$NON-NLS-1$
box.setMessage(
textBundle.format("SwtAppleCommander.UnexpectedErrorMessage", //$NON-NLS-1$
fullpath));
box.open();
}
/**
* Displays the unrecognized disk format message.
* @param fullpath

View File

@ -270,7 +270,7 @@ GraphicsFilterAdapter.BadImageMessage=Unexpected graphic file encountered\!
# SwtAppleCommander
SwtAppleCommander.AppleCommander=AppleCommander
SwtAppleCommander.UnrecognizedFormatTitle=Unrecognized Disk Format
SwtAppleCommander.UnrecognizedFormatMessage=Unable to load "{0}".\n\nAppleCommander did not recognize the format\nof the disk. Either this is a new format\nor a protected disk.\n\nSorry\!
SwtAppleCommander.UnrecognizedFormatMessage=Unable to load "{0}".\n\nAppleCommander did not recognize the format of the disk. Either this is a new format or a protected disk.\n\nSorry\!
SwtAppleCommander.OpenDiskImageTooltip=Open a disk image (Ctrl+O)
SwtAppleCommander.CreateDiskImageTooltip=Create a disk image (Ctrl+C)
SwtAppleCommander.CompareDiskImageTooltip=Compare two disk images (Ctrl+E)