display file list

This commit is contained in:
Denis Molony 2016-02-25 12:27:22 +11:00
parent 1d7b12bcc9
commit 82c14fb8c3
4 changed files with 80 additions and 34 deletions

View File

@ -4,12 +4,9 @@ import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.applefile.BootSector;
import com.bytezone.diskbrowser.disk.AbstractFormattedDisk;
import com.bytezone.diskbrowser.disk.AppleDisk;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.disk.*;
public class CPMDisk extends AbstractFormattedDisk
{
@ -56,7 +53,7 @@ public class CPMDisk extends AbstractFormattedDisk
}
}
}
listEntries ();
// listEntries ();
}
@Override
@ -81,19 +78,36 @@ public class CPMDisk extends AbstractFormattedDisk
return null;
}
@Override
public AppleFileSource getCatalog ()
{
String newLine = String.format ("%n");
String line = "--- --------- ----" + newLine;
StringBuilder text = new StringBuilder ();
text.append (String.format ("Disk : %s%n%n", getAbsolutePath ()));
text.append ("User Name Type" + newLine);
text.append (line);
for (DirectoryEntry entry : directoryEntries)
{
text.append (entry.line ());
text.append (newLine);
}
return new DefaultAppleFileSource ("CPM Disk ", text.toString (), this);
}
public static boolean isCorrectFormat (AppleDisk disk)
{
disk.setInterleave (3);
byte[] buffer = disk.readSector (0, 8);
String text = new String (buffer, 16, 24);
System.out.println (text);
if ("DIR ERA TYPESAVEREN USER".equals (text))
return true;
buffer = disk.readSector (0, 4);
text = new String (buffer, 16, 24);
System.out.println (text);
if ("DIR ERA TYPESAVEREN USER".equals (text))
return true;
@ -105,8 +119,6 @@ public class CPMDisk extends AbstractFormattedDisk
int val = buffer[i] & 0xFF;
if (val > 31 && val != 0xE5)
return false;
// if (buffer[i] == 0)
// System.out.println (new DirectoryEntry (buffer, i));
}
}

View File

@ -3,9 +3,13 @@ package com.bytezone.diskbrowser.cpm;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class DirectoryEntry
public class DirectoryEntry implements AppleFileSource
{
private final int userNumber;
private final String name;
@ -40,6 +44,11 @@ public class DirectoryEntry
entries.add (entry);
}
public String line ()
{
return name + "." + type;
}
@Override
public String toString ()
{
@ -65,4 +74,28 @@ public class DirectoryEntry
return text.toString ();
}
@Override
public String getUniqueName ()
{
return name + "." + type;
}
@Override
public DataSource getDataSource ()
{
return null;
}
@Override
public List<DiskAddress> getSectors ()
{
return null;
}
@Override
public FormattedDisk getFormattedDisk ()
{
return null;
}
}

View File

@ -25,7 +25,6 @@ public class AppleDisk implements Disk
public final File path;
private final byte[] diskBuffer; // contains the disk contents in memory
private int skip = 0;
private final int tracks; // usually 35 for floppy disks
private int sectors; // 8 or 16
@ -64,6 +63,7 @@ public class AppleDisk implements Disk
byte[] buffer = getPrefix (path); // HDV could be a 2mg
String prefix = new String (buffer, 0, 4);
int skip = 0;
if ((pos > 0 && name.substring (pos + 1).equalsIgnoreCase ("2mg"))
|| "2IMG".equals (prefix))
@ -424,19 +424,19 @@ public class AppleDisk implements Disk
assert sectorSize == 256 || sectorSize == 512 : "Invalid sector size : " + sectorSize;
assert interleave >= 0 && interleave <= MAX_INTERLEAVE : "Invalid interleave : "
+ interleave;
int diskOffset;
if (sectorSize == 256)
{
diskOffset = da.getTrack () * trackSize
int diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector ()] * sectorSize;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, sectorSize);
}
else if (sectorSize == 512)
{
diskOffset = da.getTrack () * trackSize
int diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector () * 2] * 256;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, 256);
diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector () * 2 + 1] * 256;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset + 256, 256);

View File

@ -49,10 +49,10 @@ public class DosDisk extends AbstractFormattedDisk
sectorTypesList.add (tsListSector);
sectorTypesList.add (dataSector);
byte[] sectorBuffer = disk.readSector (0, 0); // Boot sector
byte[] sectorBuffer = disk.readSector (0, 0); // Boot sector
bootSector = new BootSector (disk, sectorBuffer, "DOS");
sectorBuffer = disk.readSector (CATALOG_TRACK, 0); // VTOC
sectorBuffer = disk.readSector (CATALOG_TRACK, 0); // VTOC
dosVTOCSector = new DosVTOCSector (this, disk, sectorBuffer);
DiskAddress catalogStart = disk.getDiskAddress (sectorBuffer[1], sectorBuffer[2]);
@ -92,7 +92,8 @@ public class DosDisk extends AbstractFormattedDisk
// See beautifulboot.dsk.
if (sectorBuffer[0] != 0 && (sectorBuffer[0] & 0xFF) != 0xFF && false)
{
System.out.println ("Dos catalog sector buffer byte #0 invalid : " + sectorBuffer[0]);
System.out
.println ("Dos catalog sector buffer byte #0 invalid : " + sectorBuffer[0]);
break;
}
@ -132,7 +133,8 @@ public class DosDisk extends AbstractFormattedDisk
if (entry[0] == (byte) 0xFF) // deleted file
{
DeletedCatalogEntry deletedCatalogEntry = new DeletedCatalogEntry (this, da, entry);
DeletedCatalogEntry deletedCatalogEntry =
new DeletedCatalogEntry (this, da, entry);
deletedFileEntries.add (deletedCatalogEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (deletedCatalogEntry);
node.setAllowsChildren (false);
@ -341,8 +343,8 @@ public class DosDisk extends AbstractFormattedDisk
if (type == catalogSector)
return new DosCatalogSector (disk, buffer);
if (type == dataSector)
return new DefaultSector ("Data Sector at " + address + " : " + getSectorFilename (da),
disk, buffer);
return new DefaultSector (
"Data Sector at " + address + " : " + getSectorFilename (da), disk, buffer);
if (type == dosSector)
return new DefaultSector ("DOS sector at " + address, disk, buffer);
return super.getFormattedSector (da);
@ -369,35 +371,34 @@ public class DosDisk extends AbstractFormattedDisk
public AppleFileSource getCatalog ()
{
String newLine = String.format ("%n");
String line =
"- --- --- ------------------------------ ----- -------------"
+ " -- ---- ----------------" + newLine;
String line = "- --- --- ------------------------------ ----- -------------"
+ " -- ---- ----------------" + newLine;
StringBuilder text = new StringBuilder ();
text.append (String.format ("Disk : %s%n%n", getAbsolutePath ()));
text.append ("L Typ Len Name Addr"
+ " Length TS Data Comment" + newLine);
+ " Length TS Data Comment" + newLine);
text.append (line);
for (AppleFileSource ce : fileEntries)
text.append (((CatalogEntry) ce).getDetails () + newLine);
text.append (line);
text.append (String
.format (" Free sectors: %3d Used sectors: %3d Total sectors: %3d",
dosVTOCSector.freeSectors, dosVTOCSector.usedSectors,
(dosVTOCSector.freeSectors + dosVTOCSector.usedSectors)));
text.append (String.format (
" Free sectors: %3d Used sectors: %3d Total sectors: %3d",
dosVTOCSector.freeSectors, dosVTOCSector.usedSectors,
(dosVTOCSector.freeSectors + dosVTOCSector.usedSectors)));
if (dosVTOCSector.freeSectors != freeSectors)
text.append (String
.format ("%nActual: Free sectors: %3d Used sectors: %3d Total sectors: %3d",
freeSectors, usedSectors, (usedSectors + freeSectors)));
text.append (String.format (
"%nActual: Free sectors: %3d Used sectors: %3d Total sectors: %3d",
freeSectors, usedSectors, (usedSectors + freeSectors)));
return new DefaultAppleFileSource ("Volume " + dosVTOCSector.volume, text.toString (),
this);
this);
}
private AppleFileSource getDeletedList ()
{
StringBuilder text =
new StringBuilder ("List of files that were deleted from this disk\n");
new StringBuilder ("List of files that were deleted from this disk\n");
for (AppleFileSource afs : deletedFileEntries)
text.append (((DeletedCatalogEntry) afs).getDetails () + "\n");