dmolony-DiskBrowser/src/com/bytezone/diskbrowser/utilities/NuFX.java

85 lines
2.6 KiB
Java
Raw Normal View History

2016-02-24 21:11:14 +00:00
package com.bytezone.diskbrowser.utilities;
2015-06-01 09:35:51 +00:00
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
2020-02-07 23:26:38 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
public class NuFX
2020-02-07 23:26:38 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2016-12-15 00:01:42 +00:00
private Header header;
2015-06-01 09:35:51 +00:00
private final byte[] buffer;
private final boolean debug = false;
2020-02-02 10:17:49 +00:00
private final List<Record> records = new ArrayList<> ();
private final List<Thread> threads = new ArrayList<> ();
2015-06-01 09:35:51 +00:00
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
public NuFX (Path path) throws FileFormatException, IOException
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
buffer = Files.readAllBytes (path);
2016-12-15 00:01:42 +00:00
readBuffer ();
}
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2016-12-15 00:01:42 +00:00
private void readBuffer ()
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2016-12-15 00:01:42 +00:00
{
2015-06-01 09:35:51 +00:00
header = new Header (buffer);
int dataPtr = 48;
if (header.bin2)
dataPtr += 128;
if (debug)
System.out.printf ("%s%n%n", header);
2021-03-29 01:04:01 +00:00
for (int rec = 0; rec < header.getTotalRecords (); rec++)
2015-06-01 09:35:51 +00:00
{
2021-03-29 01:04:01 +00:00
Record record = new Record (buffer, dataPtr);
2015-06-01 09:35:51 +00:00
records.add (record);
if (debug)
System.out.printf ("Record: %d%n%n%s%n%n", rec, record);
2021-03-29 01:04:01 +00:00
dataPtr += record.getAttributes () + record.getFileNameLength ();
2015-06-01 09:35:51 +00:00
int threadsPtr = dataPtr;
2021-03-29 01:04:01 +00:00
dataPtr += record.getTotalThreads () * 16;
2015-06-01 09:35:51 +00:00
2021-03-29 01:04:01 +00:00
for (int i = 0; i < record.getTotalThreads (); i++)
2015-06-01 09:35:51 +00:00
{
Thread thread = new Thread (buffer, threadsPtr + i * 16, dataPtr);
threads.add (thread);
dataPtr += thread.getCompressedEOF ();
if (debug)
System.out.printf ("Thread: %d%n%n%s%n%n", i, thread);
}
}
}
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
public byte[] getBuffer ()
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
for (Thread thread : threads)
if (thread.hasDisk ())
return thread.getData ();
return null;
}
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
public String toString ()
2020-02-07 23:26:38 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
for (Thread thread : threads)
if (thread.hasDisk ())
return thread.toString ();
return "no disk";
}
}