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

74 lines
2.0 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.prodos;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.FormattedDisk;
2016-02-24 21:11:14 +00:00
import com.bytezone.diskbrowser.utilities.HexFormatter;
2015-06-01 09:35:51 +00:00
abstract class CatalogEntry implements AppleFileSource
{
2016-03-24 00:17:09 +00:00
ProdosDisk parentDisk;
2016-02-05 00:23:53 +00:00
DirectoryHeader parentDirectory;
String name;
int storageType;
GregorianCalendar created;
int version;
int minVersion;
int access;
2019-11-01 03:30:19 +00:00
List<DiskAddress> dataBlocks = new ArrayList<> ();
2016-02-05 00:23:53 +00:00
Disk disk;
2015-06-01 09:35:51 +00:00
2016-02-05 00:23:53 +00:00
public CatalogEntry (ProdosDisk parentDisk, byte[] entryBuffer)
{
this.parentDisk = parentDisk;
this.disk = parentDisk.getDisk ();
name = HexFormatter.getString (entryBuffer, 1, entryBuffer[0] & 0x0F);
storageType = (entryBuffer[0] & 0xF0) >> 4;
created = HexFormatter.getAppleDate (entryBuffer, 24);
2016-12-17 22:07:55 +00:00
version = entryBuffer[28] & 0xFF;
minVersion = entryBuffer[29] & 0xFF;
access = entryBuffer[30] & 0xFF;
2016-02-05 00:23:53 +00:00
}
2015-06-01 09:35:51 +00:00
2016-02-05 00:23:53 +00:00
@Override
public String getUniqueName ()
{
if (parentDirectory == null)
return name;
return parentDirectory.getUniqueName () + "/" + name;
}
2015-06-01 09:35:51 +00:00
2016-02-05 00:23:53 +00:00
@Override
public FormattedDisk getFormattedDisk ()
{
return parentDisk;
}
2016-02-25 21:49:22 +00:00
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : dataBlocks)
if (sector.matches (da))
2016-02-25 21:49:22 +00:00
return true;
return false;
}
2017-01-20 04:07:08 +00:00
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("Name .......... %s%n", name));
text.append (String.format ("Storage type... %02X%n", storageType));
text.append (String.format ("Created ....... %s%n",
created == null ? "" : parentDisk.df.format (created.getTime ())));
text.append (String.format ("Version ....... %d%n", version));
return text.toString ();
}
2015-06-01 09:35:51 +00:00
}