This commit is contained in:
Reinhard Pointner 2018-06-25 22:50:01 +07:00
parent 67a1d517a6
commit 636b901556
2 changed files with 20 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import java.io.FileNotFoundException;
import java.io.Serializable;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
@ -132,4 +133,21 @@ public class License implements Serializable {
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(FILE.get()));
public static License importLicenseFile(File file) throws Exception {
// lock memoized resource while validating and setting a new license
synchronized (License.INSTANCE) {
// check if license file is valid and not expired
License license = new License(file).check();
// write to default license file path
Files.copy(file.toPath(), License.FILE.get().toPath(), StandardCopyOption.REPLACE_EXISTING);
// clear memoized instance and reload on next access
License.INSTANCE.clear();
// return valid license object
return license;
}
}
}

View File

@ -1,5 +1,6 @@
package net.filebot;
import static net.filebot.License.*;
import static net.filebot.Logging.*;
import java.io.BufferedInputStream;
@ -9,8 +10,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
@ -150,24 +149,10 @@ public final class Settings {
public static void configureLicense(File file) {
try {
// lock memoized resource while validating and setting a new license
synchronized (License.INSTANCE) {
// check if license file is valid and not expired
License license = new License(file).check();
// confirmed valid license
log.info(license + " has been activated.");
// write to default license file path
Files.copy(file.toPath(), License.FILE.get().toPath(), StandardCopyOption.REPLACE_EXISTING);
// clear memoized instance and reload on next access
License.INSTANCE.clear();
}
log.info(importLicenseFile(file) + " has been activated.");
} catch (Throwable e) {
log.severe("License Error: " + e.getMessage());
}
}
public static String getAppStoreName() {