sparse file bug

This commit is contained in:
Denis Molony 2017-01-27 10:59:47 +11:00
parent c08a234fb3
commit 0c8f92a862
2 changed files with 19 additions and 6 deletions

View File

@ -22,6 +22,8 @@ public class SHRPictureFile extends HiResImage
while (ptr < buffer.length) while (ptr < buffer.length)
{ {
int len = HexFormatter.unsignedLong (buffer, ptr); int len = HexFormatter.unsignedLong (buffer, ptr);
if (len == 0)
break;
// int nameLen = buffer[ptr + 4] & 0xFF; // int nameLen = buffer[ptr + 4] & 0xFF;
String kind = HexFormatter.getPascalString (buffer, ptr + 4); String kind = HexFormatter.getPascalString (buffer, ptr + 4);
byte[] data = new byte[Math.min (len, buffer.length - ptr)]; byte[] data = new byte[Math.min (len, buffer.length - ptr)];

View File

@ -172,6 +172,9 @@ class FileEntry extends CatalogEntry implements ProdosConstants
parentDisk.setSectorType (keyBlock, parentDisk.indexSector); parentDisk.setSectorType (keyBlock, parentDisk.indexSector);
indexBlocks.add (disk.getDiskAddress (keyBlock)); indexBlocks.add (disk.getDiskAddress (keyBlock));
byte[] buffer = disk.readSector (keyBlock); byte[] buffer = disk.readSector (keyBlock);
int maxBlocks = (endOfFile - 1) / 512 + 1;
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); int block = HexFormatter.intValue (buffer[i], buffer[i + 256]);
@ -181,12 +184,13 @@ class FileEntry extends CatalogEntry implements ProdosConstants
invalid = true; invalid = true;
break; break;
} }
// System.out.printf ("%4d %02X %02X%n", block, fileType, auxType);
// should we break if block == 0 and it's not a text file? if (dataBlocks.size () == maxBlocks)
// if (block == 0 && !(fileType == ProdosConstants.FILE_TYPE_TEXT && auxType > 0)) break;
// if (block == 0 && fileType != 4)
// break; if (block == 0)
if (block != 0) dataBlocks.add (null); // allow for sparse image files
else
{ {
parentDisk.setSectorType (block, parentDisk.dataSector); parentDisk.setSectorType (block, parentDisk.dataSector);
dataBlocks.add (disk.getDiskAddress (block)); dataBlocks.add (disk.getDiskAddress (block));
@ -232,11 +236,13 @@ class FileEntry extends CatalogEntry implements ProdosConstants
{ {
if (file != null) if (file != null)
return file; return file;
if (invalid) if (invalid)
{ {
file = new DefaultAppleFile (name, null); file = new DefaultAppleFile (name, null);
return file; return file;
} }
/* /*
* Text files with reclen > 0 are random access, possibly with gaps between * Text files with reclen > 0 are random access, possibly with gaps between
* records, so they need to be handled separately. * records, so they need to be handled separately.
@ -432,6 +438,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants
} }
if (buffers.size () == 1 && name.endsWith (".S")) if (buffers.size () == 1 && name.endsWith (".S"))
return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile); return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile);
return new TextFile (name, buffers, auxType, endOfFile); return new TextFile (name, buffers, auxType, endOfFile);
} }
@ -440,8 +447,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants
List<TextBuffer> buffers = new ArrayList<TextBuffer> (); List<TextBuffer> buffers = new ArrayList<TextBuffer> ();
List<DiskAddress> addresses = new ArrayList<DiskAddress> (); List<DiskAddress> addresses = new ArrayList<DiskAddress> ();
readIndexBlock (keyPtr, addresses, buffers, 0); readIndexBlock (keyPtr, addresses, buffers, 0);
if (buffers.size () == 1 && name.endsWith (".S")) if (buffers.size () == 1 && name.endsWith (".S"))
return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile); return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile);
return new TextFile (name, buffers, auxType, endOfFile); return new TextFile (name, buffers, auxType, endOfFile);
} }
@ -454,8 +463,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants
System.arraycopy (buffer, 0, exactBuffer, 0, endOfFile); System.arraycopy (buffer, 0, exactBuffer, 0, endOfFile);
buffer = exactBuffer; buffer = exactBuffer;
} }
if (name.endsWith (".S")) if (name.endsWith (".S"))
return new MerlinSource (name, buffer, auxType, endOfFile); return new MerlinSource (name, buffer, auxType, endOfFile);
return new TextFile (name, buffer, auxType, endOfFile); return new TextFile (name, buffer, auxType, endOfFile);
} }