legacy cli inside newcli

This commit is contained in:
Jindra Petřík
2024-01-21 18:46:48 +01:00
parent ef29e059e4
commit 2421074b69
10 changed files with 5424 additions and 4 deletions

View File

@@ -62,7 +62,8 @@ import picocli.CommandLine.ScopeType;
AbcMerge.class,
Swf2Exe.class,
Header.class,
Config.class
Config.class,
Old.class
},
descriptionHeading = "%n@|bold,underline Description|@:%n",
optionListHeading = "%n@|bold,underline Options|@:%n",

View File

@@ -0,0 +1,53 @@
package com.jpexs.decompiler.flash.cli.commands;
import com.jpexs.decompiler.flash.cli.VersionProvider;
import com.jpexs.decompiler.flash.cli.legacy.CommandLineArgumentParser;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;
/**
*
* @author JPEXS
*/
@CommandLine.Command(
name = "old",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class,
header = "Old legacy commandline interface.",
optionListHeading = "%n@|bold,underline Options|@:%n",
parameterListHeading = "%n@|bold,underline Parameters|@:%n",
synopsisHeading = "@|bold,underline Usage|@:",
footerHeading = "%n@|bold,underline Examples|@:%n",
footer = {
"ffdec-cli old",
"ffdec-cli old -export script -format script:pcode outdir/ file.swf"
},
sortSynopsis = false
)
public class Old implements Runnable {
@Parameters (
index = "0",
arity = "0..*"
)
String args[] = new String[]{};
@Override
public void run() {
if (args.length == 0) {
args = new String[] {"--help"};
}
try {
CommandLineArgumentParser.parseArguments(args);
} catch (IOException ex) {
Logger.getLogger(Old.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2010-2023 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.cli.legacy;
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
import java.util.Locale;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class ConsoleAbortRetryIgnoreHandler implements AbortRetryIgnoreHandler {
int errorCount = 0;
int errorMode;
int retryCount;
public ConsoleAbortRetryIgnoreHandler(int errorMode, int retryCount) {
this.errorMode = errorMode;
this.retryCount = retryCount;
}
@Override
public int handle(Throwable thrown) {
if (errorMode != AbortRetryIgnoreHandler.UNDEFINED) {
int result = errorMode;
if (errorMode == AbortRetryIgnoreHandler.RETRY && errorCount < retryCount) {
errorCount++;
} else {
result = AbortRetryIgnoreHandler.IGNORE;
}
return result;
}
Scanner sc = new Scanner(System.in);
if (thrown != null) {
Logger.getLogger(ConsoleAbortRetryIgnoreHandler.class.getName()).log(Level.SEVERE, "Error occured", thrown);
System.out.println("Error occured: " + thrown.getLocalizedMessage());
}
do {
System.out.print("Select action: (A)bort, (R)Retry, (I)Ignore:");
String n = sc.nextLine();
switch (n.toLowerCase(Locale.ENGLISH)) {
case "a":
return AbortRetryIgnoreHandler.ABORT;
case "r":
return AbortRetryIgnoreHandler.RETRY;
case "i":
return AbortRetryIgnoreHandler.IGNORE;
}
} while (true);
}
@Override
public AbortRetryIgnoreHandler getNewInstance() {
return new ConsoleAbortRetryIgnoreHandler(errorMode, retryCount);
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2022-2023 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.cli.legacy;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* FileInputStream to which can be passed /dev/stdin as special file for stdin
* on Windows. On linux, standard /dev/stdin is used.
*
* @author JPEXS
*/
public class StdInAwareFileInputStream extends InputStream implements AutoCloseable {
public static final String STDIN_PATH = "/dev/stdin";
private InputStream is;
public StdInAwareFileInputStream(File file) throws FileNotFoundException {
String absPath = file.getPath().replace("\\", "/");
if (absPath.equals(STDIN_PATH) && !file.exists()) {
is = System.in;
} else {
is = new FileInputStream(file);
}
}
public StdInAwareFileInputStream(String file) throws FileNotFoundException {
this(new File(file));
}
@Override
public int available() throws IOException {
return is.available();
}
@Override
public long skip(long n) throws IOException {
return is.skip(n);
}
@Override
public synchronized void reset() throws IOException {
is.reset();
}
@Override
public void close() throws IOException {
is.close();
}
@Override
public int read() throws IOException {
return is.read();
}
@Override
public int read(byte[] b) throws IOException {
return is.read(b);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
return is.read(b, off, len);
}
}