2016-02-25 09:23:08 +00:00
|
|
|
package com.bytezone.diskbrowser.pascal;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
|
|
|
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
|
|
|
import com.bytezone.diskbrowser.disk.Disk;
|
|
|
|
import com.bytezone.diskbrowser.disk.DiskAddress;
|
|
|
|
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
|
|
|
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
|
|
|
|
|
|
|
abstract class CatalogEntry implements AppleFileSource
|
|
|
|
{
|
2016-08-14 08:41:19 +00:00
|
|
|
protected AbstractFile file;
|
2016-02-25 09:23:08 +00:00
|
|
|
protected final PascalDisk parent;
|
2016-08-14 08:41:19 +00:00
|
|
|
protected String name;
|
|
|
|
protected int firstBlock;
|
|
|
|
protected int lastBlock; // block AFTER last used block
|
|
|
|
protected int fileType;
|
|
|
|
protected GregorianCalendar date;
|
|
|
|
protected int bytesUsedInLastBlock;
|
2019-11-01 03:30:19 +00:00
|
|
|
protected final List<DiskAddress> blocks = new ArrayList<> ();
|
2016-02-25 09:23:08 +00:00
|
|
|
|
|
|
|
public CatalogEntry (PascalDisk parent, byte[] buffer)
|
|
|
|
{
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
|
|
firstBlock = HexFormatter.intValue (buffer[0], buffer[1]);
|
|
|
|
lastBlock = HexFormatter.intValue (buffer[2], buffer[3]);
|
2017-03-20 02:50:41 +00:00
|
|
|
fileType = buffer[4] & 0xFF;
|
2016-02-25 09:23:08 +00:00
|
|
|
name = HexFormatter.getPascalString (buffer, 6);
|
2016-08-02 10:37:27 +00:00
|
|
|
bytesUsedInLastBlock = HexFormatter.intValue (buffer[16], buffer[17]);
|
2016-02-25 09:23:08 +00:00
|
|
|
|
|
|
|
Disk disk = parent.getDisk ();
|
2016-08-14 08:41:19 +00:00
|
|
|
int max = Math.min (lastBlock, disk.getTotalBlocks ());
|
|
|
|
for (int i = firstBlock; i < max; i++)
|
2016-02-25 09:23:08 +00:00
|
|
|
blocks.add (disk.getDiskAddress (i));
|
|
|
|
}
|
|
|
|
|
2016-02-25 21:49:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean contains (DiskAddress da)
|
2016-02-25 09:23:08 +00:00
|
|
|
{
|
|
|
|
for (DiskAddress sector : blocks)
|
2016-07-19 01:24:36 +00:00
|
|
|
if (sector.matches (da))
|
2016-02-25 09:23:08 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<DiskAddress> getSectors ()
|
|
|
|
{
|
2019-11-01 03:30:19 +00:00
|
|
|
List<DiskAddress> sectors = new ArrayList<> (blocks);
|
2016-02-25 09:23:08 +00:00
|
|
|
return sectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FormattedDisk getFormattedDisk ()
|
|
|
|
{
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUniqueName ()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2016-08-14 08:41:19 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString ()
|
|
|
|
{
|
|
|
|
int size = lastBlock - firstBlock;
|
2017-03-20 02:50:41 +00:00
|
|
|
String fileTypeText = fileType < 0 || fileType >= parent.fileTypes.length ? "????"
|
|
|
|
: parent.fileTypes[fileType];
|
|
|
|
return String.format ("%03d %s %-15s", size, fileTypeText, name);
|
2016-08-14 08:41:19 +00:00
|
|
|
}
|
2016-02-25 09:23:08 +00:00
|
|
|
}
|