Compare commits

...

4 Commits

Author SHA1 Message Date
Denis Molony 6f943ae8c2 tidying 2022-07-31 10:08:15 +10:00
Denis Molony 5add6c0729 tidying 2022-07-31 09:58:00 +10:00
Denis Molony 921c946ab5 Added Squeeze format (BQY) 2022-07-31 09:21:52 +10:00
Denis Molony 898587b23b Added a formatted checkbox to the save dialog 2022-07-31 07:13:59 +10:00
14 changed files with 239 additions and 74 deletions

View File

@ -88,7 +88,7 @@ public class CPMDisk extends AbstractFormattedDisk
if (b1 > 31 && b1 != EMPTY_BYTE_VALUE)
break;
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
break;
for (int i = 0; i < buffer.length; i += 32)
@ -99,7 +99,7 @@ public class CPMDisk extends AbstractFormattedDisk
if (b1 == EMPTY_BYTE_VALUE) // deleted file??
continue;
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
break;
DirectoryEntry entry = new DirectoryEntry (this, buffer, i);
@ -188,9 +188,8 @@ public class CPMDisk extends AbstractFormattedDisk
public AppleFileSource getCatalog ()
// ---------------------------------------------------------------------------------//
{
String line =
"---- --------- --- - - -- -- -- -- ----------------------------"
+ "-------------------\n";
String line = "---- --------- --- - - -- -- -- -- ----------------------------"
+ "-------------------\n";
StringBuilder text = new StringBuilder ();
text.append (String.format ("File : %s%n%n", getDisplayPath ()));
text.append ("User Name Typ R S Ex S2 S1 RC Blocks\n");

View File

@ -139,9 +139,8 @@ class DirectoryEntry implements AppleFileSource
char ro = readOnly ? '*' : ' ';
char sf = systemFile ? '*' : ' ';
String text =
String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s",
userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
String text = String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s",
userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
for (DirectoryEntry entry : entries)
text = text + "\n" + entry.line ();
@ -218,14 +217,13 @@ class DirectoryEntry implements AppleFileSource
else if ("DVR".equals (type))
appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File");
else if ("ASM".equals (type) || "DOC".equals (type) || "COB".equals (type)
|| "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type)
|| "ALX".equals (type) || "SRC".equals (type) || "H".equals (type)
|| exactBuffer[len - 1] == 0x1A)
|| "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type) || "ALX".equals (type)
|| "SRC".equals (type) || "H".equals (type) || exactBuffer[len - 1] == 0x1A)
appleFile = new CPMTextFile (name, exactBuffer);
else if ("BAS".equals (type))
appleFile = new CPMBasicFile (name, exactBuffer);
else
appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + type);
appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + name + "." + type);
return appleFile;
}

View File

@ -148,7 +148,7 @@ public class DiskFactory
if ("sdk".equals (suffix) // NuFX disk
|| "shk".equals (suffix) // NuFX files or disk
|| "bxy".equals (suffix)) // NuFX in Binary2
|| "bxy".equals (suffix)) // NuFX in Bin2
{
if (debug)
System.out.println (" ** sdk/shk/bxy **");
@ -156,7 +156,11 @@ public class DiskFactory
{
nuFX = new NuFX (file.toPath ());
if (nuFX.getTotalDisks () == 0 && nuFX.getTotalFiles () == 0)
{
if (debug)
System.out.println ("Empty NuFX file");
return null;
}
byte[] diskBuffer = nuFX.getDiskBuffer ();
if (diskBuffer == null)
@ -183,10 +187,10 @@ public class DiskFactory
return null;
}
}
else if ("bny".equals (suffix)) // Binary2 uncompressed files
else if ("bny".equals (suffix) || "bqy".equals (suffix)) // Binary2 uncompressed files
{
if (debug)
System.out.println (" ** bny **");
System.out.println (" ** bny/bqy **");
try
{
binary2 = new Binary2 (file.toPath ());

View File

@ -15,27 +15,21 @@ import com.bytezone.diskbrowser.utilities.DefaultAction;
public abstract class AbstractSaveAction extends DefaultAction
// -----------------------------------------------------------------------------------//
{
private JFileChooser fileChooser;
private String dialogTitle;
protected JFileChooser fileChooser = new JFileChooser ();
// ---------------------------------------------------------------------------------//
public AbstractSaveAction (String menuText, String tip, String dialogTitle)
// ---------------------------------------------------------------------------------//
{
super (menuText, tip);
this.dialogTitle = dialogTitle;
fileChooser.setDialogTitle (dialogTitle);
}
// ---------------------------------------------------------------------------------//
void setSelectedFile (File file)
// ---------------------------------------------------------------------------------//
{
if (fileChooser == null)
{
fileChooser = new JFileChooser ();
fileChooser.setDialogTitle (dialogTitle);
}
fileChooser.setSelectedFile (file);
}
@ -43,26 +37,22 @@ public abstract class AbstractSaveAction extends DefaultAction
void saveBuffer (byte[] buffer)
// ---------------------------------------------------------------------------------//
{
if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
return;
File file = fileChooser.getSelectedFile ();
try
{
Files.write (file.toPath (), buffer, StandardOpenOption.CREATE_NEW);
JOptionPane.showMessageDialog (null,
String.format ("File %s saved", file.getName ()));
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);
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);
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (), "Failed",
JOptionPane.ERROR_MESSAGE);
}
}
}

View File

@ -36,6 +36,7 @@ public class FontAction extends DefaultAction implements QuitListener
{
super ("Set Font...", "Set display to a different font or font size",
"/com/bytezone/loadlister/");
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_F, mask));
}
@ -146,8 +147,7 @@ public class FontAction extends DefaultAction implements QuitListener
// ---------------------------------------------------------------------------------//
{
FontChangeEvent fontChangeEvent = new FontChangeEvent (font);
FontChangeListener[] listeners =
(listenerList.getListeners (FontChangeListener.class));
FontChangeListener[] listeners = (listenerList.getListeners (FontChangeListener.class));
for (FontChangeListener listener : listeners)
listener.changeFont (fontChangeEvent);
}

View File

@ -3,6 +3,7 @@ package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.disk.AppleDisk;
@ -40,7 +41,9 @@ class SaveDiskAction extends AbstractSaveAction implements DiskSelectionListener
String suffix = blocks <= 560 ? ".dsk" : ".hdv";
setSelectedFile (new File (formattedDisk.getName () + suffix));
saveBuffer (appleDisk.getBuffer ());
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
saveBuffer (appleDisk.getBuffer ());
}
else
System.out.println ("Not an AppleDisk"); // impossible

View File

@ -1,9 +1,15 @@
package com.bytezone.diskbrowser.gui;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.Action;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
@ -12,12 +18,17 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
//-----------------------------------------------------------------------------------//
{
AppleFileSource appleFileSource;
private JCheckBox formatted = new JCheckBox ("Formatted");
// ---------------------------------------------------------------------------------//
SaveFileAction ()
// ---------------------------------------------------------------------------------//
{
super ("Save file...", "Save currently selected file", "Save File");
fileChooser.setAccessory (formatted);
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_S, mask));
}
// ---------------------------------------------------------------------------------//
@ -31,8 +42,18 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
return;
}
setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin"));
saveBuffer (appleFileSource.getDataSource ().getBuffer ());
if (formatted.isSelected ())
setSelectedFile (new File (appleFileSource.getUniqueName () + ".txt"));
else
setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin"));
if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
return;
if (formatted.isSelected ())
saveBuffer (appleFileSource.getDataSource ().getText ().getBytes ());
else
saveBuffer (appleFileSource.getDataSource ().getBuffer ());
}
// ---------------------------------------------------------------------------------//
@ -41,8 +62,8 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
// ---------------------------------------------------------------------------------//
{
this.appleFileSource = event.appleFileSource;
setEnabled (
event.appleFileSource != null && event.appleFileSource.getDataSource () != null
&& event.appleFileSource.getDataSource ().getBuffer () != null);
setEnabled (appleFileSource != null && appleFileSource.getDataSource () != null
&& appleFileSource.getDataSource ().getBuffer () != null);
}
}

View File

@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.disk.Disk;
@ -41,7 +42,9 @@ class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionLis
blocks.size () == 1 ? disk.readBlock (blocks.get (0)) : disk.readBlocks (blocks);
setSelectedFile (new File ("SavedSectors.bin"));
saveBuffer (buffer);
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
saveBuffer (buffer);
}
// ---------------------------------------------------------------------------------//

View File

@ -10,20 +10,20 @@ import com.bytezone.diskbrowser.prodos.write.DiskFullException;
import com.bytezone.diskbrowser.prodos.write.FileAlreadyExistsException;
import com.bytezone.diskbrowser.prodos.write.ProdosDisk;
import com.bytezone.diskbrowser.prodos.write.VolumeCatalogFullException;
import com.bytezone.diskbrowser.utilities.Utility;
// -----------------------------------------------------------------------------------//
public class Binary2
// -----------------------------------------------------------------------------------//
{
private static final String UNDERLINE =
"------------------------------------------------------"
+ "-----------------------";
"------------------------------------------------------" + "-----------------------";
Binary2Header binary2Header;
byte[] buffer;
List<Binary2Header> headers = new ArrayList<> ();
int totalBlocks;
String fileName;
private Binary2Header binary2Header;
private byte[] buffer;
private List<Binary2Header> headers = new ArrayList<> ();
private int totalBlocks;
private String fileName;
// ---------------------------------------------------------------------------------//
public Binary2 (Path path) throws IOException
@ -43,18 +43,17 @@ public class Binary2
do
{
binary2Header = new Binary2Header (buffer, ptr);
System.out.println (binary2Header);
headers.add (binary2Header);
totalBlocks += binary2Header.totalBlocks;
ptr += ((binary2Header.eof - 1) / 128 + 1) * 128 + 128;
ptr += ((binary2Header.eof - 1) / 128 + 2) * 128;
} while (binary2Header.filesToFollow > 0);
}
// ---------------------------------------------------------------------------------//
public byte[] getDiskBuffer () throws DiskFullException, VolumeCatalogFullException,
FileAlreadyExistsException, IOException
public byte[] getDiskBuffer ()
throws DiskFullException, VolumeCatalogFullException, FileAlreadyExistsException, IOException
// ---------------------------------------------------------------------------------//
{
ProdosDisk disk = new ProdosDisk (800, "DiskBrowser");
@ -64,9 +63,19 @@ public class Binary2
byte[] dataBuffer = new byte[header.eof]; // this sux
System.arraycopy (buffer, header.ptr + 128, dataBuffer, 0, dataBuffer.length);
disk.addFile (header.fileName, header.fileType, header.auxType, header.created,
header.modified, dataBuffer, header.eof);
if (header.compressed && dataBuffer[0] == 0x76 && dataBuffer[1] == (byte) 0xFF)
{
String name = Utility.getCString (dataBuffer, 4);
Squeeze squeeze = new Squeeze ();
byte[] tmp = squeeze.unSqueeze (dataBuffer);
disk.addFile (name, header.fileType, header.auxType, header.created, header.modified, tmp,
tmp.length);
}
else
disk.addFile (header.fileName, header.fileType, header.auxType, header.created,
header.modified, dataBuffer, header.eof);
}
disk.close ();
@ -80,12 +89,12 @@ public class Binary2
{
StringBuilder text = new StringBuilder ();
text.append (String.format (
" %-15.15s Files:%5d%n%n",
fileName, headers.size ()));
text.append (
String.format (" %-15.15s Files:%5d%n%n",
fileName, headers.size ()));
text.append (" Name Type Auxtyp Modified"
+ " Fmat Length\n");
text.append (
" Name Type Auxtyp Modified" + " Fmat Length\n");
text.append (String.format ("%s%n", UNDERLINE));

View File

@ -14,10 +14,9 @@ public class Binary2Header
// -----------------------------------------------------------------------------------//
{
static DateTimeFormatter formatter = DateTimeFormatter.ofPattern ("dd-LLL-yy HH:mm");
static String[] osTypes =
{ "Prodos", "DOS 3.3", "Reserved", "DOS 3.2 or 3.1", "Pascal", "Macintosh MFS",
"Macintosh HFS", "Lisa", "CPM", "Reserved", "MS-DOS", "High Sierra (CD-ROM)",
"ISO 9660 (CD-ROM)", "AppleShare" };
static String[] osTypes = { "Prodos", "DOS 3.3", "Reserved", "DOS 3.2 or 3.1", "Pascal",
"Macintosh MFS", "Macintosh HFS", "Lisa", "CPM", "Reserved", "MS-DOS", "High Sierra (CD-ROM)",
"ISO 9660 (CD-ROM)", "AppleShare" };
int ptr;
byte[] buffer;
@ -89,8 +88,8 @@ public class Binary2Header
public String getLine ()
// ---------------------------------------------------------------------------------//
{
return String.format (" %-33s %3s $%04X %s unc %7d", fileName,
fileTypes[fileType], auxType, modified.format (formatter), eof);
return String.format (" %-33s %3s $%04X %s unc %7d", fileName, fileTypes[fileType],
auxType, modified.format (formatter), eof);
}
// ---------------------------------------------------------------------------------//
@ -117,12 +116,13 @@ public class Binary2Header
text.append (String.format ("Prodos storage type ... %02X%n", prodos16storageType));
text.append (String.format ("Prodos total blocks ... %02X%n", prodos16totalBlocks));
text.append (String.format ("Prodos eof ............ %06X %<,d%n", prodos16eof));
text.append (
String.format ("Disk space needed ..... %08X %<,d%n", diskSpaceRequired));
text.append (
String.format ("OS type ............... %02X %s%n", osType, osTypes[osType]));
text.append (String.format ("Disk space needed ..... %08X %<,d%n", diskSpaceRequired));
text.append (String.format ("OS type ............... %02X %s%n", osType, osTypes[osType]));
text.append (String.format ("Native file type ...... %02X%n", nativeFileType));
text.append (String.format ("Data flags ............ %02X%n", dataFlags));
text.append (String.format (" compressed .......... %s%n", compressed));
text.append (String.format (" encrypted ........... %s%n", encrypted));
text.append (String.format (" sparse .............. %s%n", sparsePacked));
text.append (String.format ("Version ............... %02X%n", version));
text.append (String.format ("Following files ....... %02X%n", filesToFollow));

View File

@ -0,0 +1,125 @@
package com.bytezone.diskbrowser.nufx;
import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.Utility;
// see http://fileformats.archiveteam.org/wiki/Squeeze
// see http://fileformats.archiveteam.org/wiki/RLE90
// -----------------------------------------------------------------------------------//
public class Squeeze
// -----------------------------------------------------------------------------------//
{
private static final byte[] Squeeze = { 0x76, (byte) 0xFF };
private static int RLE_DELIMITER = 0x90;
private static int EOF_TOKEN = 0x100;
private int bits;
private int bitPos = 7; // trigger the first read
private int ptr;
private byte[] buffer;
private Node[] nodes;
// ---------------------------------------------------------------------------------//
public byte[] unSqueeze (byte[] buffer)
// ---------------------------------------------------------------------------------//
{
if (!Utility.isMagic (buffer, 0, Squeeze))
throw new FileFormatException ("Not Squeeze format");
byte[] uncompressed = new byte[buffer.length * 3];
int uncPtr = 0;
int fileChecksum = Utility.getShort (buffer, 2);
String fileName = Utility.getCString (buffer, 4);
ptr = fileName.length () + 5;
int nodeCount = Utility.getShort (buffer, ptr);
ptr += 2;
nodes = new Node[nodeCount];
this.buffer = buffer;
for (int i = 0; i < nodes.length; i++)
{
int left = Utility.getSignedShort (buffer, ptr);
int right = Utility.getSignedShort (buffer, ptr + 2);
nodes[i] = new Node (left, right);
ptr += 4;
}
boolean repeating = false;
int lastVal = 0;
int sum = 0;
while (true)
{
int val = decodeSymbol ();
if (val == EOF_TOKEN)
break;
if (repeating)
{
repeating = false;
if (val == 0) // flag indicating a single RLE_DELIMITER
{
lastVal = RLE_DELIMITER;
val = 2;
}
while (--val != 0)
{
sum += lastVal;
uncompressed[uncPtr++] = (byte) lastVal;
}
}
else
{
if (val == RLE_DELIMITER)
repeating = true;
else
{
lastVal = val;
sum += lastVal;
uncompressed[uncPtr++] = (byte) lastVal;
}
}
}
if ((sum & 0xFFFF) != fileChecksum)
System.out.printf ("Checksum mismatch : %04X %04X%n", fileChecksum, sum & 0xFFFF);
byte[] uncompressedBuffer = new byte[uncPtr];
System.arraycopy (uncompressed, 0, uncompressedBuffer, 0, uncompressedBuffer.length);
return uncompressedBuffer;
}
// ---------------------------------------------------------------------------------//
private int decodeSymbol ()
// ---------------------------------------------------------------------------------//
{
int val = 0;
while (true)
{
if (++bitPos > 7)
{
bits = buffer[ptr++];
bitPos = 0;
}
val = (bits & 1) == 0 ? nodes[val].left : nodes[val].right;
bits >>>= 1;
if (val < 0)
return -++val; // increment and make positive
}
}
// ---------------------------------------------------------------------------------//
record Node (int left, int right)
// ---------------------------------------------------------------------------------//
{
};
}

View File

@ -1,7 +1,6 @@
package com.bytezone.diskbrowser.pascal;
import java.awt.Color;
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
@ -30,7 +29,6 @@ public class PascalDisk extends AbstractFormattedDisk
// -----------------------------------------------------------------------------------//
{
static final int CATALOG_ENTRY_SIZE = 26;
private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT);
private final DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT);
private final VolumeEntry volumeEntry;
private final PascalCatalogSector diskCatalogSector;
@ -235,7 +233,6 @@ public class PascalDisk extends AbstractFormattedDisk
}
int lastByte = Utility.getShort (buffer, ptr + 22);
// GregorianCalendar date = Utility.getPascalDate (buffer, 24);
LocalDate localDate = Utility.getPascalLocalDate (buffer, 24);
String dateString = localDate == null ? ""
: localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT));

View File

@ -17,6 +17,7 @@ public abstract class DefaultAction extends AbstractAction
// ---------------------------------------------------------------------------------//
{
super (text);
this.baseURL = null;
putValue (Action.SHORT_DESCRIPTION, tip);
}
@ -26,6 +27,7 @@ public abstract class DefaultAction extends AbstractAction
// ---------------------------------------------------------------------------------//
{
super (text);
this.baseURL = baseURL;
putValue (Action.SHORT_DESCRIPTION, tip);
}
@ -39,6 +41,7 @@ public abstract class DefaultAction extends AbstractAction
System.out.println ("Base URL not set");
return;
}
URL url = this.getClass ().getResource (baseURL + iconName);
if (url != null)
putValue (iconType, new ImageIcon (url));

View File

@ -41,7 +41,7 @@ public final class Utility
private static MathContext mathContext8 = new MathContext (15);
private static final List<String> suffixes = Arrays.asList ("po", "dsk", "do", "hdv", "2mg",
"d13", "sdk", "shk", "bxy", "bny", "woz", "img", "dimg");
"d13", "sdk", "shk", "bxy", "bny", "bqy", "woz", "img", "dimg");
// ---------------------------------------------------------------------------------//
private Utility ()
@ -454,6 +454,19 @@ public final class Utility
}
}
// ---------------------------------------------------------------------------------//
public static String getCString (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
int length = 0;
int ptr = offset;
while (buffer[ptr++] != 0)
++length;
return new String (buffer, offset, length);
}
// ---------------------------------------------------------------------------------//
public static int getWizLong (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//