allowed zip files again

This commit is contained in:
Denis Molony 2017-03-17 16:07:10 +11:00
parent f5519e3a6b
commit a8924c41b1
3 changed files with 91 additions and 17 deletions

View File

@ -36,8 +36,8 @@ public class AppleDisk implements Disk
private int interleave = 0;
private static int[][] interleaveSector = //
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // Dos
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // None
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos/Pascal
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM
@ -125,7 +125,11 @@ public class AppleDisk implements Disk
System.out.printf ("Blocks : %,d%n", blocks);
}
this.blocks = diskData / 4096 * 8; // reduce blocks to a multiple of 8
if (diskData > 0)
this.blocks = diskData / 4096 * 8; // reduce blocks to a multiple of 8
// see /Asimov disks/images/gs/os/prodos16/ProDOS 16v1_3.2mg
if (debug)
System.out.printf ("Blocks : %,d%n", blocks);
@ -443,7 +447,7 @@ public class AppleDisk implements Disk
{
if (!isValidAddress (block))
{
System.out.println ("Invalid block : " + block);
System.out.printf ("Invalid block : %d of %d%n", block, this.blocks);
return null;
// return new AppleDiskAddress (this, 0); this was looping 26/07/2016
}

View File

@ -7,7 +7,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.bytezone.diskbrowser.cpm.CPMDisk;
import com.bytezone.diskbrowser.dos.DosDisk;
@ -65,7 +68,7 @@ public class DiskFactory
in.close ();
tmp.deleteOnExit ();
suffix = Utility.getSuffix (file.getName ()); // ignores the .gz
suffix = Utility.getSuffix (file.getName ()); // ignores the .gz and .zip
file = tmp;
compressed = true;
}
@ -75,6 +78,50 @@ public class DiskFactory
return null;
}
}
else if (suffix.equals ("zip"))
{
if (debug)
System.out.println (" ** zip **");
try
{
ZipFile zipFile = new ZipFile (path);
Enumeration<? extends ZipEntry> entries = zipFile.entries ();
while (entries.hasMoreElements ()) // loop until first valid name
{
ZipEntry entry = entries.nextElement ();
System.out.println (entry.getName ());
if (Utility.validFileType (entry.getName ()))
{
InputStream stream = zipFile.getInputStream (entry);
File tmp = File.createTempFile ("zip", null);
FileOutputStream fos = new FileOutputStream (tmp);
int bytesRead;
byte[] buffer = new byte[1024];
while ((bytesRead = stream.read (buffer)) > 0)
fos.write (buffer, 0, bytesRead);
stream.close ();
fos.close ();
tmp.deleteOnExit ();
suffix = Utility.getSuffix (file.getName ()); // ignores the .gz and .zip
file = tmp;
compressed = true;
break;
}
}
zipFile.close ();
}
catch (IOException e)
{
e.printStackTrace ();
return null;
}
}
if (suffix.equals ("sdk"))
{
@ -116,7 +163,11 @@ public class DiskFactory
disk2 = check2mgDisk (file);
if (disk2 != null)
{
if (compressed)
disk2.setOriginalPath (originalPath);
return disk2;
}
AppleDisk appleDisk = new AppleDisk (file, (int) file.length () / 4096, 8);
return new DataDisk (appleDisk);
@ -128,7 +179,11 @@ public class DiskFactory
System.out.println (" ** 2mg **");
disk2 = check2mgDisk (file);
if (disk2 != null)
{
if (compressed)
disk2.setOriginalPath (originalPath);
return disk2;
}
AppleDisk appleDisk = new AppleDisk (file, (int) file.length () / 4096, 8);
return new DataDisk (appleDisk);
@ -438,20 +493,34 @@ public class DiskFactory
/*
offset | size | description
------ | ---- | -----------
+$000 | Long | The integer constant '2IMG'. This integer should be little-endian, so on the Apple IIgs, this is equivalent to the four characters 'GMI2'; in ORCA/C 2.1, you can use the integer constant '2IMG'.
+$004 | Long | A four-character tag identifying the application that created the file.
+$000 | Long | The integer constant '2IMG'. This integer should be little-endian,
so on the Apple IIgs, this is equivalent to the four characters
'GMI2'; in ORCA/C 2.1, you can use the integer constant '2IMG'.
+$004 | Long | A four-character tag identifying the application that created the
file.
+$008 | Word | The length of this header, in bytes. Should be 52.
+$00A | Word | The version number of the image file format. Should be 1.
+$00C | Long | The image format. See table below.
+$010 | Long | Flags. See table below.
+$014 | Long | The number of 512-byte blocks in the disk image. This value should be zero unless the image format is 1 (ProDOS order).
+$018 | Long | Offset to the first byte of the first block of the disk in the image file, from the beginning of the file. The disk data must come before the comment and creator-specific chunks.
+$01C | Long | Length of the disk data in bytes. This should be the number of blocks * 512.
+$020 | Long | Offset to the first byte of the image comment. Can be zero if there's no comment. The comment must come after the data chunk, but before the creator-specific chunk. The comment, if it exists, should be raw text; no length byte or C-style null terminator byte is required (that's what the next field is for).
+$014 | Long | The number of 512-byte blocks in the disk image. This value should
be zero unless the image format is 1 (ProDOS order).
+$018 | Long | Offset to the first byte of the first block of the disk in the image
file, from the beginning of the file. The disk data must come before
the comment and creator-specific chunks.
+$01C | Long | Length of the disk data in bytes. This should be the number of
blocks * 512.
+$020 | Long | Offset to the first byte of the image comment. Can be zero if
there's no comment. The comment must come after the data chunk, but
before the creator-specific chunk. The comment, if it exists, should
be raw text; no length byte or C-style null terminator byte is
required (that's what the next field is for).
+$024 | Long | Length of the comment chunk. Zero if there's no comment.
+$028 | Long | Offset to the first byte of the creator-specific data chunk, or zero if there is none.
+$02C | Long | Length of the creator-specific chunk; zero if there is no creator-specific data.
+$030 | 16 bytes | Reserved space; this pads the header to 64 bytes. These values must all be zero.
+$028 | Long | Offset to the first byte of the creator-specific data chunk, or zero
if there is none.
+$02C | Long | Length of the creator-specific chunk; zero if there is no
creator-specific data.
+$030 | 16 bytes | Reserved space; this pads the header to 64 bytes. These values
must all be zero.
*/
private static FormattedDisk check2mgDisk (File file)
@ -462,11 +531,12 @@ public class DiskFactory
try
{
AppleDisk disk = new AppleDisk (file, 0, 0);
if (ProdosDisk.isCorrectFormat (disk))
if (disk.getTotalBlocks () > 0 && ProdosDisk.isCorrectFormat (disk))
return new ProdosDisk (disk);
}
catch (Exception e)
{
System.out.println (e);
}
if (debug)
System.out.println ("Not a Prodos 2mg disk");

View File

@ -12,11 +12,11 @@ public class InterleaveAction extends DefaultAction
{
int interleave;
FormattedDisk currentDisk;
static String[] names = { "DOS", "Prodos", "Infocom", "CPM" };
static String[] names = { "No Interleave", "Prodos/Pascal", "Infocom", "CPM" };
public InterleaveAction (int interleave)
{
super (names[interleave] + " interleave", "Alter interleave");
super (names[interleave], "Alter interleave");
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt " + interleave));
this.interleave = interleave;
}