|
| 1 | +package me.javapacker.config; |
| 2 | + |
| 3 | +import me.javapacker.steps.api.PackerStep; |
| 4 | + |
| 5 | +import java.io.*; |
| 6 | +import java.util.Properties; |
| 7 | + |
| 8 | +public class PackerConfiguration { |
| 9 | + |
| 10 | + public static PackerConfiguration INSTANCE = new PackerConfiguration(); |
| 11 | + final Properties properties = new Properties(); |
| 12 | + private static String encryptionKey; |
| 13 | + private static String inputPath; |
| 14 | + private static String outputPath; |
| 15 | + private static boolean useNullByteName; |
| 16 | + private static boolean fakeDirectory; |
| 17 | + |
| 18 | + private PackerConfiguration() { } |
| 19 | + |
| 20 | + public void readConfiguration() throws Exception { |
| 21 | + final File f = new File("javapacker.properties"); |
| 22 | + if(!f.exists()) |
| 23 | + { |
| 24 | + properties.setProperty("inputPath", "input.jar"); |
| 25 | + properties.setProperty("outputPath", "output.jar"); |
| 26 | + properties.setProperty("encryptionKey", "ABCDEFGHIJKLMNPA"); |
| 27 | + properties.setProperty("useNullByteName", "true"); |
| 28 | + properties.setProperty("fakeDirectory", "true"); |
| 29 | + properties.store(new FileOutputStream(f), ""); |
| 30 | + } |
| 31 | + loadConfiguration(f); |
| 32 | + } |
| 33 | + |
| 34 | + private void loadConfiguration(final File f) throws IOException { |
| 35 | + properties.load(new FileInputStream(f)); |
| 36 | + inputPath = properties.getProperty("inputPath"); |
| 37 | + outputPath = properties.getProperty("outputPath"); |
| 38 | + encryptionKey = properties.getProperty("encryptionKey"); |
| 39 | + useNullByteName = Boolean.parseBoolean(properties.getProperty("useNullByteName")); |
| 40 | + fakeDirectory = Boolean.parseBoolean(properties.getProperty("fakeDirectory")); |
| 41 | + if(encryptionKey.length() != 16) |
| 42 | + { |
| 43 | + throw new RuntimeException("EncryptionKey length must be 16 bytes!"); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + public String getEncryptionKey() { |
| 48 | + return encryptionKey; |
| 49 | + } |
| 50 | + |
| 51 | + public String getInputPath() { |
| 52 | + return inputPath; |
| 53 | + } |
| 54 | + |
| 55 | + public String getOutputPath() { |
| 56 | + return outputPath; |
| 57 | + } |
| 58 | + |
| 59 | + public boolean isUseNullByteName() { |
| 60 | + return useNullByteName; |
| 61 | + } |
| 62 | + |
| 63 | + public boolean isFakeDirectory() { |
| 64 | + return fakeDirectory; |
| 65 | + } |
| 66 | +} |
| 67 | + |
0 commit comments