summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jeff2015-01-17 16:20:15 -0500
committerGravatar jeff2015-01-17 16:20:15 -0500
commitba67f6c0231157c0b07b37fe0a09fca381bb37d9 (patch)
tree924c65b7f1b93f901d70d2c6b529278954010f14
parentstarted on command line interface for build system (diff)
downloadenigma-ba67f6c0231157c0b07b37fe0a09fca381bb37d9.tar.gz
enigma-ba67f6c0231157c0b07b37fe0a09fca381bb37d9.tar.xz
enigma-ba67f6c0231157c0b07b37fe0a09fca381bb37d9.zip
added command-line interface for scriptable awesome
-rw-r--r--build.py13
-rw-r--r--readme.txt (renamed from readme.gui.txt)9
-rw-r--r--src/cuchaz/enigma/CommandMain.java134
3 files changed, 130 insertions, 26 deletions
diff --git a/build.py b/build.py
index 69182514..62b96d11 100644
--- a/build.py
+++ b/build.py
@@ -12,8 +12,11 @@ dirBuild = "build"
12dirTemp = os.path.join(dirBuild, "tmp") 12dirTemp = os.path.join(dirBuild, "tmp")
13 13
14 14
15def getJarFullName(name) : 15def getJarFullName(name=None) :
16 return "%s-%s-%s.jar" % (projectName, name, version) 16 if name is not None:
17 return "%s-%s-%s.jar" % (projectName, name, version)
18 else:
19 return "%s-%s.jar" % (projectName, version)
17 20
18def buildGuiJar(): 21def buildGuiJar():
19 jarName = "gui" 22 jarName = "gui"
@@ -25,9 +28,9 @@ def buildGuiJar():
25 ssjb.delete(os.path.join(dirTemp, "LICENSE.txt")) 28 ssjb.delete(os.path.join(dirTemp, "LICENSE.txt"))
26 ssjb.copyFile(dirTemp, "license.APL2.txt") 29 ssjb.copyFile(dirTemp, "license.APL2.txt")
27 ssjb.copyFile(dirTemp, "license.GPL3.txt") 30 ssjb.copyFile(dirTemp, "license.GPL3.txt")
28 ssjb.copyFile(dirTemp, "readme.gui.txt", renameTo="readme.txt") 31 ssjb.copyFile(dirTemp, "readme.txt")
29 manifest = ssjb.buildManifest("%s-%s" % (projectName, jarName), version, author, "cuchaz.enigma.Main") 32 manifest = ssjb.buildManifest(projectName, version, author, "cuchaz.enigma.Main")
30 ssjb.jar(os.path.join(dirBuild, getJarFullName(jarName)), dirTemp, manifest=manifest) 33 ssjb.jar(os.path.join(dirBuild, getJarFullName()), dirTemp, manifest=manifest)
31 ssjb.delete(dirTemp) 34 ssjb.delete(dirTemp)
32 35
33def buildTranslateJar(): 36def buildTranslateJar():
diff --git a/readme.gui.txt b/readme.txt
index 81f985a0..3844f54e 100644
--- a/readme.gui.txt
+++ b/readme.txt
@@ -17,3 +17,12 @@ Enigma includes unmodified versions of the following libraries which are also re
17 JSyntaxPane 17 JSyntaxPane
18 18
19Copies of the GNU General Public license verion 3 and the Apache license v2 have been included in this distribution. 19Copies of the GNU General Public license verion 3 and the Apache license v2 have been included in this distribution.
20
21
22USING ENIGMA
23
24Launch the GUI:
25 java -jar enigma.jar
26
27Use Enigma on the command line:
28 java -cp enigma.jar cuchaz.enigma.CommandMain
diff --git a/src/cuchaz/enigma/CommandMain.java b/src/cuchaz/enigma/CommandMain.java
index 6a01661b..74bd4991 100644
--- a/src/cuchaz/enigma/CommandMain.java
+++ b/src/cuchaz/enigma/CommandMain.java
@@ -1,23 +1,65 @@
1package cuchaz.enigma; 1package cuchaz.enigma;
2 2
3import java.io.File;
4import java.io.FileReader;
5
6import cuchaz.enigma.Deobfuscator.ProgressListener;
7import cuchaz.enigma.mapping.Mappings;
8import cuchaz.enigma.mapping.MappingsReader;
9
3public class CommandMain { 10public class CommandMain {
4 11
5 public static void main(String[] args) { 12 public static class ConsoleProgressListener implements ProgressListener {
6 13
7 // parse the args 14 private static final int ReportTime = 5000; // 5s
8 if (args.length < 1) { 15
9 printHelp(); 16 private int m_totalWork;
10 return; 17 private long m_startTime;
18 private long m_lastReportTime;
19
20 @Override
21 public void init(int totalWork, String title) {
22 m_totalWork = totalWork;
23 m_startTime = System.currentTimeMillis();
24 m_lastReportTime = m_startTime;
25 System.out.println(title);
26 }
27
28 @Override
29 public void onProgress(int numDone, String message) {
30
31 long now = System.currentTimeMillis();
32 boolean isLastUpdate = numDone == m_totalWork;
33 boolean shouldReport = isLastUpdate || now - m_lastReportTime > ReportTime;
34
35 if (shouldReport) {
36 int percent = numDone*100/m_totalWork;
37 System.out.println(String.format("\tProgress: %3d%%", percent));
38 m_lastReportTime = now;
39 }
40 if (isLastUpdate) {
41 double elapsedSeconds = (now - m_startTime)/1000;
42 System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds));
43 }
11 } 44 }
45 }
46
47 public static void main(String[] args)
48 throws Exception {
12 49
13 // process the command 50 try {
14 String command = args[0]; 51
15 if (command.equalsIgnoreCase("deobfuscate")) { 52 // process the command
16 deobfuscate(args); 53 String command = getArg(args, 0, "command");
17 } else if(command.equalsIgnoreCase("decompile")) { 54 if (command.equalsIgnoreCase("deobfuscate")) {
18 decompile(args); 55 deobfuscate(args);
19 } else { 56 } else if(command.equalsIgnoreCase("decompile")) {
20 System.out.println("Command not recognized: " + args[0]); 57 decompile(args);
58 } else {
59 throw new IllegalArgumentException("Command not recognized: " + command);
60 }
61 } catch (IllegalArgumentException ex) {
62 System.out.println(ex.getMessage());
21 printHelp(); 63 printHelp();
22 } 64 }
23 } 65 }
@@ -25,19 +67,69 @@ public class CommandMain {
25 private static void printHelp() { 67 private static void printHelp() {
26 System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); 68 System.out.println(String.format("%s - %s", Constants.Name, Constants.Version));
27 System.out.println("Usage:"); 69 System.out.println("Usage:");
28 System.out.println("\tjava -jar enigma.jar cuchaz.enigma.CommandMain <command>"); 70 System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain <command>");
29 System.out.println("\twhere <command> is one of:"); 71 System.out.println("\twhere <command> is one of:");
30 System.out.println("\t\tdeobfuscate <mappings file> <in jar> <out jar>"); 72 System.out.println("\t\tdeobfuscate <mappings file> <in jar> <out jar>");
31 System.out.println("\t\tdecompile <mappings file> <in jar> <out jar>"); 73 System.out.println("\t\tdecompile <mappings file> <in jar> <out folder>");
32 } 74 }
33 75
34 private static void decompile(String[] args) { 76 private static void decompile(String[] args)
35 // TODO 77 throws Exception {
36 throw new Error("Not implemented yet"); 78 File fileMappings = getReadableFile(getArg(args, 1, "mappings file"));
79 File fileJarIn = getReadableFile(getArg(args, 2, "in jar"));
80 File fileJarOut = getWritableFolder(getArg(args, 3, "out folder"));
81 Deobfuscator deobfuscator = getDeobfuscator(fileMappings, fileJarIn);
82 deobfuscator.writeSources(fileJarOut, new ConsoleProgressListener());
37 } 83 }
38 84
39 private static void deobfuscate(String[] args) { 85 private static void deobfuscate(String[] args)
40 // TODO 86 throws Exception {
41 throw new Error("Not implemented yet"); 87 File fileMappings = getReadableFile(getArg(args, 1, "mappings file"));
88 File fileJarIn = getReadableFile(getArg(args, 2, "in jar"));
89 File fileJarOut = getWritableFile(getArg(args, 3, "out jar"));
90 Deobfuscator deobfuscator = getDeobfuscator(fileMappings, fileJarIn);
91 deobfuscator.writeJar(fileJarOut, new ConsoleProgressListener());
92 }
93
94 private static Deobfuscator getDeobfuscator(File fileMappings, File fileJar)
95 throws Exception {
96 System.out.println("Reading mappings...");
97 Mappings mappings = new MappingsReader().read(new FileReader(fileMappings));
98 System.out.println("Reading jar...");
99 Deobfuscator deobfuscator = new Deobfuscator(fileJar);
100 deobfuscator.setMappings(mappings);
101 return deobfuscator;
102 }
103
104 private static String getArg(String[] args, int i, String name) {
105 if (i >= args.length) {
106 throw new IllegalArgumentException(name + " is required");
107 }
108 return args[i];
109 }
110
111 private static File getWritableFile(String path) {
112 File file = new File(path).getAbsoluteFile();
113 File dir = file.getParentFile();
114 if (dir == null || !dir.exists()) {
115 throw new IllegalArgumentException("Cannot write to folder: " + file);
116 }
117 return file;
118 }
119
120 private static File getWritableFolder(String path) {
121 File dir = new File(path).getAbsoluteFile();
122 if (!dir.exists()) {
123 throw new IllegalArgumentException("Cannot write to folder: " + dir);
124 }
125 return dir;
126 }
127
128 private static File getReadableFile(String path) {
129 File file = new File(path).getAbsoluteFile();
130 if (!file.exists()) {
131 throw new IllegalArgumentException("Cannot find file: " + file.getAbsolutePath());
132 }
133 return file;
42 } 134 }
43} 135}