/******************************************************************************* * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public * License v3.0 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html *
* Contributors:
* Jeff Martin - initial API and implementation
******************************************************************************/
package cuchaz.enigma;
import java.io.File;
import java.util.jar.JarFile;
import cuchaz.enigma.Deobfuscator.ProgressListener;
import cuchaz.enigma.mapping.Mappings;
import cuchaz.enigma.mapping.MappingsEnigmaReader;
public class CommandMain {
public static class ConsoleProgressListener implements ProgressListener {
private static final int ReportTime = 5000; // 5s
private int totalWork;
private long startTime;
private long lastReportTime;
@Override
public void init(int totalWork, String title) {
this.totalWork = totalWork;
this.startTime = System.currentTimeMillis();
this.lastReportTime = this.startTime;
System.out.println(title);
}
@Override
public void onProgress(int numDone, String message) {
long now = System.currentTimeMillis();
boolean isLastUpdate = numDone == this.totalWork;
boolean shouldReport = isLastUpdate || now - this.lastReportTime > ReportTime;
if (shouldReport) {
int percent = numDone * 100 / this.totalWork;
System.out.println(String.format("\tProgress: %3d%%", percent));
this.lastReportTime = now;
}
if (isLastUpdate) {
double elapsedSeconds = (now - this.startTime) / 1000.0;
System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds));
}
}
}
public static void main(String[] args) throws Exception {
try {
// process the command
String command = getArg(args, 0, "command", true);
if (command.equalsIgnoreCase("deobfuscate")) {
deobfuscate(args);
} else if (command.equalsIgnoreCase("decompile")) {
decompile(args);
} else if (command.equalsIgnoreCase("protectify")) {
protectify(args);
} else if (command.equalsIgnoreCase("publify")) {
publify(args);
} else {
throw new IllegalArgumentException("Command not recognized: " + command);
}
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
printHelp();
}
}
private static void printHelp() {
System.out.println(String.format("%s - %s", Constants.NAME, Constants.VERSION));
System.out.println("Usage:");
System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain