dmolony-DiskBrowser/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java

95 lines
3.4 KiB
Java
Raw Normal View History

2016-02-25 09:23:08 +00:00
package com.bytezone.diskbrowser.pascal;
2022-05-11 00:09:27 +00:00
import java.time.LocalDate;
2016-02-25 09:23:08 +00:00
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;
import com.bytezone.diskbrowser.utilities.Utility;
2016-02-25 09:23:08 +00:00
2020-02-09 13:13:33 +00:00
// -----------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
abstract class CatalogEntry implements AppleFileSource
2020-02-09 13:13:33 +00:00
// -----------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
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;
2022-05-11 00:09:27 +00:00
protected LocalDate localDate;
2016-08-14 08:41:19 +00:00
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
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
CatalogEntry (PascalDisk parent, byte[] buffer)
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
this.parent = parent;
firstBlock = Utility.getShort (buffer, 0);
lastBlock = Utility.getShort (buffer, 2);
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);
bytesUsedInLastBlock = Utility.getShort (buffer, 16);
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));
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 21:49:22 +00:00
@Override
public boolean contains (DiskAddress da)
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
for (DiskAddress sector : blocks)
if (sector.matches (da))
2016-02-25 09:23:08 +00:00
return true;
2022-03-28 03:55:49 +00:00
2016-02-25 09:23:08 +00:00
return false;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public List<DiskAddress> getSectors ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
2020-10-28 08:26:29 +00:00
return new ArrayList<> (blocks); // make a copy
2016-02-25 09:23:08 +00:00
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public FormattedDisk getFormattedDisk ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
return parent;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public String getUniqueName ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
return name;
}
2016-08-14 08:41:19 +00:00
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-08-14 08:41:19 +00:00
@Override
public String toString ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-08-14 08:41:19 +00:00
{
int size = lastBlock - firstBlock;
2022-03-28 03:55:49 +00:00
String fileTypeText =
fileType < 0 || fileType >= parent.fileTypes.length ? "????" : parent.fileTypes[fileType];
2017-03-20 02:50:41 +00:00
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
}