mirror of
https://github.com/mitb-archive/filebot
synced 2024-08-13 17:03:45 -04:00
Experiment with PGP signed messages
This commit is contained in:
parent
86ab36028e
commit
89dc1d9864
@ -2,14 +2,16 @@ package net.filebot;
|
|||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.*;
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
|
||||||
import static net.filebot.util.JsonUtilities.*;
|
import static net.filebot.util.JsonUtilities.*;
|
||||||
import static net.filebot.util.RegularExpressions.*;
|
import static net.filebot.util.RegularExpressions.*;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
@ -38,8 +40,15 @@ public class License implements Serializable {
|
|||||||
|
|
||||||
private Exception error;
|
private Exception error;
|
||||||
|
|
||||||
public License(byte[] bytes) {
|
public License(File file) {
|
||||||
try {
|
try {
|
||||||
|
// read and verify license file
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new FileNotFoundException("License not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = Files.readAllBytes(file.toPath());
|
||||||
|
|
||||||
// verify and get clear signed content
|
// verify and get clear signed content
|
||||||
Map<String, String> properties = getProperties(bytes);
|
Map<String, String> properties = getProperties(bytes);
|
||||||
|
|
||||||
@ -112,21 +121,19 @@ public class License implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s License %s (Valid-Until: %s)", product, id, expires.atZone(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
return String.format("%s License %s (Valid-Until: %s)", product, id, expires == null ? null : expires.atZone(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SystemProperty<File> FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
public static final SystemProperty<File> FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
||||||
public static final MemoizedResource<License> INSTANCE = Resource.lazy(() -> new License(readFile(FILE.get())));
|
public static final MemoizedResource<License> INSTANCE = Resource.lazy(() -> new License(FILE.get()));
|
||||||
|
|
||||||
public static License configure(File file) throws Exception {
|
public static License configure(File file) throws Exception {
|
||||||
byte[] bytes = readFile(file);
|
|
||||||
|
|
||||||
// check if license file is valid and not expired
|
// check if license file is valid and not expired
|
||||||
License license = new License(bytes);
|
License license = new License(file);
|
||||||
license.check();
|
license.check();
|
||||||
|
|
||||||
// write to default license file path
|
// write to default license file path
|
||||||
writeFile(bytes, FILE.get());
|
Files.copy(file.toPath(), FILE.get().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
// clear memoized instance and reload on next access
|
// clear memoized instance and reload on next access
|
||||||
INSTANCE.clear();
|
INSTANCE.clear();
|
||||||
|
@ -188,6 +188,14 @@ public class Main {
|
|||||||
// import license if launched with license file
|
// import license if launched with license file
|
||||||
configureLicense(args);
|
configureLicense(args);
|
||||||
|
|
||||||
|
if (LICENSE == LicenseModel.PGPSignedMessage) {
|
||||||
|
try {
|
||||||
|
LICENSE.check();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
debug.finest(e::toString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JavaFX is used for ProgressMonitor and GettingStartedDialog
|
// JavaFX is used for ProgressMonitor and GettingStartedDialog
|
||||||
try {
|
try {
|
||||||
initJavaFX();
|
initJavaFX();
|
||||||
|
@ -2,6 +2,7 @@ package net.filebot.cli;
|
|||||||
|
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
|
import static net.filebot.Settings.*;
|
||||||
import static net.filebot.util.ExceptionUtilities.*;
|
import static net.filebot.util.ExceptionUtilities.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import java.util.stream.Stream;
|
|||||||
import javax.script.Bindings;
|
import javax.script.Bindings;
|
||||||
import javax.script.SimpleBindings;
|
import javax.script.SimpleBindings;
|
||||||
|
|
||||||
|
import net.filebot.LicenseError;
|
||||||
|
|
||||||
public class ArgumentProcessor {
|
public class ArgumentProcessor {
|
||||||
|
|
||||||
public int run(ArgumentBean args) {
|
public int run(ArgumentBean args) {
|
||||||
@ -32,6 +35,10 @@ public class ArgumentProcessor {
|
|||||||
// script finished successfully
|
// script finished successfully
|
||||||
log.finest("Done ヾ(@⌒ー⌒@)ノ");
|
log.finest("Done ヾ(@⌒ー⌒@)ノ");
|
||||||
return 0;
|
return 0;
|
||||||
|
} catch (LicenseError e) {
|
||||||
|
log.severe("License Error: " + e.getMessage());
|
||||||
|
log.info(format("%n%s %s requires a valid license:%n%n=> %s%n%nPlease run `filebot --license *.psm` to install your FileBot license.%n", getApplicationName(), getApplicationVersion(), getPurchaseURL()));
|
||||||
|
return 1;
|
||||||
} 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());
|
||||||
|
@ -30,8 +30,10 @@ import java.util.logging.Level;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import net.filebot.HistorySpooler;
|
import net.filebot.HistorySpooler;
|
||||||
|
import net.filebot.LicenseError;
|
||||||
import net.filebot.NativeRenameAction;
|
import net.filebot.NativeRenameAction;
|
||||||
import net.filebot.ResourceManager;
|
import net.filebot.ResourceManager;
|
||||||
import net.filebot.StandardRenameAction;
|
import net.filebot.StandardRenameAction;
|
||||||
@ -73,8 +75,6 @@ class RenameAction extends AbstractAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LICENSE.check();
|
|
||||||
|
|
||||||
List<Match<Object, File>> matches = new ArrayList<Match<Object, File>>(model.matches());
|
List<Match<Object, File>> matches = new ArrayList<Match<Object, File>>(model.matches());
|
||||||
StandardRenameAction action = (StandardRenameAction) getValue(RENAME_ACTION);
|
StandardRenameAction action = (StandardRenameAction) getValue(RENAME_ACTION);
|
||||||
|
|
||||||
@ -82,6 +82,8 @@ class RenameAction extends AbstractAction {
|
|||||||
Map<File, File> renameLog = new LinkedHashMap<File, File>();
|
Map<File, File> renameLog = new LinkedHashMap<File, File>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
LICENSE.check();
|
||||||
|
|
||||||
if (useNativeShell() && NativeRenameAction.isSupported(action)) {
|
if (useNativeShell() && NativeRenameAction.isSupported(action)) {
|
||||||
// call on EDT
|
// call on EDT
|
||||||
NativeRenameWorker worker = new NativeRenameWorker(renameMap, renameLog, NativeRenameAction.valueOf(action.name()));
|
NativeRenameWorker worker = new NativeRenameWorker(renameMap, renameLog, NativeRenameAction.valueOf(action.name()));
|
||||||
@ -92,6 +94,9 @@ class RenameAction extends AbstractAction {
|
|||||||
String message = String.format("%s %d %s. This may take a while.", action.getDisplayVerb(), renameMap.size(), renameMap.size() == 1 ? "file" : "files");
|
String message = String.format("%s %d %s. This may take a while.", action.getDisplayVerb(), renameMap.size(), renameMap.size() == 1 ? "file" : "files");
|
||||||
ProgressMonitor.runTask(action.getDisplayName(), message, worker).get();
|
ProgressMonitor.runTask(action.getDisplayName(), message, worker).get();
|
||||||
}
|
}
|
||||||
|
} catch (LicenseError e) {
|
||||||
|
JOptionPane.showMessageDialog(window, e.getMessage(), "License Error", JOptionPane.WARNING_MESSAGE);
|
||||||
|
return;
|
||||||
} catch (CancellationException e) {
|
} catch (CancellationException e) {
|
||||||
debug.finest(e::toString);
|
debug.finest(e::toString);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user