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

130 lines
4.6 KiB
Java
Raw Normal View History

2020-02-09 13:13:33 +00:00
package com.bytezone.diskbrowser.prodos;
2021-04-17 07:33:27 +00:00
import java.time.LocalDateTime;
2020-02-09 13:13:33 +00:00
import java.util.ArrayList;
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;
import com.bytezone.diskbrowser.utilities.HexFormatter;
2021-04-17 07:33:27 +00:00
import com.bytezone.diskbrowser.utilities.Utility;
2020-02-09 13:13:33 +00:00
// -----------------------------------------------------------------------------------//
abstract class CatalogEntry implements AppleFileSource
// -----------------------------------------------------------------------------------//
{
2023-04-07 09:50:02 +00:00
static String[] storageTypes = { "Del", "Sdl", "Sap", "Tre", "Pas", "Ext", "", "", "",
"", "", "", "", "DIR", "SDH", "VDH" };
2021-04-25 02:08:09 +00:00
Disk disk;
2020-02-09 13:13:33 +00:00
ProdosDisk parentDisk;
2021-04-25 02:08:09 +00:00
2021-04-27 11:26:09 +00:00
int blockNo;
int entryNo;
2020-02-09 13:13:33 +00:00
String name;
int storageType;
2021-04-25 02:08:09 +00:00
2021-04-17 07:33:27 +00:00
LocalDateTime created;
2020-02-09 13:13:33 +00:00
int version;
int minVersion;
int access;
2021-04-25 02:08:09 +00:00
2020-02-09 13:13:33 +00:00
List<DiskAddress> dataBlocks = new ArrayList<> ();
2021-05-14 02:19:32 +00:00
List<DiskAddress> resourceBlocks = new ArrayList<> ();
2021-04-25 02:08:09 +00:00
DirectoryHeader parentDirectory;
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2021-04-27 11:26:09 +00:00
CatalogEntry (ProdosDisk parentDisk, byte[] entryBuffer, int blockNo, int entryNo)
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
{
this.parentDisk = parentDisk;
this.disk = parentDisk.getDisk ();
2021-04-27 11:26:09 +00:00
this.blockNo = blockNo;
this.entryNo = entryNo;
2021-04-25 02:08:09 +00:00
2020-02-09 13:13:33 +00:00
name = HexFormatter.getString (entryBuffer, 1, entryBuffer[0] & 0x0F);
storageType = (entryBuffer[0] & 0xF0) >> 4;
2021-04-25 02:08:09 +00:00
created = Utility.getAppleDate (entryBuffer, 0x18);
version = entryBuffer[0x1C] & 0xFF;
minVersion = entryBuffer[0x1D] & 0xFF;
access = entryBuffer[0x1E] & 0xFF;
2020-02-09 13:13:33 +00:00
}
2021-04-27 11:26:09 +00:00
// ---------------------------------------------------------------------------------//
public String getName ()
// ---------------------------------------------------------------------------------//
{
return name;
}
// ---------------------------------------------------------------------------------//
public String getText ()
// ---------------------------------------------------------------------------------//
{
2021-05-01 23:38:24 +00:00
return String.format ("%04X:%02X %-15s %s", blockNo, entryNo, name,
storageTypes[storageType]);
2021-04-27 11:26:09 +00:00
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
@Override
public String getUniqueName ()
// ---------------------------------------------------------------------------------//
{
if (parentDirectory == null)
return name;
return parentDirectory.getUniqueName () + "/" + name;
}
// ---------------------------------------------------------------------------------//
@Override
public FormattedDisk getFormattedDisk ()
// ---------------------------------------------------------------------------------//
{
return parentDisk;
}
// ---------------------------------------------------------------------------------//
@Override
public boolean contains (DiskAddress da)
// ---------------------------------------------------------------------------------//
{
2021-04-25 02:08:09 +00:00
for (DiskAddress diskAddress : dataBlocks)
if (diskAddress.matches (da))
2020-02-09 13:13:33 +00:00
return true;
2021-05-14 02:19:32 +00:00
for (DiskAddress diskAddress : resourceBlocks)
if (diskAddress.matches (da))
return true;
2020-02-09 13:13:33 +00:00
return false;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("Name .......... %s%n", name));
2022-07-29 13:00:30 +00:00
text.append (String.format ("Access ........ %02X%n", access));
2020-02-09 13:13:33 +00:00
text.append (String.format ("Storage type... %02X%n", storageType));
text.append (String.format ("Created ....... %s%n",
2021-04-17 07:33:27 +00:00
created == null ? "" : created.format (ProdosDisk.df)));
2020-02-09 13:13:33 +00:00
text.append (String.format ("Version ....... %d%n", version));
return text.toString ();
}
// https://comp.sys.apple2.narkive.com/lOfvHRLD/prodos-storage-type-and-user-types
// Two previously unused bytes in each file's directory entry are now used to
// indicate the case of a filename. The bytes are at relative locations
// +$1C and +$1D in each directory entry, and were previously labeled version
// and min_version. Since ProDOS 8 never actually used these bytes for version
// checking (except in one case, discussed below), they are now used to store
// lowercase information. (In the Volume header, bytes +$1A and +$1B are used instead.)
2015-06-01 09:35:51 +00:00
}