summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/CommandMain.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/CommandMain.java')
-rw-r--r--src/main/java/cuchaz/enigma/CommandMain.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/main/java/cuchaz/enigma/CommandMain.java b/src/main/java/cuchaz/enigma/CommandMain.java
index 8dfbe24..d7967b4 100644
--- a/src/main/java/cuchaz/enigma/CommandMain.java
+++ b/src/main/java/cuchaz/enigma/CommandMain.java
@@ -23,42 +23,38 @@ public class CommandMain {
23 23
24 private static final int ReportTime = 5000; // 5s 24 private static final int ReportTime = 5000; // 5s
25 25
26 private int m_totalWork; 26 private int totalWork;
27 private long m_startTime; 27 private long startTime;
28 private long m_lastReportTime; 28 private long lastReportTime;
29 29
30 @Override 30 @Override
31 public void init(int totalWork, String title) { 31 public void init(int totalWork, String title) {
32 m_totalWork = totalWork; 32 this.totalWork = totalWork;
33 m_startTime = System.currentTimeMillis(); 33 this.startTime = System.currentTimeMillis();
34 m_lastReportTime = m_startTime; 34 this.lastReportTime = this.startTime;
35 System.out.println(title); 35 System.out.println(title);
36 } 36 }
37 37
38 @Override 38 @Override
39 public void onProgress(int numDone, String message) { 39 public void onProgress(int numDone, String message) {
40
41 long now = System.currentTimeMillis(); 40 long now = System.currentTimeMillis();
42 boolean isLastUpdate = numDone == m_totalWork; 41 boolean isLastUpdate = numDone == this.totalWork;
43 boolean shouldReport = isLastUpdate || now - m_lastReportTime > ReportTime; 42 boolean shouldReport = isLastUpdate || now - this.lastReportTime > ReportTime;
44 43
45 if (shouldReport) { 44 if (shouldReport) {
46 int percent = numDone * 100 / m_totalWork; 45 int percent = numDone * 100 / this.totalWork;
47 System.out.println(String.format("\tProgress: %3d%%", percent)); 46 System.out.println(String.format("\tProgress: %3d%%", percent));
48 m_lastReportTime = now; 47 this.lastReportTime = now;
49 } 48 }
50 if (isLastUpdate) { 49 if (isLastUpdate) {
51 double elapsedSeconds = (now - m_startTime) / 1000; 50 double elapsedSeconds = (now - this.startTime) / 1000;
52 System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds)); 51 System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds));
53 } 52 }
54 } 53 }
55 } 54 }
56 55
57 public static void main(String[] args) 56 public static void main(String[] args) throws Exception {
58 throws Exception {
59
60 try { 57 try {
61
62 // process the command 58 // process the command
63 String command = getArg(args, 0, "command", true); 59 String command = getArg(args, 0, "command", true);
64 if (command.equalsIgnoreCase("deobfuscate")) { 60 if (command.equalsIgnoreCase("deobfuscate")) {
@@ -88,8 +84,7 @@ public class CommandMain {
88 System.out.println("\t\tprotectify <in jar> <out jar>"); 84 System.out.println("\t\tprotectify <in jar> <out jar>");
89 } 85 }
90 86
91 private static void decompile(String[] args) 87 private static void decompile(String[] args) throws Exception {
92 throws Exception {
93 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); 88 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true));
94 File fileJarOut = getWritableFolder(getArg(args, 2, "out folder", true)); 89 File fileJarOut = getWritableFolder(getArg(args, 2, "out folder", true));
95 File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false)); 90 File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false));
@@ -97,8 +92,7 @@ public class CommandMain {
97 deobfuscator.writeSources(fileJarOut, new ConsoleProgressListener()); 92 deobfuscator.writeSources(fileJarOut, new ConsoleProgressListener());
98 } 93 }
99 94
100 private static void deobfuscate(String[] args) 95 private static void deobfuscate(String[] args) throws Exception {
101 throws Exception {
102 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); 96 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true));
103 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true)); 97 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true));
104 File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false)); 98 File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false));
@@ -106,24 +100,21 @@ public class CommandMain {
106 deobfuscator.writeJar(fileJarOut, new ConsoleProgressListener()); 100 deobfuscator.writeJar(fileJarOut, new ConsoleProgressListener());
107 } 101 }
108 102
109 private static void protectify(String[] args) 103 private static void protectify(String[] args) throws Exception {
110 throws Exception {
111 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); 104 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true));
112 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true)); 105 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true));
113 Deobfuscator deobfuscator = getDeobfuscator(null, new JarFile(fileJarIn)); 106 Deobfuscator deobfuscator = getDeobfuscator(null, new JarFile(fileJarIn));
114 deobfuscator.protectifyJar(fileJarOut, new ConsoleProgressListener()); 107 deobfuscator.protectifyJar(fileJarOut, new ConsoleProgressListener());
115 } 108 }
116 109
117 private static void publify(String[] args) 110 private static void publify(String[] args) throws Exception {
118 throws Exception {
119 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); 111 File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true));
120 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true)); 112 File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true));
121 Deobfuscator deobfuscator = getDeobfuscator(null, new JarFile(fileJarIn)); 113 Deobfuscator deobfuscator = getDeobfuscator(null, new JarFile(fileJarIn));
122 deobfuscator.publifyJar(fileJarOut, new ConsoleProgressListener()); 114 deobfuscator.publifyJar(fileJarOut, new ConsoleProgressListener());
123 } 115 }
124 116
125 private static Deobfuscator getDeobfuscator(File fileMappings, JarFile jar) 117 private static Deobfuscator getDeobfuscator(File fileMappings, JarFile jar) throws Exception {
126 throws Exception {
127 System.out.println("Reading jar..."); 118 System.out.println("Reading jar...");
128 Deobfuscator deobfuscator = new Deobfuscator(jar); 119 Deobfuscator deobfuscator = new Deobfuscator(jar);
129 if (fileMappings != null) { 120 if (fileMappings != null) {