start i/o logic, CLI is partial atm
This commit is contained in:
parent
012ba02313
commit
b5c9928827
|
@ -11,6 +11,8 @@
|
|||
<component name="ChangeListManager">
|
||||
<list default="true" id="cf74c012-cc69-4732-ac79-9ddfcbf803ee" name="Changes" comment="shut up">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/net/screwgravity/vitality4j/June.java" beforeDir="false" afterPath="$PROJECT_DIR$/net/screwgravity/vitality4j/tools.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/net/screwgravity/vitality4j/Scotty.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/net/screwgravity/vitality4j/standalone.java" beforeDir="false" afterPath="$PROJECT_DIR$/net/screwgravity/vitality4j/standalone.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -18,6 +20,13 @@
|
|||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
<option name="UPDATE_TYPE" value="REBASE" />
|
||||
|
@ -123,7 +132,15 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1723521528643</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<task id="LOCAL-00008" summary="shut up">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723524380202</created>
|
||||
<option name="number" value="00008" />
|
||||
<option name="presentableId" value="LOCAL-00008" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723524380202</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="9" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package net.screwgravity.vitality4j;
|
||||
|
||||
public class June {
|
||||
// todo
|
||||
}
|
|
@ -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<CompressedFile> files = new ArrayList<CompressedFile>();
|
||||
|
||||
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<CompressedFile> 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<CompressedFile> targets, File directory) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
146
net/screwgravity/vitality4j/tools.java
Normal file
146
net/screwgravity/vitality4j/tools.java
Normal file
|
@ -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<CompressedFile> files = new ArrayList<CompressedFile>();
|
||||
|
||||
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<CompressedFile> 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<CompressedFile> targets, File directory) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class June {
|
||||
// todo
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user