This commit is contained in:
Denis Molony 2021-04-18 07:32:03 +10:00
parent 49fa2903fc
commit e3ac682fc0
5 changed files with 86 additions and 84 deletions

View File

@ -146,19 +146,23 @@ public class DiskFactory
} }
} }
if ("sdk".equals (suffix)) // shrinkit disk archive if ("sdk".equals (suffix) || "shk".equals (suffix)) // shrinkit disk/file archive
{ {
if (debug) if (debug)
System.out.println (" ** sdk **"); System.out.println (" ** sdk/shk **");
try try
{ {
NuFX nuFX = new NuFX (file.toPath ()); NuFX nuFX = new NuFX (file.toPath ());
int totalDisks = nuFX.getTotalDisks (); if (nuFX.getTotalDisks () == 0 && nuFX.getTotalFiles () == 0)
if (totalDisks == 0)
return null; return null;
byte[] diskBuffer = nuFX.getDiskBuffer ();
if (diskBuffer == null)
return null;
File tmp = File.createTempFile (suffix, null); File tmp = File.createTempFile (suffix, null);
FileOutputStream fos = new FileOutputStream (tmp); FileOutputStream fos = new FileOutputStream (tmp);
fos.write (nuFX.getDiskBuffer ()); fos.write (diskBuffer);
fos.close (); fos.close ();
tmp.deleteOnExit (); tmp.deleteOnExit ();
file = tmp; file = tmp;
@ -175,38 +179,6 @@ public class DiskFactory
return null; return null;
} }
} }
else if ("shk".equals (suffix)) // shrinkit file archive
{
if (debug)
System.out.println (" ** shk **");
try
{
NuFX nuFX = new NuFX (file.toPath ());
int totalFiles = nuFX.getTotalFiles ();
// System.out.printf ("Total files: %d%n", totalFiles);
if (totalFiles == 0)
return null;
File tmp = File.createTempFile (suffix, null);
FileOutputStream fos = new FileOutputStream (tmp);
fos.write (nuFX.getDiskBuffer ());
fos.close ();
tmp.deleteOnExit ();
file = tmp;
suffix = "po";
compressed = true;
}
catch (IOException e)
{
e.printStackTrace ();
return null;
}
catch (FileFormatException e)
{
return null;
}
}
FormattedDisk disk = null; FormattedDisk disk = null;
FormattedDisk disk2 = null; FormattedDisk disk2 = null;

View File

@ -290,9 +290,7 @@ public class ProdosDisk
{ {
int nextBlock = getFreeBlock (); int nextBlock = getFreeBlock ();
if (nextBlock < 0) if (nextBlock < 0)
{ throw new DiskFullException ("Disk Full");
throw new DiskFullException ("Full");
}
volumeBitMap.set (nextBlock, false); // mark as unavailable volumeBitMap.set (nextBlock, false); // mark as unavailable

View File

@ -22,6 +22,7 @@ public class NuFX
private final List<Record> records = new ArrayList<> (); private final List<Record> records = new ArrayList<> ();
private int totalFiles; private int totalFiles;
private int totalDisks; private int totalDisks;
private int totalBlocks;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public NuFX (Path path) throws FileFormatException, IOException public NuFX (Path path) throws FileFormatException, IOException
@ -41,6 +42,11 @@ public class NuFX
for (int rec = 0; rec < masterHeader.getTotalRecords (); rec++) for (int rec = 0; rec < masterHeader.getTotalRecords (); rec++)
{ {
Record record = new Record (buffer, dataPtr); Record record = new Record (buffer, dataPtr);
if (record.getFileSystemID () != 1)
{
System.out.println ("Not Prodos");
break;
}
records.add (record); records.add (record);
if (debug) if (debug)
@ -61,7 +67,17 @@ public class NuFX
} }
if (record.hasFile ()) if (record.hasFile ())
{
++totalFiles; ++totalFiles;
int blocks = (record.getFileSize () - 1) / 512 + 1;
if (blocks == 1) // seedling
totalBlocks += blocks;
else if (blocks <= 256) // sapling
totalBlocks += blocks + 1;
else // tree
totalBlocks += blocks + (blocks / 256) + 1;
}
if (record.hasDisk ()) if (record.hasDisk ())
++totalDisks; ++totalDisks;
} }
@ -80,41 +96,53 @@ public class NuFX
} }
else if (totalFiles > 0) else if (totalFiles > 0)
{ {
try int[] diskSizes = { 280, 800, 1600, 3200, 6400, 65536 };
// System.out.printf ("Files require: %d blocks%n", totalBlocks);
for (int diskSize : diskSizes)
{ {
ProdosDisk disk = new ProdosDisk (3200, "DISKBROWSER"); // System.out.printf ("Checking %d %d%n", diskSize, totalBlocks);
int count = 0; if (diskSize < (totalBlocks + 10))
for (Record record : records) continue;
try
{ {
if (record.hasFile ()) ProdosDisk disk = new ProdosDisk (diskSize, "DISK.BROWSER");
int count = 0;
for (Record record : records)
{ {
String fileName = record.getFileName (); if (record.hasFile ())
int fileSize = record.getFileSize (); {
byte fileType = (byte) record.getFileType (); String fileName = record.getFileName ();
int eof = record.getUncompressedSize (); // int fileSize = record.getFileSize ();
int auxType = record.getAuxType (); byte fileType = (byte) record.getFileType ();
LocalDateTime created = record.getCreated (); int eof = record.getUncompressedSize ();
LocalDateTime modified = record.getModified (); int auxType = record.getAuxType ();
byte[] buffer = record.getData (); LocalDateTime created = record.getCreated ();
LocalDateTime modified = record.getModified ();
byte[] buffer = record.getData ();
System.out.printf ("%3d %-35s %,7d %02X %,7d %,7d %,7d %s %s%n", if (false)
++count, fileName, fileSize, fileType, eof, auxType, buffer.length, System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count,
created, modified); fileName, fileType, auxType, eof, buffer.length, created, modified);
disk.addFile (fileName, fileType, auxType, created, modified, buffer);
disk.addFile (fileName, fileType, auxType, created, modified, buffer);
}
} }
disk.close ();
return disk.getBuffer ();
}
catch (IOException e)
{
e.printStackTrace ();
return null;
}
catch (DiskFullException e)
{
System.out.println ("disk full: " + diskSize); // go round again
} }
disk.close ();
return disk.getBuffer ();
}
catch (IOException e)
{
e.printStackTrace ();
}
catch (DiskFullException e)
{
e.printStackTrace ();
} }
} }
@ -148,6 +176,13 @@ public class NuFX
return totalDisks; return totalDisks;
} }
// ---------------------------------------------------------------------------------//
public int getTotalBlocks ()
// ---------------------------------------------------------------------------------//
{
return totalBlocks;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private void listFiles () private void listFiles ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -179,7 +214,8 @@ public class NuFX
public static void main (String[] args) throws FileFormatException, IOException public static void main (String[] args) throws FileFormatException, IOException
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
File file = new File ("/Users/denismolony/Dropbox/Examples/SHK/DiversiCopy.3.1.shk"); File file = new File (
"/Users/denismolony/Dropbox/Examples/SHK/Disk Disintegrator Deluxe 5.0_D1.SHK");
NuFX nufx = new NuFX (file.toPath ()); NuFX nufx = new NuFX (file.toPath ());
System.out.println (nufx); System.out.println (nufx);

View File

@ -202,6 +202,13 @@ class Record
return modified.getLocalDateTime (); return modified.getLocalDateTime ();
} }
// ---------------------------------------------------------------------------------//
int getFileSystemID ()
// ---------------------------------------------------------------------------------//
{
return fileSystemID;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
int getFileSize () int getFileSize ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -195,18 +195,6 @@ public class Utility
int minute = buffer[offset + 2] & 0x3F; int minute = buffer[offset + 2] & 0x3F;
int hour = buffer[offset + 3] & 0x1F; int hour = buffer[offset + 3] & 0x1F;
if (month < 1 || month > 12)
{
System.out.printf ("Invalid month: %d%n", month);
return null;
}
if (hour > 23)
{
System.out.printf ("Invalid hour: %d%n", hour);
return null;
}
if (year < 70) if (year < 70)
year += 2000; year += 2000;
else else
@ -214,11 +202,12 @@ public class Utility
try try
{ {
return LocalDateTime.of (year, month - 1, day, hour, minute); return LocalDateTime.of (year, month, day, hour, minute);
} }
catch (DateTimeException e) catch (DateTimeException e)
{ {
System.out.println ("Bad date/time"); System.out.printf ("Bad date/time: %d %d %d %d %d %n", year, month, day, hour,
minute);
} }
} }