mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-03-16 22:31:23 +00:00
combined file and buffer saves
This commit is contained in:
parent
d3f21e0d49
commit
9dddd2be3e
@ -670,6 +670,13 @@ public class AppleDisk implements Disk
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public byte[] getBuffer ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return diskBuffer;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private int getBufferOffset (DiskAddress da)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
Loading…
x
Reference in New Issue
Block a user