start i/o logic, CLI is partial atm

This commit is contained in:
Downforce Agent 2024-08-13 00:35:51 -05:00
parent 012ba02313
commit b5c9928827
5 changed files with 188 additions and 132 deletions

View File

@ -11,6 +11,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="cf74c012-cc69-4732-ac79-9ddfcbf803ee" name="Changes" comment="shut up"> <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$/.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" /> <change beforePath="$PROJECT_DIR$/net/screwgravity/vitality4j/standalone.java" beforeDir="false" afterPath="$PROJECT_DIR$/net/screwgravity/vitality4j/standalone.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -18,6 +20,13 @@
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="UPDATE_TYPE" value="REBASE" /> <option name="UPDATE_TYPE" value="REBASE" />
@ -123,7 +132,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1723521528643</updated> <updated>1723521528643</updated>
</task> </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 /> <servers />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">

View File

@ -1,5 +0,0 @@
package net.screwgravity.vitality4j;
public class June {
// todo
}

View File

@ -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();
}
}
}

View File

@ -1,5 +1,11 @@
package net.screwgravity.vitality4j; 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 class standalone {
public static boolean fromTerminal = false; public static boolean fromTerminal = false;
public static final int[] version = new int[]{0, 0, 1}; public static final int[] version = new int[]{0, 0, 1};
@ -14,7 +20,7 @@ public class standalone {
static String targetPath; // psarc file static String targetPath; // psarc file
static String sourcePath; // folder contents to import when using -c, list of files to export when using -x static String sourcePath; // folder contents to import when using -c, list of files to export when using -x
static boolean overwrite = false; static boolean overwrite = false;
static Scotty.CompressionFormats targetFormat = Scotty.CompressionFormats.ZLIB; static CompressionFormats targetFormat = CompressionFormats.ZLIB;
static byte targetStrength = 9; static byte targetStrength = 9;
static long targetBlockSize = 65536; // in bytes static long targetBlockSize = 65536; // in bytes
static boolean makeAbsolute = false; static boolean makeAbsolute = false;
@ -101,17 +107,17 @@ public class standalone {
case "-u": case "-u":
argIsTakingParam = false; argIsTakingParam = false;
argWhichIsTakingParam = s; argWhichIsTakingParam = s;
targetFormat = Scotty.CompressionFormats.NONE; targetFormat = CompressionFormats.NONE;
break; break;
case "-z": case "-z":
argIsTakingParam = false; argIsTakingParam = false;
argWhichIsTakingParam = s; argWhichIsTakingParam = s;
targetFormat = Scotty.CompressionFormats.ZLIB; targetFormat = CompressionFormats.ZLIB;
break; break;
case "-l": case "-l":
argIsTakingParam = false; argIsTakingParam = false;
argWhichIsTakingParam = s; argWhichIsTakingParam = s;
targetFormat = Scotty.CompressionFormats.LZMA; targetFormat = CompressionFormats.LZMA;
break; break;
case "-r": case "-r":
argIsTakingParam = false; argIsTakingParam = false;
@ -129,7 +135,7 @@ public class standalone {
makeCaseInsensitive = true; makeCaseInsensitive = true;
break; break;
default: default:
if ((args.length - 1) == i && (!s.startsWith("-") || s.endsWith(".psarc"))) { if ((args.length - 1) == i) {
targetPath = s; targetPath = s;
} else { } else {
System.out.println("invalid option: " + s); System.out.println("invalid option: " + s);
@ -150,13 +156,23 @@ public class standalone {
System.out.println("INFO: case insensitive mode is " + makeCaseInsensitive); System.out.println("INFO: case insensitive mode is " + makeCaseInsensitive);
} }
if () { if (operation.isEmpty()) {
operation = "-i";
} }
switch (operation) { 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: default:
System.out.println("No valid operation specified. Exiting."); System.out.println("Unimplemented operation specified. Exiting.");
System.exit(0); System.exit(0);
break; break;
} }

View 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
}
}