diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c1225a3..90ddf11 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -11,6 +11,8 @@
+
+
@@ -18,6 +20,13 @@
+
+
+
@@ -123,7 +132,15 @@
1723521528643
-
+
+
+ 1723524380202
+
+
+
+ 1723524380202
+
+
diff --git a/net/screwgravity/vitality4j/June.java b/net/screwgravity/vitality4j/June.java
deleted file mode 100644
index 107b98c..0000000
--- a/net/screwgravity/vitality4j/June.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package net.screwgravity.vitality4j;
-
-public class June {
- // todo
-}
diff --git a/net/screwgravity/vitality4j/Scotty.java b/net/screwgravity/vitality4j/Scotty.java
deleted file mode 100644
index 3994d5a..0000000
--- a/net/screwgravity/vitality4j/Scotty.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package net.screwgravity.vitality4j;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Scotty {
- public enum CompressionFormats {
- NONE(0),
- ZLIB(1),
- LZMA(2);
-
- private final int value;
- CompressionFormats(final int value) {this.value = value;}
-
- public int getValue() {
- return value;
- }
- }
-
- public enum PathModes {
- RELATIVE(0),
- IGNORE_CASE(1),
- ABSOLUTE(2);
-
- private final int value;
- PathModes(final int value) {this.value = value;}
-
- public int getValue() {
- return value;
- }
- }
-
- public class CompressedFile {
- private final PSARC container;
- private final String path;
- public CompressionFormats algorithm = null; // if NULL then it inherits the value from the entire PSARC file
-
- public CompressedFile(PSARC container, String path) {
- this.container = container;
- this.path = path;
- }
-
- public PSARC getContainer() {
- return container;
- }
-
- public String getLocationInArchive() {
- return path;
- }
-
- public InputStream getIOStream() {
- throw new UnsupportedOperationException();
- }
- }
-
- public class PSARC {
- 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 PathModes mode = PathModes.RELATIVE;
- private RandomAccessFile fromDisk = null; // if NULL then file is a new file
- private List files = new ArrayList();
-
- public PSARC() { // new w/ defaults
- // use defaults, do nothing
- }
-
- public PSARC(File location) throws IOException { // existing
- // todo: read psarc and set vars above
- fromDisk = new RandomAccessFile(location, "r"); // mode will be changed retroactively with a new RandomAccessFile if we ever need to make writes
- System.out.println(fromDisk.read(version, 4, 4));
-
- }
-
- public PSARC(CompressionFormats algorithm, byte strength) { // new
- this.algorithm = algorithm;
- this.strength = strength;
- }
-
- public PSARC(CompressionFormats algorithm, byte strength, long blockSize) { // new
- this.algorithm = algorithm;
- this.strength = strength;
- this.blockSize = blockSize;
- }
-
- public List listAllFiles() {
- return files;
- }
-
- public String[] listAllFilePaths() {
- throw new UnsupportedOperationException();
- }
-
- public boolean addFile(File input) {
- throw new UnsupportedOperationException();
- }
-
- public boolean writeOut(File destination) {
- throw new UnsupportedOperationException();
- }
-
- public boolean extractAll(File destination) {
- throw new UnsupportedOperationException();
- }
-
- public boolean extractSingleFile(CompressedFile target, File destination) {
- throw new UnsupportedOperationException();
- }
-
- public boolean extractMultipleFiles(List targets, File directory) {
- throw new UnsupportedOperationException();
- }
- }
-
-
-}
diff --git a/net/screwgravity/vitality4j/standalone.java b/net/screwgravity/vitality4j/standalone.java
index 47ab427..23666bc 100644
--- a/net/screwgravity/vitality4j/standalone.java
+++ b/net/screwgravity/vitality4j/standalone.java
@@ -1,5 +1,11 @@
package net.screwgravity.vitality4j;
+import net.screwgravity.vitality4j.tools.Scotty.CompressionFormats;
+import net.screwgravity.vitality4j.tools.Scotty.PSARC;
+
+import java.io.File;
+import java.io.IOException;
+
public class standalone {
public static boolean fromTerminal = false;
public static final int[] version = new int[]{0, 0, 1};
@@ -14,7 +20,7 @@ public class standalone {
static String targetPath; // psarc file
static String sourcePath; // folder contents to import when using -c, list of files to export when using -x
static boolean overwrite = false;
- static Scotty.CompressionFormats targetFormat = Scotty.CompressionFormats.ZLIB;
+ static CompressionFormats targetFormat = CompressionFormats.ZLIB;
static byte targetStrength = 9;
static long targetBlockSize = 65536; // in bytes
static boolean makeAbsolute = false;
@@ -101,17 +107,17 @@ public class standalone {
case "-u":
argIsTakingParam = false;
argWhichIsTakingParam = s;
- targetFormat = Scotty.CompressionFormats.NONE;
+ targetFormat = CompressionFormats.NONE;
break;
case "-z":
argIsTakingParam = false;
argWhichIsTakingParam = s;
- targetFormat = Scotty.CompressionFormats.ZLIB;
+ targetFormat = CompressionFormats.ZLIB;
break;
case "-l":
argIsTakingParam = false;
argWhichIsTakingParam = s;
- targetFormat = Scotty.CompressionFormats.LZMA;
+ targetFormat = CompressionFormats.LZMA;
break;
case "-r":
argIsTakingParam = false;
@@ -129,7 +135,7 @@ public class standalone {
makeCaseInsensitive = true;
break;
default:
- if ((args.length - 1) == i && (!s.startsWith("-") || s.endsWith(".psarc"))) {
+ if ((args.length - 1) == i) {
targetPath = s;
} else {
System.out.println("invalid option: " + s);
@@ -150,13 +156,23 @@ public class standalone {
System.out.println("INFO: case insensitive mode is " + makeCaseInsensitive);
}
- if () {
-
+ if (operation.isEmpty()) {
+ operation = "-i";
}
switch (operation) {
+ 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]);
+ System.exit(0);
+ } catch (Exception e) {
+ System.out.println("Error reading file \"" + targetPath + "\".\n" + e.getMessage());
+ System.exit(1);
+ }
+ break;
default:
- System.out.println("No valid operation specified. Exiting.");
+ System.out.println("Unimplemented operation specified. Exiting.");
System.exit(0);
break;
}
diff --git a/net/screwgravity/vitality4j/tools.java b/net/screwgravity/vitality4j/tools.java
new file mode 100644
index 0000000..634322a
--- /dev/null
+++ b/net/screwgravity/vitality4j/tools.java
@@ -0,0 +1,146 @@
+package net.screwgravity.vitality4j;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class tools {
+ public static class IncorrectFileTypeException extends Exception {
+ public IncorrectFileTypeException(String errorMessage) {
+ super(errorMessage);
+ }
+ }
+
+ public static class Scotty {
+ public enum CompressionFormats {
+ NONE(0),
+ ZLIB(1),
+ LZMA(2);
+
+ private final int value;
+ CompressionFormats(final int value) {this.value = value;}
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public enum PathModes {
+ RELATIVE(0),
+ IGNORE_CASE(1),
+ ABSOLUTE(2);
+
+ private final int value;
+ PathModes(final int value) {this.value = value;}
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static class CompressedFile {
+ private final PSARC container;
+ private final String path;
+ public CompressionFormats algorithm = null; // if NULL then it inherits the value from the entire PSARC file
+
+ public CompressedFile(PSARC container, String path) {
+ this.container = container;
+ this.path = path;
+ }
+
+ public PSARC getContainer() {
+ return container;
+ }
+
+ public String getLocationInArchive() {
+ return path;
+ }
+
+ public InputStream getIOStream() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public static class PSARC {
+ 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 PathModes mode = PathModes.RELATIVE;
+ private RandomAccessFile fromDisk = null; // if NULL then file is a new file
+ private List files = new ArrayList();
+
+ public PSARC() { // new w/ defaults
+ // use defaults, do nothing
+ }
+
+ public PSARC(File location) throws IOException, IncorrectFileTypeException { // existing
+ // todo: read psarc and set vars above
+ fromDisk = new RandomAccessFile(location, "r"); // mode will be changed retroactively with a new RandomAccessFile if we ever need to make writes
+
+ // verify this is actually a PSARC file
+ // magic number should be "PSAR" in ascii
+ byte[] magic = new byte[4];
+ fromDisk.read(magic);
+ if (!Arrays.equals(magic, new byte[]{80, 83, 65, 82})) {
+ throw new IncorrectFileTypeException("Magic number invalid. Is this actually a PSARC?");
+ }
+
+ // ok, it is safe to continue
+ fromDisk.seek(4);
+ fromDisk.read(version);
+ }
+
+ public PSARC(CompressionFormats algorithm, byte strength) { // new
+ this.algorithm = algorithm;
+ this.strength = strength;
+ }
+
+ public PSARC(CompressionFormats algorithm, byte strength, long blockSize) { // new
+ this.algorithm = algorithm;
+ this.strength = strength;
+ this.blockSize = blockSize;
+ }
+
+ public List listAllFiles() {
+ return files;
+ }
+
+ public String[] listAllFilePaths() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addFile(File input) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean writeOut(File destination) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean extractAll(File destination) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean extractSingleFile(CompressedFile target, File destination) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean extractMultipleFiles(List targets, File directory) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+
+ }
+
+ public static class June {
+ // todo
+ }
+
+
+}