diff --git a/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java b/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java index 3934e8b..6e4d248 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java @@ -28,6 +28,9 @@ import java.util.List; *

* Date Created: Mar 2, 2003 * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public interface DirectoryEntry { /** @@ -37,17 +40,17 @@ public interface DirectoryEntry { * return value should always be a list - a directory * with 0 entries returns an empty list. */ - public List getFiles(); + public List getFiles() throws DiskException; /** * Create a new FileEntry. */ - public FileEntry createFile() throws DiskFullException; - + public FileEntry createFile() throws DiskException; + /** * Create a new DirectoryEntry. */ - public DirectoryEntry createDirectory(String name) throws DiskFullException; + public DirectoryEntry createDirectory(String name) throws DiskException; /** * Identify if additional directories can be created. This @@ -56,7 +59,7 @@ public interface DirectoryEntry { * to writing. */ public boolean canCreateDirectories(); - + /** * Indicates if this disk image can create a file. * If not, the reason may be as simple as it has not beem implemented diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java new file mode 100644 index 0000000..2ead92b --- /dev/null +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java @@ -0,0 +1,39 @@ +/* + * 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 DiskCorruptException is thrown during the disk's data structures are corrupted + * beyound hope of automatic recovering. + *
+ * Created on Nov 30, 2017. + * @author Lisias Toledo + */ +public class DiskCorruptException extends DiskException { + + private static final long serialVersionUID = 0xFFFFFFFF80000000L; + + /** + * Constructor for DiskFullException. + */ + public DiskCorruptException(String description) { + super(description); + } +} diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java new file mode 100644 index 0000000..2114316 --- /dev/null +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java @@ -0,0 +1,39 @@ +/* + * 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 DiskFullException is thrown during a write operation when the file + * being written will not fit on the disk. + *
+ * Created on Dec 23, 2002. + * @author Rob Greene + */ +public class DiskException extends Exception { + + private static final long serialVersionUID = 0xFFFFFFFF80000000L; + + /** + * Constructor for DiskFullException. + */ + public DiskException(String description) { + super(description); + } +} diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java index 60fa270..de28f56 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java @@ -25,8 +25,11 @@ package com.webcodepro.applecommander.storage; *
* Created on Dec 23, 2002. * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ -public class DiskFullException extends Exception { +public class DiskFullException extends DiskException { private static final long serialVersionUID = 0xFFFFFFFF80000000L; diff --git a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java index d407638..68160c6 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java @@ -268,7 +268,13 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry { * Returns a null if specific filename is not located. */ public FileEntry getFile(String filename) { - List files = getFiles(); + List files; + try { + files = getFiles(); + } catch (DiskException e) { + // FIXME how to warn the User about this? + files = new ArrayList<>(); + } return getFile(files, filename.trim()); } @@ -282,11 +288,13 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry { if (files != null) { for (int i=0; i * Date created: Oct 4, 2002 12:29:23 AM * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public class DosFormatDisk extends FormattedDisk { private TextBundle textBundle = StorageBundle.getInstance(); @@ -132,14 +139,22 @@ public class DosFormatDisk extends FormattedDisk { /** * Retrieve a list of files. + * @throws DiskException * @see com.webcodepro.applecommander.storage.FormattedDisk#getFiles() */ - public List getFiles() { + public List getFiles() throws DiskException { List list = new ArrayList<>(); byte[] vtoc = readVtoc(); int track = AppleUtil.getUnsignedByte(vtoc[1]); int sector = AppleUtil.getUnsignedByte(vtoc[2]); + final Map> visits = new HashMap<>(); while (sector != 0) { // bug fix: iterate through all catalog _sectors_ + + // Prevents a recursive catalog crawling. + if ( !visits.containsKey(track) ) visits.put(track, new HashMap()); + if ( visits.get(track).containsKey(sector)) throw new DiskCorruptException("Recursive Directory structure detected."); + else visits.get(track).put(sector, Boolean.TRUE); + byte[] catalogSector = readSector(track, sector); int offset = 0x0b; while (offset < 0xff) { // iterate through all entries diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDirectoryEntry.java b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDirectoryEntry.java index 3ebc356..bee6f14 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDirectoryEntry.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDirectoryEntry.java @@ -22,6 +22,7 @@ package com.webcodepro.applecommander.storage.os.prodos; import java.util.List; import com.webcodepro.applecommander.storage.DirectoryEntry; +import com.webcodepro.applecommander.storage.DiskException; import com.webcodepro.applecommander.storage.DiskFullException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.StorageBundle; @@ -32,21 +33,24 @@ import com.webcodepro.applecommander.util.TextBundle; *

* Date Created: Mar 2, 2003 * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public class ProdosDirectoryEntry extends ProdosFileEntry implements DirectoryEntry { private TextBundle textBundle = StorageBundle.getInstance(); private ProdosSubdirectoryHeader subdirectoryHeader; - + /** * Constructor for ProdosDirectoryEntry. */ - public ProdosDirectoryEntry(ProdosFormatDisk disk, int block, int offset, + public ProdosDirectoryEntry(ProdosFormatDisk disk, int block, int offset, ProdosSubdirectoryHeader subdirectoryHeader) { super(disk, block, offset); this.subdirectoryHeader = subdirectoryHeader; subdirectoryHeader.setProdosDirectoryEntry(this); } - + /** * Get the subdirectory header. */ @@ -60,8 +64,9 @@ public class ProdosDirectoryEntry extends ProdosFileEntry implements DirectoryEn * value should be null. If this a directory, the * return value should always be a list - a directory * with 0 entries returns an empty list. + * @throws DiskException */ - public List getFiles() { + public List getFiles() throws DiskException { return getDisk().getFiles(getSubdirectoryHeader().getFileEntryBlock()); } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java index aef90a5..27fa001 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java @@ -23,10 +23,14 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.webcodepro.applecommander.storage.DirectoryEntry; +import com.webcodepro.applecommander.storage.DiskException; +import com.webcodepro.applecommander.storage.DiskCorruptException; import com.webcodepro.applecommander.storage.DiskFullException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FormattedDisk; @@ -40,6 +44,9 @@ import com.webcodepro.applecommander.util.TextBundle; *

* Date created: Oct 3, 2002 11:45:25 PM * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public class ProdosFormatDisk extends FormattedDisk { private TextBundle textBundle = StorageBundle.getInstance(); @@ -255,9 +262,10 @@ public class ProdosFormatDisk extends FormattedDisk { /** * Retrieve a list of files. + * @throws DiskException * @see com.webcodepro.applecommander.storage.FormattedDisk#getFiles() */ - public List getFiles() { + public List getFiles() throws DiskException { return getFiles(VOLUME_DIRECTORY_BLOCK); } @@ -265,9 +273,14 @@ public class ProdosFormatDisk extends FormattedDisk { * Build a list of files, starting in the given block number. * This works for the master as well as the subdirectories. */ - protected List getFiles(int blockNumber) { + protected List getFiles(int blockNumber) throws DiskException { List files = new ArrayList<>(); + final Map visits = new HashMap<>(); while (blockNumber != 0) { + // Prevents a recursive catalog crawling. + if ( visits.containsKey(blockNumber)) throw new DiskCorruptException("Recursive Directory structure detected."); + else visits.put(blockNumber, Boolean.TRUE); + byte[] block = readBlock(blockNumber); int offset = 4; while (offset+ProdosCommonEntry.ENTRY_LENGTH < BLOCK_SIZE) { diff --git a/src/main/java/com/webcodepro/applecommander/ui/ac.java b/src/main/java/com/webcodepro/applecommander/ui/ac.java index ecdf863..a3cd089 100644 --- a/src/main/java/com/webcodepro/applecommander/ui/ac.java +++ b/src/main/java/com/webcodepro/applecommander/ui/ac.java @@ -34,7 +34,7 @@ import java.util.List; import com.webcodepro.applecommander.storage.DirectoryEntry; import com.webcodepro.applecommander.storage.Disk; -import com.webcodepro.applecommander.storage.DiskFullException; +import com.webcodepro.applecommander.storage.DiskException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FileFilter; import com.webcodepro.applecommander.storage.FormattedDisk; @@ -85,6 +85,9 @@ import com.webcodepro.applecommander.util.TextBundle; * * * @author John B. Matthews + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public class ac { private static TextBundle textBundle = UiBundle.getInstance(); @@ -154,7 +157,7 @@ public class ac { * Put fileName from the local filesytem into the file named fileOnImageName on the disk named imageName; * Note: only volume level supported; input size unlimited. */ - public static void putFile(String fileName, String imageName, String fileOnImageName, String fileType, String address) throws IOException, DiskFullException { + public static void putFile(String fileName, String imageName, String fileOnImageName, String fileType, String address) throws IOException, DiskException { Name name = new Name(fileOnImageName); File file = new File(fileName); if (!file.canRead()) @@ -188,7 +191,7 @@ public class ac { * Note: only volume level supported; input size unlimited. */ static void putFile(String imageName, Name name, String fileType, - String address) throws IOException, DiskFullException { + String address) throws IOException, DiskException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); byte[] inb = new byte[1024]; @@ -225,7 +228,7 @@ public class ac { * Assume a cc65 style four-byte header with start address in bytes 0-1. */ public static void putCC65(String fileName, String imageName, String fileOnImageName, String fileType) - throws IOException, DiskFullException { + throws IOException, DiskException { byte[] header = new byte[4]; if (System.in.read(header, 0, 4) == 4) { @@ -239,7 +242,7 @@ public class ac { * Assume a cc65 style four-byte header with start address in bytes 0-1. */ static void putCC65(String imageName, Name name, String fileType) - throws IOException, DiskFullException { + throws IOException, DiskException { byte[] header = new byte[4]; if (System.in.read(header, 0, 4) == 4) { @@ -253,7 +256,7 @@ public class ac { * This would only make sense for a ProDOS-formatted disk. */ static void putGEOS(String imageName) - throws IOException, DiskFullException { + throws IOException, DiskException { putFile(imageName, new Name("GEOS-Should Be ProDOS"), "GEO", "0"); //$NON-NLS-2$ $NON-NLS-3$ } @@ -327,9 +330,11 @@ public class ac { directory = "."+File.separator; } 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]; - writeFiles(formattedDisk.getFiles(), directory); + writeFiles(formattedDisk.getFiles(), directory); + } catch (DiskException e) { + // FIXME How to warn user about the problem? } } @@ -352,8 +357,10 @@ public class ac { OutputStream output = new FileOutputStream(file); output.write(buf, 0, buf.length); output.close(); - } else if (entry.isDirectory()) { + } else if (entry.isDirectory()) try { writeFiles(((DirectoryEntry) entry).getFiles(),directory+entry.getFilename()+File.separator); + } catch (DiskException e) { + // FIXME How to warn user about the problem? } } } @@ -373,11 +380,13 @@ public class ac { if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) { return entry; } - if (entry.isDirectory()) { + if (entry.isDirectory()) try { entry = getEntry(((DirectoryEntry) entry).getFiles(), fileName); if (entry != null) { return entry; } + } catch (DiskException e) { + // FIXME How to warn user about the problem? } } } @@ -406,6 +415,8 @@ public class ac { new Integer(formattedDisk.getUsedSpace()) })); System.out.println(); } + } catch (DiskException e) { + throw new IOException(e); } catch (RuntimeException e) { System.out.println(args[d] + ": " + e.getMessage()); //$NON-NLS-1$ System.out.println(); @@ -430,9 +441,11 @@ public class ac { } System.out.println(); } - if (entry.isDirectory()) { + if (entry.isDirectory()) try { showFiles(((DirectoryEntry) entry).getFiles(), indent + " ", display); //$NON-NLS-1$ + } catch (DiskException e) { + // FIXME How to warn user about the problem? } } } @@ -602,29 +615,33 @@ public class ac { } public FileEntry getEntry(FormattedDisk formattedDisk) { - List files = formattedDisk.getFiles(); - FileEntry entry = null; - for (int i = 0; i < path.length - 1; i++) { - String dirName = path[i]; - for (int j = 0; j < files.size(); j++) { - entry = (FileEntry) files.get(j); - String entryName = entry.getFilename(); - if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) { - files = ((DirectoryEntry) entry).getFiles(); + try { + List files = formattedDisk.getFiles(); + FileEntry entry = null; + for (int i = 0; i < path.length - 1; i++) { + String dirName = path[i]; + for (int j = 0; j < files.size(); j++) { + entry = (FileEntry) files.get(j); + String entryName = entry.getFilename(); + if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) { + files = ((DirectoryEntry) entry).getFiles(); + } } } - } - for (int i = 0; i < files.size(); i++) { - entry = (FileEntry) files.get(i); - String entryName = entry.getFilename(); - if (!entry.isDeleted() && name.equalsIgnoreCase(entryName)) { - return entry; + for (int i = 0; i < files.size(); i++) { + entry = (FileEntry) files.get(i); + String entryName = entry.getFilename(); + if (!entry.isDeleted() && name.equalsIgnoreCase(entryName)) { + return entry; + } } + } catch (DiskException e) { + // FIXME How to warn user about the problem? } return null; } - public FileEntry createEntry(FormattedDisk formattedDisk) throws DiskFullException { + public FileEntry createEntry(FormattedDisk formattedDisk) throws DiskException { if (path.length == 1) { return formattedDisk.createFile(); } diff --git a/src/main/java/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java b/src/main/java/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java index f5794e3..51a79d6 100644 --- a/src/main/java/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java +++ b/src/main/java/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -71,6 +72,7 @@ import org.eclipse.swt.widgets.TreeItem; import com.webcodepro.applecommander.compiler.ApplesoftCompiler; import com.webcodepro.applecommander.storage.DirectoryEntry; import com.webcodepro.applecommander.storage.Disk; +import com.webcodepro.applecommander.storage.DiskException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FileEntryComparator; import com.webcodepro.applecommander.storage.FileFilter; @@ -114,6 +116,9 @@ import com.webcodepro.applecommander.util.TextBundle; *

* Date created: Nov 17, 2002 9:46:53 PM * @author Rob Greene + * + * Changed at: Dec 1, 2017 + * @author Lisias Toledo */ public class DiskExplorerTab { private static final char CTRL_C = 'C' - '@'; @@ -224,7 +229,11 @@ public class DiskExplorerTab { * Single-click handler. */ public void widgetSelected(SelectionEvent event) { - changeCurrentFormat(getCurrentFormat()); // minor hack + try { + changeCurrentFormat(getCurrentFormat()); // minor hack + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } /** * Double-click handler. @@ -248,8 +257,8 @@ public class DiskExplorerTab { diskItem.setText(disks[i].getDiskName()); diskItem.setData(disks[i]); directoryTree.setSelection(new TreeItem[] { diskItem }); - - if (disks[i].canHaveDirectories()) { + + if (disks[i].canHaveDirectories()) try { Iterator files = disks[i].getFiles().iterator(); while (files.hasNext()) { FileEntry entry = (FileEntry) files.next(); @@ -260,15 +269,21 @@ public class DiskExplorerTab { addDirectoriesToTree(item, (DirectoryEntry)entry); } } - } + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } - + computeColumnWidths(FormattedDisk.FILE_DISPLAY_STANDARD); computeColumnWidths(FormattedDisk.FILE_DISPLAY_NATIVE); computeColumnWidths(FormattedDisk.FILE_DISPLAY_DETAIL); formatChanged = true; - fillFileTable(disks[0].getFiles()); + try { + fillFileTable(disks[0].getFiles()); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } directoryTree.setSelection(new TreeItem[] { directoryTree.getItems()[0] }); } /** @@ -338,11 +353,15 @@ public class DiskExplorerTab { item.setImage(imageManager.get(ImageManager.ICON_IMPORT_FILE)); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - importFiles(); + try { + importFiles(); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); item.setEnabled(disks[0].canCreateFile() && disks[0].canWriteFileData()); - + return menu; } /** @@ -389,7 +408,11 @@ public class DiskExplorerTab { item.setImage(imageManager.get(ImageManager.ICON_VIEW_FILE)); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - viewFile(null); + try { + viewFile(null); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); @@ -444,7 +467,11 @@ public class DiskExplorerTab { item.setText(textBundle.get("ViewAsTextMenuItem")); //$NON-NLS-1$ item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - viewFile(TextFileFilter.class); + try { + viewFile(TextFileFilter.class); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); @@ -452,7 +479,11 @@ public class DiskExplorerTab { item.setText(textBundle.get("VeiwAsGraphicsMenuItem")); //$NON-NLS-1$ item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - viewFile(GraphicsFileFilter.class); + try { + viewFile(GraphicsFileFilter.class); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); @@ -879,7 +910,11 @@ public class DiskExplorerTab { * Double-click handler. */ public void widgetDefaultSelected(SelectionEvent event) { - viewFile(null); + try { + viewFile(null); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); TableColumn column = null; @@ -1101,12 +1136,13 @@ public class DiskExplorerTab { } /** * Start the import wizard and import the selected files. + * @throws DiskException */ - protected void importFiles() { + protected void importFiles() throws DiskException { //FIXME: This code has become really ugly! TreeItem treeItem = directoryTree.getSelection()[0]; DirectoryEntry directory = (DirectoryEntry) treeItem.getData(); - ImportWizard wizard = new ImportWizard(shell, + ImportWizard wizard = new ImportWizard(shell, imageManager, directory.getFormattedDisk()); wizard.open(); if (wizard.isWizardCompleted()) { @@ -1201,8 +1237,9 @@ public class DiskExplorerTab { } /** * Helper function for building fileTree. + * @throws DiskException */ - protected void addDirectoriesToTree(TreeItem directoryItem, DirectoryEntry directoryEntry) { + protected void addDirectoriesToTree(TreeItem directoryItem, DirectoryEntry directoryEntry) throws DiskException { Iterator files = directoryEntry.getFiles().iterator(); while (files.hasNext()) { final FileEntry entry = (FileEntry) files.next(); @@ -1228,8 +1265,12 @@ public class DiskExplorerTab { standardFormatToolItem.setToolTipText(textBundle.get("StandardViewHoverText")); //$NON-NLS-1$ standardFormatToolItem.setSelection(true); standardFormatToolItem.addSelectionListener(new SelectionAdapter () { - public void widgetSelected(SelectionEvent e) { - changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD); + public void widgetSelected(SelectionEvent event) { + try { + changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); nativeFormatToolItem = new ToolItem(toolBar, SWT.RADIO); @@ -1237,8 +1278,12 @@ public class DiskExplorerTab { nativeFormatToolItem.setText(textBundle.get("NativeViewToolItem")); //$NON-NLS-1$ nativeFormatToolItem.setToolTipText(textBundle.get("NativeViewHoverText")); //$NON-NLS-1$ nativeFormatToolItem.addSelectionListener(new SelectionAdapter () { - public void widgetSelected(SelectionEvent e) { - changeCurrentFormat(FormattedDisk.FILE_DISPLAY_NATIVE); + public void widgetSelected(SelectionEvent event) { + try { + changeCurrentFormat(FormattedDisk.FILE_DISPLAY_NATIVE); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); detailFormatToolItem = new ToolItem(toolBar, SWT.RADIO); @@ -1246,13 +1291,17 @@ public class DiskExplorerTab { detailFormatToolItem.setText(textBundle.get("DetailViewToolItem")); //$NON-NLS-1$ detailFormatToolItem.setToolTipText(textBundle.get("DetailViewHoverText")); //$NON-NLS-1$ detailFormatToolItem.addSelectionListener(new SelectionAdapter () { - public void widgetSelected(SelectionEvent e) { - changeCurrentFormat(FormattedDisk.FILE_DISPLAY_DETAIL); + public void widgetSelected(SelectionEvent event) { + try { + changeCurrentFormat(FormattedDisk.FILE_DISPLAY_DETAIL); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); - + new ToolItem(toolBar, SWT.SEPARATOR); - + showDeletedFilesToolItem = new ToolItem(toolBar, SWT.CHECK); showDeletedFilesToolItem.setImage(imageManager.get(ImageManager.ICON_SHOW_DELETED_FILES)); showDeletedFilesToolItem.setText(textBundle.get("ShowDeletedFilesToolItem")); //$NON-NLS-1$ @@ -1274,11 +1323,15 @@ public class DiskExplorerTab { importToolItem.setToolTipText(textBundle.get("ImportWizardHoverText")); //$NON-NLS-1$ importToolItem.setEnabled(disks[0].canCreateFile() && disks[0].canWriteFileData()); importToolItem.addSelectionListener(new SelectionAdapter () { - public void widgetSelected(SelectionEvent e) { - importFiles(); + public void widgetSelected(SelectionEvent event) { + try { + importFiles(); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); - + exportToolItem = new ToolItem(toolBar, SWT.DROP_DOWN); exportToolItem.setImage(imageManager.get(ImageManager.ICON_EXPORT_FILE)); exportToolItem.setText(textBundle.get("ExportWizardToolItem")); //$NON-NLS-1$ @@ -1315,9 +1368,11 @@ public class DiskExplorerTab { viewFileItem.setEnabled(false); viewFileItem.addSelectionListener(new SelectionAdapter () { public void widgetSelected(SelectionEvent event) { - if (event.detail != SWT.ARROW) { + if (event.detail != SWT.ARROW) try { viewFile(null); - } + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }); printToolItem = new ToolItem(toolBar, SWT.PUSH); @@ -1402,8 +1457,9 @@ public class DiskExplorerTab { } /** * Change the current format and refresh the display. + * @throws DiskException */ - protected void changeCurrentFormat(int newFormat) { + protected void changeCurrentFormat(int newFormat) throws DiskException { TreeItem selection = directoryTree.getSelection()[0]; Object data = selection.getData(); DirectoryEntry directory = (DirectoryEntry) data; @@ -1522,8 +1578,9 @@ public class DiskExplorerTab { } /** * Open up the view file window for the currently selected file. + * @throws DiskException */ - protected void viewFile(Class fileFilterClass) { + protected void viewFile(Class fileFilterClass) throws DiskException { FileEntry fileEntry = getSelectedFileEntry(); if (fileEntry.isDeleted()) { SwtUtil.showErrorDialog(shell, textBundle.get("DeleteFileErrorTitle"), //$NON-NLS-1$ @@ -1583,8 +1640,8 @@ public class DiskExplorerTab { return new Listener() { public void handleEvent(Event event) { FileEntry fileEntry = getSelectedFileEntry(); - if (fileEntry != null && event.type == SWT.KeyUp && (event.stateMask & SWT.CTRL) != 0) { - switch (event.character) { + if (fileEntry != null && event.type == SWT.KeyUp && (event.stateMask & SWT.CTRL) != 0) + try { switch (event.character) { case CTRL_C: // Compile Wizard if (getCompileToolItem().isEnabled()) { compileFileWizard(); @@ -1601,8 +1658,9 @@ public class DiskExplorerTab { case CTRL_V: // View file viewFile(null); break; - } - } + } } catch (DiskException e) { + // FIXME how to warn the User about this? + } } }; } @@ -1624,7 +1682,7 @@ public class DiskExplorerTab { saveAs(); break; } - } else { + } else try { switch (event.character) { case CTRL_I: // Import Wizard importFiles(); @@ -1638,10 +1696,12 @@ public class DiskExplorerTab { } break; } - } + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } else { // No CTRL key - if ((event.stateMask & SWT.ALT) != SWT.ALT) { // Ignore ALT key combinations like alt-F4! - switch (event.keyCode) { + if ((event.stateMask & SWT.ALT) != SWT.ALT) // Ignore ALT key combinations like alt-F4! + try { switch (event.keyCode) { case SWT.F2: // Standard file display changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD); break; @@ -1657,7 +1717,9 @@ public class DiskExplorerTab { fillFileTable(getCurrentFileList()); break; } - } + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } } } @@ -1728,7 +1790,11 @@ public class DiskExplorerTab { printFileHeaders(); gc.setFont(normalFont); println(disk.getDiskName()); - printFiles(disk, 1); + try { + printFiles(disk, 1); + } catch (DiskException e) { + // FIXME how to warn the User about this? + } } if (y != clientArea.y) { // partial page printFooter(); @@ -1811,7 +1877,7 @@ public class DiskExplorerTab { clientArea.y + clientArea.height + dpiY - point.y); page++; } - protected void printFiles(DirectoryEntry directory, int level) { + protected void printFiles(DirectoryEntry directory, int level) throws DiskException { Iterator iterator = directory.getFiles().iterator(); while (iterator.hasNext()) { FileEntry fileEntry = (FileEntry) iterator.next();