Header i/o complete for read routine. todo: lift file i/o from Watto

This commit is contained in:
Downforce Agent 2024-10-07 17:34:18 -05:00
parent 754a4cdbc2
commit 035013dee6
3 changed files with 64 additions and 21 deletions

View File

@ -9,8 +9,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="cf74c012-cc69-4732-ac79-9ddfcbf803ee" name="Changes" comment="Going to bowling">
<list default="true" id="cf74c012-cc69-4732-ac79-9ddfcbf803ee" name="Changes" comment="I forgot you can just type hex numbers in java ._.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/net/screwgravity/vitality4j/standalone.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/net/screwgravity/vitality4j/standalone.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/net/screwgravity/vitality4j/tools.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/net/screwgravity/vitality4j/tools.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -175,7 +176,15 @@
<option name="project" value="LOCAL" />
<updated>1728338443139</updated>
</task>
<option name="localTasksCounter" value="12" />
<task id="LOCAL-00012" summary="I forgot you can just type hex numbers in java ._.">
<option name="closed" value="true" />
<created>1728338552620</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1728338552620</updated>
</task>
<option name="localTasksCounter" value="13" />
<servers />
</component>
<component name="VcsManagerConfiguration">
@ -190,6 +199,7 @@
<MESSAGE value="start i/o logic, CLI is partial atm" />
<MESSAGE value="The compiler fucked itself" />
<MESSAGE value="Going to bowling" />
<option name="LAST_COMMIT_MESSAGE" value="Going to bowling" />
<MESSAGE value="I forgot you can just type hex numbers in java ._." />
<option name="LAST_COMMIT_MESSAGE" value="I forgot you can just type hex numbers in java ._." />
</component>
</project>

View File

@ -151,11 +151,6 @@ public class standalone {
i++;
}
if (verbosity != Verbosities.QUIET) {
System.out.println("INFO: absolute mode is " + makeAbsolute);
System.out.println("INFO: case insensitive mode is " + makeCaseInsensitive);
}
if (operation.isEmpty()) {
operation = "-i";
}
@ -164,10 +159,26 @@ public class standalone {
case "-i":
try {
PSARC psarc = new PSARC(new File (targetPath)); // System.getProperty("user.dir") + File.separator +
System.out.println("PSARC version " + psarc.version[0] + "." + psarc.version[1] + "." + psarc.version[2] + "." + psarc.version[3]);
String comp = "nothing";
if (psarc.algorithm == CompressionFormats.ZLIB) {comp = "ZLIB";} else if (psarc.algorithm == CompressionFormats.LZMA) {comp = "LZMA";}
System.out.println("Compressed with " + comp);
if (verbosity != Verbosities.QUIET) {
System.out.println("PSARC version " + psarc.version[0] + "." + psarc.version[1] + "." + psarc.version[2] + "." + psarc.version[3]);
boolean isAbsolute = false;
boolean isCaseInsensitive = false;
if (psarc.mode == tools.Scotty.PathModes.ABSOLUTE ||
psarc.mode == tools.Scotty.PathModes.IGNORE_CASE_ABSOLUTE) {isAbsolute = true;}
if (psarc.mode == tools.Scotty.PathModes.IGNORE_CASE ||
psarc.mode == tools.Scotty.PathModes.IGNORE_CASE_ABSOLUTE) {isCaseInsensitive = true;}
System.out.println("INFO: absolute mode is " + isAbsolute);
System.out.println("INFO: case insensitive mode is " + isCaseInsensitive);
String comp = "nothing";
if (psarc.algorithm == CompressionFormats.ZLIB) {comp = "ZLIB";} else if (psarc.algorithm == CompressionFormats.LZMA) {comp = "LZMA";}
System.out.println("INFO: Compressed with " + comp);
if (verbosity == Verbosities.VERBOSE) {
System.out.println("INFO: block size at " + psarc.blockSize);
System.out.println("INFO: TOC is " + psarc.toc_length + " bytes total containing " +
psarc.toc_number_of_entries + " files.\nINFO: Each TOC entry is " +
psarc.toc_entry_length + " bytes long.");
}
}
System.exit(0);
} catch (Exception e) {
System.out.println("Error reading file \"" + targetPath + "\".\n" + e.getMessage());

View File

@ -32,7 +32,8 @@ public class tools {
public enum PathModes {
RELATIVE(0),
IGNORE_CASE(1),
ABSOLUTE(2);
ABSOLUTE(2),
IGNORE_CASE_ABSOLUTE(3);
private final int value;
PathModes(final int value) {this.value = value;}
@ -69,11 +70,13 @@ public class tools {
public byte[] version = new byte[]{0, 0, 0, 0}; // fixed length of 32 bits
public CompressionFormats algorithm = CompressionFormats.ZLIB; // the algorithm used to compress the files
public byte strength = 9; // intensity of the compression algorithm from 0 to 9
public long blockSize = 65536;
public int blockSize = 65536;
public PathModes mode = PathModes.RELATIVE;
private RandomAccessFile fromDisk = null; // if NULL then file is a new file
private List<CompressedFile> files = new ArrayList<CompressedFile>();
private int toc_length = 0;
public List<CompressedFile> files = new ArrayList<CompressedFile>();
public int toc_length = 0;
public int toc_entry_length = 30;
public int toc_number_of_entries = 0;
public PSARC() { // new w/ defaults
// use defaults, do nothing
@ -93,8 +96,9 @@ public class tools {
// ok, it is safe to continue
fromDisk.seek(4);
fromDisk.read(version);
fromDisk.read(version); // get version
// get algorithm
byte[] algorithm_cast = new byte[]{0, 0, 0, 0};
byte[] header_zlib = new byte[]{0x7A, 0x6C, 0x69, 0x62};
byte[] header_lzma = new byte[]{0x6C, 0x7A, 0x6D, 0x61};
@ -103,9 +107,27 @@ public class tools {
else if (Arrays.equals(algorithm_cast, header_lzma)) {algorithm = CompressionFormats.LZMA;}
else {throw new IncorrectFileTypeException("Unrecognized or unimplemented compression algorithm.");}
byte[] toc_length_cast = new byte[]{0, 0, 0, 0};
fromDisk.read(toc_length_cast);
//toc_length = (int)toc_length_cast;
// get toc size and entry size
toc_length = fromDisk.readInt();
toc_entry_length = fromDisk.readInt();
toc_number_of_entries = fromDisk.readInt();
blockSize = fromDisk.readInt();
int raw_af = fromDisk.readInt(); // RAW AS FUCK!!!!!!!!!!!!!!!!!!!!!!!!!
switch (raw_af) { // thanks java for not allowing me to use my int -> enum cast for no reason
case 0:
mode = PathModes.RELATIVE;
break;
case 1:
mode = PathModes.IGNORE_CASE;
break;
case 2:
mode = PathModes.ABSOLUTE;
break;
case 3:
mode = PathModes.IGNORE_CASE_ABSOLUTE;
break;
}
}
public PSARC(CompressionFormats algorithm, byte strength) { // new
@ -113,7 +135,7 @@ public class tools {
this.strength = strength;
}
public PSARC(CompressionFormats algorithm, byte strength, long blockSize) { // new
public PSARC(CompressionFormats algorithm, byte strength, int blockSize) { // new
this.algorithm = algorithm;
this.strength = strength;
this.blockSize = blockSize;