1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-03-10 06:20:27 -04:00

Experiment with PGP signed messages

This commit is contained in:
Reinhard Pointner 2018-06-10 22:27:50 +07:00
parent bb6b6f244d
commit f0a59d51f0
3 changed files with 41 additions and 24 deletions

View File

@ -117,10 +117,19 @@ public class Main {
System.exit(status); System.exit(status);
} }
// CLI behaviour for console interactive usage
if (isHeadless() || System.console() != null) {
// print license to console if we have an interactive console
if (configureLicense(args)) {
System.exit(0);
}
// exit with man page if we can't launch the GUI
if (isHeadless()) { if (isHeadless()) {
log.info(String.format("%s / %s (headless)%n%n%s", getApplicationIdentifier(), getJavaRuntimeIdentifier(), args.usage())); log.info(String.format("%s / %s (headless)%n%n%s", getApplicationIdentifier(), getJavaRuntimeIdentifier(), args.usage()));
System.exit(1); System.exit(1);
} }
}
// GUI mode => start user interface // GUI mode => start user interface
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
@ -155,6 +164,23 @@ public class Main {
} }
} }
private static boolean configureLicense(ArgumentBean args) {
File file = args.getLicenseFile();
if (file == null || LICENSE != LicenseModel.PGPSignedMessage) {
return false;
}
try {
License license = License.configure(file);
log.info(license + " has been activated.");
} catch (Throwable e) {
log.severe("License Error: " + e.getMessage());
}
return true;
}
private static void onStart(ArgumentBean args) throws Exception { private static void onStart(ArgumentBean args) throws Exception {
// publish file arguments // publish file arguments
List<File> files = args.getFiles(false); List<File> files = args.getFiles(false);
@ -162,17 +188,8 @@ public class Main {
SwingEventBus.getInstance().post(new FileTransferable(files)); SwingEventBus.getInstance().post(new FileTransferable(files));
} }
// import license if started with license file // import license if launched with license file
if (LicenseModel.PGPSignedMessage == LICENSE) { configureLicense(args);
args.getLicenseFile().ifPresent(f -> {
try {
License license = License.configure(f);
log.info(license + " has been activated.");
} catch (Throwable e) {
log.severe("License Error: " + e.getMessage());
}
});
}
// JavaFX is used for ProgressMonitor and GettingStartedDialog // JavaFX is used for ProgressMonitor and GettingStartedDialog
try { try {

View File

@ -351,8 +351,8 @@ public class ArgumentBean {
}).orElseThrow(error("Illegal mode", mode)); }).orElseThrow(error("Illegal mode", mode));
} }
public Optional<File> getLicenseFile() { public File getLicenseFile() {
return optional(license).map(File::new); return license == null ? null : new File(license);
} }
private final String[] args; private final String[] args;

View File

@ -21,17 +21,17 @@ public class ArgumentProcessor {
// interactive mode enables basic selection and confirmation dialogs in the CLI // interactive mode enables basic selection and confirmation dialogs in the CLI
CmdlineInterface cli = args.isInteractive() ? new CmdlineOperationsTextUI() : new CmdlineOperations(); CmdlineInterface cli = args.isInteractive() ? new CmdlineOperationsTextUI() : new CmdlineOperations();
// execute simple command
if (args.script == null) { if (args.script == null) {
// execute command
return runCommand(cli, args); return runCommand(cli, args);
} else { }
// execute user script // execute user script
runScript(cli, args); runScript(cli, args);
// script finished successfully // script finished successfully
log.finest("Done ヾ(@⌒ー⌒@)"); log.finest("Done ヾ(@⌒ー⌒@)");
return 0; return 0;
}
} catch (Throwable e) { } catch (Throwable e) {
if (findCause(e, CmdlineException.class) != null) { if (findCause(e, CmdlineException.class) != null) {
log.log(Level.WARNING, findCause(e, CmdlineException.class).getMessage()); log.log(Level.WARNING, findCause(e, CmdlineException.class).getMessage());