display nufx disks correctly

This commit is contained in:
Denis Molony 2021-05-08 19:56:57 +10:00
parent 269a1bbd83
commit c6443ff89e
5 changed files with 53 additions and 27 deletions

View File

@ -139,7 +139,7 @@ public class DiskFactory
} }
if ("sdk".equals (suffix) || "shk".equals (suffix) // shrinkit disk/file archive if ("sdk".equals (suffix) || "shk".equals (suffix) // shrinkit disk/file archive
|| "bxy".equals (suffix)) || "bxy".equals (suffix) || "bny".equals (suffix))
{ {
if (debug) if (debug)
System.out.println (" ** sdk/shk/bxy **"); System.out.println (" ** sdk/shk/bxy **");

View File

@ -1,5 +1,7 @@
package com.bytezone.diskbrowser.utilities; package com.bytezone.diskbrowser.utilities;
import static com.bytezone.diskbrowser.prodos.ProdosConstants.BLOCK_SIZE;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -22,7 +24,7 @@ public class NuFX
+ "-----------------------"; + "-----------------------";
private MasterHeader masterHeader; private MasterHeader masterHeader;
private final byte[] buffer; private final byte[] buffer;
private final boolean debug = false; private final boolean debug = true;
private final List<Record> records = new ArrayList<> (); private final List<Record> records = new ArrayList<> ();
private int totalFiles; private int totalFiles;
@ -78,25 +80,26 @@ public class NuFX
if (record.hasDisk ()) if (record.hasDisk ())
++totalDisks; ++totalDisks;
} }
listFiles ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private void calculateTotalBlocks () private void calculateTotalBlocks () // not exact
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
totalBlocks = 0; totalBlocks = 0;
for (Record record : records) for (Record record : records)
if (record.hasFile ()) if (record.hasFile () || record.hasResource ())
{ {
// note: total blocks does not include subdirectory blocks // note: total blocks does not include subdirectory blocks
int blocks = (record.getUncompressedSize () - 1) / 512 + 1; int blocks = (record.getUncompressedSize () - 1) / BLOCK_SIZE + 1;
if (blocks == 1) // seedling if (blocks == 1) // seedling
totalBlocks += blocks; totalBlocks += blocks;
else if (blocks <= 256) // sapling else if (blocks <= 0x100) // sapling
totalBlocks += blocks + 1; totalBlocks += blocks + 1;
else // tree else // tree
totalBlocks += blocks + (blocks / 256) + 2; totalBlocks += blocks + (blocks / 0x100) + 2;
} }
} }
@ -231,7 +234,7 @@ public class NuFX
{ {
if (record.hasFile ()) if (record.hasFile ())
{ {
System.out.printf ("%3d %-35s %,7d %d %,7d%n", count, record.getFileName (), System.out.printf ("%3d %-35s %,7d %02X %,7d%n", count, record.getFileName (),
record.getFileSize (), record.getFileType (), record.getUncompressedSize ()); record.getFileSize (), record.getFileType (), record.getUncompressedSize ());
} }
count++; count++;
@ -245,7 +248,7 @@ public class NuFX
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (String.format (" %s Created:%s Mod:%s Recs:%5d%n%n", text.append (String.format (" %-15.15s Created:%-17s Mod:%-17s Recs:%5d%n%n",
volumeName.getFileName (), masterHeader.getCreated2 (), volumeName.getFileName (), masterHeader.getCreated2 (),
masterHeader.getModified2 (), masterHeader.getTotalRecords ())); masterHeader.getModified2 (), masterHeader.getTotalRecords ()));
@ -259,9 +262,16 @@ public class NuFX
for (Record record : records) for (Record record : records)
{ {
text.append (String.format ("%s%n", record.getLine ())); // if (record.hasDisk ())
totalUncompressedSize += record.getUncompressedSize (); // {
totalCompressedSize += record.getCompressedSize (); //
// }
// else
{
text.append (String.format ("%s%n", record.getLine ()));
totalUncompressedSize += record.getUncompressedSize ();
totalCompressedSize += record.getCompressedSize ();
}
} }
text.append (String.format ("%s%n", UNDERLINE)); text.append (String.format ("%s%n", UNDERLINE));

View File

@ -233,6 +233,7 @@ class Record
return fileSystems[fileSystemID]; return fileSystems[fileSystemID];
} }
// Called by NuFX.listFiles()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
int getFileSize () int getFileSize ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -249,7 +250,7 @@ class Record
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
for (Thread thread : threads) for (Thread thread : threads)
if (thread.hasFile ()) if (thread.hasFile () || thread.hasDisk ())
return thread.threadFormat; return thread.threadFormat;
return 0; return 0;
@ -259,10 +260,13 @@ class Record
int getUncompressedSize () int getUncompressedSize ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (hasDisk ())
return auxType * storType;
int size = 0; int size = 0;
for (Thread thread : threads) for (Thread thread : threads)
if (thread.hasFile () || thread.hasResource ()) if (thread.hasFile () || thread.hasResource () || thread.hasDisk ())
size += thread.getUncompressedEOF (); size += thread.getUncompressedEOF ();
return size; return size;
@ -275,7 +279,7 @@ class Record
int size = 0; int size = 0;
for (Thread thread : threads) for (Thread thread : threads)
if (thread.hasFile () || thread.hasResource ()) if (thread.hasFile () || thread.hasResource () || thread.hasDisk ())
size += thread.getCompressedEOF (); size += thread.getCompressedEOF ();
return size; return size;
@ -307,15 +311,22 @@ class Record
String getLine () String getLine ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
float pct = 0;
if (getUncompressedSize () > 0)
pct = getCompressedSize () * 100 / getUncompressedSize ();
String lockedFlag = (access | 0xC3) == 1 ? "+" : " ";
String forkedFlag = hasResource () ? "+" : " ";
String name = getFileName (); String name = getFileName ();
if (name.length () > 27) if (name.length () > 27)
name = ".." + name.substring (name.length () - 25); name = ".." + name.substring (name.length () - 25);
float pct = 100;
if (getUncompressedSize () > 0)
pct = getCompressedSize () * 100 / getUncompressedSize ();
String lockedFlag = (access | 0xC3) == 1 ? "+" : " ";
String forkedFlag = hasResource () ? "+" : " ";
if (hasDisk ())
return String.format ("%s%-27.27s %-4s %-6s %-15s %s %3.0f%% %7d", lockedFlag,
name, "Disk", (getUncompressedSize () / 1024) + "k", archived.format2 (),
threadFormats[getThreadFormat ()], pct, getUncompressedSize ());
return String.format ("%s%-27.27s %s%s $%04X %-15s %s %3.0f%% %7d", lockedFlag, return String.format ("%s%-27.27s %s%s $%04X %-15s %s %3.0f%% %7d", lockedFlag,
name, fileTypes[fileType], forkedFlag, auxType, archived.format2 (), name, fileTypes[fileType], forkedFlag, auxType, archived.format2 (),
threadFormats[getThreadFormat ()], pct, getUncompressedSize ()); threadFormats[getThreadFormat ()], pct, getUncompressedSize ());

View File

@ -14,6 +14,10 @@ class Thread
{ "data fork", "disk image", "resource fork" }, { "data fork", "disk image", "resource fork" },
{ "filename", "undefined", "undefined" } }; { "filename", "undefined", "undefined" } };
private static final int DATA_FORK = 0;
private static final int DISK_IMAGE = 1;
private static final int RESOURCEFORK = 2;
final int threadClass; final int threadClass;
final int threadFormat; final int threadFormat;
final int threadKind; final int threadKind;
@ -96,13 +100,13 @@ class Thread
case 2: case 2:
switch (threadKind) switch (threadKind)
{ {
case 0: // data fork of file case DATA_FORK:
hasFile = true; hasFile = true;
break; break;
case 1: // disk image case DISK_IMAGE:
hasDisk = true; hasDisk = true;
break; break;
case 2: // resource fork of file case RESOURCEFORK:
hasResource = true; hasResource = true;
break; break;
} }
@ -195,13 +199,14 @@ class Thread
return fileName; return fileName;
} }
// Called by Record.getFileSize()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
int getFileSize () int getFileSize ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (lzw != null) // if (lzw != null)
System.out.printf ("%04X v %04X v %04X%n", compressedEOF, uncompressedEOF, // System.out.printf ("%04X v %04X v %04X%n", compressedEOF, uncompressedEOF,
lzw.getSize ()); // lzw.getSize ());
return lzw != null ? lzw.getSize () : uncompressedEOF; return lzw != null ? lzw.getSize () : uncompressedEOF;
// return uncompressedEOF; // return uncompressedEOF;
} }

View File

@ -34,7 +34,7 @@ public class Utility
public static final byte ASCII_CARET = 0x5E; public static final byte ASCII_CARET = 0x5E;
public static final List<String> suffixes = Arrays.asList ("po", "dsk", "do", "hdv", public static final List<String> suffixes = Arrays.asList ("po", "dsk", "do", "hdv",
"2mg", "v2d", "d13", "sdk", "shk", "bxy", "woz", "img", "dimg"); "2mg", "v2d", "d13", "sdk", "shk", "bxy", "bny", "woz", "img", "dimg");
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static boolean test (Graphics2D g) public static boolean test (Graphics2D g)