diff --git a/.gitignore b/.gitignore index 1a5cb52..0909ed1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /target/ /resources/ /data/ -/SLPProcessor/ +/MerySLP/ /slp-processor.iml /.idea/ *.jfr diff --git a/src/main/java/io/github/merykitty/meryslp/Info.java b/src/main/java/io/github/merykitty/meryslp/Info.java index 3712c62..96fc516 100644 --- a/src/main/java/io/github/merykitty/meryslp/Info.java +++ b/src/main/java/io/github/merykitty/meryslp/Info.java @@ -1,7 +1,12 @@ package io.github.merykitty.meryslp; +import io.github.merykitty.meryslp.misc.EnvironmentResolver; + public class Info { public static void main(String[] args) { - + EnvironmentResolver.info( + """ + """ + ); } } diff --git a/src/main/java/io/github/merykitty/meryslp/SLPDecoder.java b/src/main/java/io/github/merykitty/meryslp/SLPDecoder.java index 169ef8f..07b5b2f 100644 --- a/src/main/java/io/github/merykitty/meryslp/SLPDecoder.java +++ b/src/main/java/io/github/merykitty/meryslp/SLPDecoder.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.logging.Level; import io.github.merykitty.meryslp.misc.EnvironmentResolver; import io.github.merykitty.meryslp.misc.PrimitiveOptional; @@ -20,6 +21,8 @@ public class SLPDecoder { private static final Path DEFAULT_OUTPUT_FOLDER = Path.of("data/decoder-output"); public static void main(String[] args) throws IOException { + EnvironmentResolver.setLogLevel(Level.INFO); + var parser = ArgumentParsers.newFor("SLPDecoder").build() .defaultHelp(true) .description("Decode SLP files into human readable graphics images and meta data"); @@ -33,7 +36,6 @@ public static void main(String[] args) throws IOException { try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { - System.out.println("Incorrect command line format"); return; } var configFile = EnvironmentResolver.homeDir().resolve(DEFAULT_CONFIG_FILE); @@ -55,25 +57,25 @@ public static void main(String[] args) throws IOException { processSLPFile(path, outputFolder, palettes); }); } catch (RuntimeException e) { - System.out.println("Error: " + e.getCause().toString()); + EnvironmentResolver.error("Error: " + e.getCause().toString()); } catch (Exception e) { - System.out.println("Error: " + e.toString()); + EnvironmentResolver.error("Error: " + e.toString()); } } private static void processSLPFile(Path inputFile, Path outputFolder, PaletteContainer palettes) { try { var fileName = inputFile.getFileName(); - System.out.println("File name: " + fileName.toString()); + EnvironmentResolver.info("File name: " + fileName.toString()); long start = System.currentTimeMillis(); var file = SLPFiles.decode(inputFile, palettes); long mid = System.currentTimeMillis(); - System.out.println("Read slp file: " + (mid - start) + " ms"); + EnvironmentResolver.info("Read slp file: " + (mid - start) + " ms"); file.exportGraphics(outputFolder.resolve(fileName)); long end = System.currentTimeMillis(); - System.out.println("Print data: " + (end - mid) + " ms"); + EnvironmentResolver.info("Print data: " + (end - mid) + " ms"); } catch (Exception e) { - System.out.println(e); + EnvironmentResolver.info(e); } } } diff --git a/src/main/java/io/github/merykitty/meryslp/SLPEncoder.java b/src/main/java/io/github/merykitty/meryslp/SLPEncoder.java index affb339..50c9e32 100644 --- a/src/main/java/io/github/merykitty/meryslp/SLPEncoder.java +++ b/src/main/java/io/github/merykitty/meryslp/SLPEncoder.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.logging.Level; public class SLPEncoder { private static final Path DEFAULT_CONFIG_FILE = Path.of("resources/aoe1-config.json"); @@ -19,6 +20,8 @@ public class SLPEncoder { private static final Path DEFAULT_OUTPUT_FOLDER = Path.of("data/encoder-output"); public static void main(String[] args) throws IOException { + EnvironmentResolver.setLogLevel(Level.INFO); + var parser = ArgumentParsers.newFor("SLPDecoder").build() .defaultHelp(true) .description("Encode human readable graphics images and meta data to SLP files"); @@ -32,7 +35,6 @@ public static void main(String[] args) throws IOException { try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { - System.out.println("Incorrect command line format"); return; } @@ -53,25 +55,25 @@ public static void main(String[] args) throws IOException { files.filter(Files::isDirectory) .forEach(path -> encodeSLP(path, outputFolder, palettes)); } catch (RuntimeException e) { - System.out.println("Error: " + e.getCause().toString()); + EnvironmentResolver.error("Error: " + e.getCause().toString()); } catch (Exception e) { - System.out.println("Error: " + e.toString()); + EnvironmentResolver.error("Error: " + e.toString()); } } private static void encodeSLP(Path inputFile, Path outputFolder, PaletteContainer palettes) { try { var fileName = inputFile.getFileName(); - System.out.println("File name: " + fileName.toString()); + EnvironmentResolver.info("File name: " + fileName.toString()); long start = System.currentTimeMillis(); var file = SLPFiles.importGraphics(inputFile, palettes); long mid = System.currentTimeMillis(); - System.out.println("Import graphics: " + (mid - start) + " ms"); + EnvironmentResolver.info("Import graphics: " + (mid - start) + " ms"); SLPFiles.encode(outputFolder.resolve(fileName), palettes, file, true); long end = System.currentTimeMillis(); - System.out.println("Encode slp file: " + (end - mid) + " ms"); + EnvironmentResolver.info("Encode slp file: " + (end - mid) + " ms"); } catch (Exception e) { - System.out.println(e.toString()); + EnvironmentResolver.info(e); } } } diff --git a/src/main/java/io/github/merykitty/meryslp/Test.java b/src/main/java/io/github/merykitty/meryslp/Test.java index a5b8d83..59e5c3d 100644 --- a/src/main/java/io/github/merykitty/meryslp/Test.java +++ b/src/main/java/io/github/merykitty/meryslp/Test.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.logging.Level; import io.github.merykitty.meryslp.common.SLPFiles; import io.github.merykitty.meryslp.image.PaletteContainer; @@ -18,6 +19,7 @@ public class Test { private static final Path ENCODE_OUTPUT_FOLDER = HOME_DIR.resolve("data/encoder-output"); public static void main(String[] args) throws IOException { + EnvironmentResolver.setLogLevel(Level.ALL); // var palettes = new PaletteContainer(CONFIG_FILE, PALETTE_FOLDER); // var files = Files.list(DECODE_INPUT_FOLDER); // files.filter(Files::isRegularFile) diff --git a/src/main/java/io/github/merykitty/meryslp/misc/EnvironmentResolver.java b/src/main/java/io/github/merykitty/meryslp/misc/EnvironmentResolver.java index c9cf7de..0251127 100644 --- a/src/main/java/io/github/merykitty/meryslp/misc/EnvironmentResolver.java +++ b/src/main/java/io/github/merykitty/meryslp/misc/EnvironmentResolver.java @@ -6,6 +6,9 @@ import java.lang.invoke.MethodType; import java.nio.file.Files; import java.nio.file.Path; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; public class EnvironmentResolver { private static final long INIT_MAX_PATH_LENGTH = 256; @@ -13,10 +16,12 @@ public class EnvironmentResolver { private static final String OS_NAME; private static final Path HOME_DIR; + private static final Logger LOGGER = Logger.getGlobal(); static { try { OS_NAME = System.getProperty("os.name").toLowerCase(); + LOGGER.addHandler(new ConsoleHandler()); if (OS_NAME.contains("linux")) { var execPath = Files.readSymbolicLink(Path.of("/proc/self/exe")); var execName = execPath.getFileName().toString(); @@ -83,6 +88,10 @@ public class EnvironmentResolver { } } + public static void setLogLevel(Level level) { + LOGGER.setLevel(level); + } + public static Path homeDir() { return HOME_DIR; } @@ -90,4 +99,20 @@ public static Path homeDir() { public static String osName() { return OS_NAME; } + + public static void debug(Object message) { + LOGGER.fine(message.toString()); + } + + public static void info(Object message) { + LOGGER.info(message.toString()); + } + + public static void warning(Object message) { + LOGGER.warning(message.toString()); + } + + public static void error(Object message) { + LOGGER.severe(message.toString()); + } } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 9b4d9a1..5dc87c4 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.github.merykitty.meryslp { + requires java.logging; requires jdk.unsupported; requires jdk.incubator.foreign; requires org.json; diff --git a/src/main/resources/unix-x64/icon.png b/src/main/resources/unix-x64/icon.png new file mode 100644 index 0000000..dcd44b4 Binary files /dev/null and b/src/main/resources/unix-x64/icon.png differ diff --git a/src/main/resources/windows-x64/decoder.properties b/src/main/resources/windows-x64/decoder.properties index eee38ba..a1db3cf 100644 --- a/src/main/resources/windows-x64/decoder.properties +++ b/src/main/resources/windows-x64/decoder.properties @@ -1,4 +1,4 @@ java-options=-Dforeign.restricted=permit -XX:+UseParallelGC -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields module=io.github.merykitty.meryslp/io.github.merykitty.meryslp.SLPDecoder -icon=./resources/icon.png +icon=./resources/icon.ico win-console=true diff --git a/src/main/resources/windows-x64/encoder.properties b/src/main/resources/windows-x64/encoder.properties index 18ac02f..db2fa06 100644 --- a/src/main/resources/windows-x64/encoder.properties +++ b/src/main/resources/windows-x64/encoder.properties @@ -1,4 +1,4 @@ java-options=-Dforeign.restricted=permit -XX:+UseParallelGC -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -module=io.github.merykitty.slpprocessor/io.github.merykitty.slpprocessor.SLPEncoder -icon=./resources/icon.png +module=io.github.merykitty.meryslp/io.github.merykitty.meryslp.SLPEncoder +icon=./resources/icon.ico win-console=true diff --git a/src/main/resources/windows-x64/icon.ico b/src/main/resources/windows-x64/icon.ico new file mode 100644 index 0000000..8d2c957 Binary files /dev/null and b/src/main/resources/windows-x64/icon.ico differ