diff --git a/src/com/bytezone/diskbrowser/disk/AppleDisk.java b/src/com/bytezone/diskbrowser/disk/AppleDisk.java index 481d7de..d842b68 100755 --- a/src/com/bytezone/diskbrowser/disk/AppleDisk.java +++ b/src/com/bytezone/diskbrowser/disk/AppleDisk.java @@ -670,6 +670,13 @@ public class AppleDisk implements Disk } } + // ---------------------------------------------------------------------------------// + public byte[] getBuffer () + // ---------------------------------------------------------------------------------// + { + return diskBuffer; + } + // ---------------------------------------------------------------------------------// private int getBufferOffset (DiskAddress da) // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/gui/AbstractSaveAction.java b/src/com/bytezone/diskbrowser/gui/AbstractSaveAction.java index e275e08..548cd1c 100644 --- a/src/com/bytezone/diskbrowser/gui/AbstractSaveAction.java +++ b/src/com/bytezone/diskbrowser/gui/AbstractSaveAction.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.StandardOpenOption; import javax.swing.JFileChooser; @@ -16,15 +15,15 @@ import com.bytezone.diskbrowser.utilities.DefaultAction; public abstract class AbstractSaveAction extends DefaultAction // -----------------------------------------------------------------------------------// { - JFileChooser fileChooser; - String title; + private JFileChooser fileChooser; + private String dialogTitle; // ---------------------------------------------------------------------------------// - public AbstractSaveAction (String text, String tip, String title) + public AbstractSaveAction (String menuText, String tip, String dialogTitle) // ---------------------------------------------------------------------------------// { - super (text, tip); - this.title = title; + super (menuText, tip); + this.dialogTitle = dialogTitle; } // ---------------------------------------------------------------------------------// @@ -34,7 +33,7 @@ public abstract class AbstractSaveAction extends DefaultAction if (fileChooser == null) { fileChooser = new JFileChooser (); - fileChooser.setDialogTitle (title); + fileChooser.setDialogTitle (dialogTitle); } fileChooser.setSelectedFile (file); @@ -69,23 +68,30 @@ public abstract class AbstractSaveAction extends DefaultAction } // ---------------------------------------------------------------------------------// - void saveFile (Path sourcePath) - // ---------------------------------------------------------------------------------// - { - if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION) - { - File file = fileChooser.getSelectedFile (); - try - { - Files.copy (sourcePath, file.toPath ()); - JOptionPane.showMessageDialog (null, - String.format ("File %s saved", file.getName ())); - } - catch (IOException e) - { - e.printStackTrace (); - JOptionPane.showMessageDialog (null, "File failed to save"); - } - } - } + // void saveFile (Path sourcePath) + // // ---------------------------------------------------------------------------------// + // { + // if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION) + // { + // File file = fileChooser.getSelectedFile (); + // try + // { + // Files.copy (sourcePath, file.toPath ()); + // JOptionPane.showMessageDialog (null, + // String.format ("File %s saved", file.getName ())); + // } + // catch (FileAlreadyExistsException e) + // { + // JOptionPane.showMessageDialog (null, + // "File " + file.getName () + " already exists", "Failed", + // JOptionPane.ERROR_MESSAGE); + // } + // catch (IOException e) + // { + // e.printStackTrace (); + // JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (), + // "Failed", JOptionPane.ERROR_MESSAGE); + // } + // } + // } } diff --git a/src/com/bytezone/diskbrowser/gui/SaveDiskAction.java b/src/com/bytezone/diskbrowser/gui/SaveDiskAction.java index 1320b44..9dd9eaf 100644 --- a/src/com/bytezone/diskbrowser/gui/SaveDiskAction.java +++ b/src/com/bytezone/diskbrowser/gui/SaveDiskAction.java @@ -5,6 +5,7 @@ import java.io.File; import javax.swing.JOptionPane; +import com.bytezone.diskbrowser.disk.AppleDisk; import com.bytezone.diskbrowser.disk.Disk; import com.bytezone.diskbrowser.disk.FormattedDisk; @@ -33,11 +34,17 @@ class SaveDiskAction extends AbstractSaveAction implements DiskSelectionListener } Disk disk = formattedDisk.getDisk (); - int blocks = disk.getTotalBlocks (); - String suffix = blocks <= 560 ? ".dsk" : ".hdv"; + if (disk instanceof AppleDisk appleDisk) + { + int blocks = disk.getTotalBlocks (); + String suffix = blocks <= 560 ? ".dsk" : ".hdv"; - setSelectedFile (new File (formattedDisk.getName () + suffix)); - saveFile (disk.getFile ().toPath ()); + setSelectedFile (new File (formattedDisk.getName () + suffix)); + // saveFile (disk.getFile ().toPath ()); + saveBuffer (appleDisk.getBuffer ()); + } + else + System.out.println ("Not an AppleDisk"); } // ---------------------------------------------------------------------------------//