mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-01 03:41:29 +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)
|
private int getBufferOffset (DiskAddress da)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
@ -16,15 +15,15 @@ import com.bytezone.diskbrowser.utilities.DefaultAction;
|
||||||
public abstract class AbstractSaveAction extends DefaultAction
|
public abstract class AbstractSaveAction extends DefaultAction
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
JFileChooser fileChooser;
|
private JFileChooser fileChooser;
|
||||||
String title;
|
private String dialogTitle;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public AbstractSaveAction (String text, String tip, String title)
|
public AbstractSaveAction (String menuText, String tip, String dialogTitle)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super (text, tip);
|
super (menuText, tip);
|
||||||
this.title = title;
|
this.dialogTitle = dialogTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -34,7 +33,7 @@ public abstract class AbstractSaveAction extends DefaultAction
|
||||||
if (fileChooser == null)
|
if (fileChooser == null)
|
||||||
{
|
{
|
||||||
fileChooser = new JFileChooser ();
|
fileChooser = new JFileChooser ();
|
||||||
fileChooser.setDialogTitle (title);
|
fileChooser.setDialogTitle (dialogTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileChooser.setSelectedFile (file);
|
fileChooser.setSelectedFile (file);
|
||||||
|
@ -69,23 +68,30 @@ public abstract class AbstractSaveAction extends DefaultAction
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
void saveFile (Path sourcePath)
|
// void saveFile (Path sourcePath)
|
||||||
// ---------------------------------------------------------------------------------//
|
// // ---------------------------------------------------------------------------------//
|
||||||
{
|
// {
|
||||||
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
|
// if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
|
||||||
{
|
// {
|
||||||
File file = fileChooser.getSelectedFile ();
|
// File file = fileChooser.getSelectedFile ();
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
Files.copy (sourcePath, file.toPath ());
|
// Files.copy (sourcePath, file.toPath ());
|
||||||
JOptionPane.showMessageDialog (null,
|
// JOptionPane.showMessageDialog (null,
|
||||||
String.format ("File %s saved", file.getName ()));
|
// String.format ("File %s saved", file.getName ()));
|
||||||
}
|
// }
|
||||||
catch (IOException e)
|
// catch (FileAlreadyExistsException e)
|
||||||
{
|
// {
|
||||||
e.printStackTrace ();
|
// JOptionPane.showMessageDialog (null,
|
||||||
JOptionPane.showMessageDialog (null, "File failed to save");
|
// "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 javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import com.bytezone.diskbrowser.disk.AppleDisk;
|
||||||
import com.bytezone.diskbrowser.disk.Disk;
|
import com.bytezone.diskbrowser.disk.Disk;
|
||||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||||
|
|
||||||
|
@ -33,11 +34,17 @@ class SaveDiskAction extends AbstractSaveAction implements DiskSelectionListener
|
||||||
}
|
}
|
||||||
|
|
||||||
Disk disk = formattedDisk.getDisk ();
|
Disk disk = formattedDisk.getDisk ();
|
||||||
int blocks = disk.getTotalBlocks ();
|
if (disk instanceof AppleDisk appleDisk)
|
||||||
String suffix = blocks <= 560 ? ".dsk" : ".hdv";
|
{
|
||||||
|
int blocks = disk.getTotalBlocks ();
|
||||||
|
String suffix = blocks <= 560 ? ".dsk" : ".hdv";
|
||||||
|
|
||||||
setSelectedFile (new File (formattedDisk.getName () + suffix));
|
setSelectedFile (new File (formattedDisk.getName () + suffix));
|
||||||
saveFile (disk.getFile ().toPath ());
|
// saveFile (disk.getFile ().toPath ());
|
||||||
|
saveBuffer (appleDisk.getBuffer ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println ("Not an AppleDisk");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user