2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot;
|
2009-01-24 19:08:57 -05:00
|
|
|
|
2016-03-09 15:36:28 -05:00
|
|
|
import static net.filebot.Logging.*;
|
2011-11-28 22:14:39 -05:00
|
|
|
|
2018-03-17 08:43:06 -04:00
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
2009-07-27 18:34:42 -04:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.ResourceBundle;
|
2014-11-04 08:45:27 -05:00
|
|
|
import java.util.logging.Level;
|
2009-01-24 19:08:57 -05:00
|
|
|
import java.util.prefs.BackingStoreException;
|
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
2014-07-29 02:40:35 -04:00
|
|
|
import net.filebot.UserFiles.FileChooser;
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.cli.ArgumentBean;
|
|
|
|
import net.filebot.util.PreferencesList;
|
|
|
|
import net.filebot.util.PreferencesMap;
|
2016-08-10 19:06:18 -04:00
|
|
|
import net.filebot.util.PreferencesMap.JsonAdapter;
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
|
|
|
import net.filebot.util.PreferencesMap.StringAdapter;
|
2009-01-24 19:08:57 -05:00
|
|
|
|
|
|
|
public final class Settings {
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
public static String getApplicationName() {
|
2009-07-27 18:34:42 -04:00
|
|
|
return getApplicationProperty("application.name");
|
2011-12-24 02:30:54 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
public static String getApplicationVersion() {
|
2009-07-27 18:34:42 -04:00
|
|
|
return getApplicationProperty("application.version");
|
2011-12-24 02:30:54 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2012-02-22 03:11:56 -05:00
|
|
|
public static int getApplicationRevisionNumber() {
|
2012-03-07 09:06:10 -05:00
|
|
|
try {
|
|
|
|
return Integer.parseInt(getApplicationProperty("application.revision"));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-22 03:11:56 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-07-27 18:34:42 -04:00
|
|
|
public static String getApplicationProperty(String key) {
|
|
|
|
return ResourceBundle.getBundle(Settings.class.getName(), Locale.ROOT).getString(key);
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2014-08-07 05:35:19 -04:00
|
|
|
public static String getApiKey(String name) {
|
2018-01-19 15:55:19 -05:00
|
|
|
return getApplicationProperty("apikey." + name);
|
2014-08-07 05:35:19 -04:00
|
|
|
}
|
|
|
|
|
2012-06-30 04:46:55 -04:00
|
|
|
public static boolean isUnixFS() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("unixfs"));
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2012-07-17 16:52:03 -04:00
|
|
|
public static boolean useNativeShell() {
|
2012-07-19 23:38:47 -04:00
|
|
|
return Boolean.parseBoolean(System.getProperty("useNativeShell"));
|
2012-07-17 16:52:03 -04:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2013-01-11 21:19:47 -05:00
|
|
|
public static boolean useGVFS() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useGVFS"));
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2012-10-23 15:05:55 -04:00
|
|
|
public static boolean useExtendedFileAttributes() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useExtendedFileAttributes"));
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
|
|
|
public static boolean useCreationDate() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useCreationDate"));
|
|
|
|
}
|
|
|
|
|
2016-03-05 16:06:26 -05:00
|
|
|
public static boolean useRenameHistory() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("application.rename.history", "true"));
|
|
|
|
}
|
|
|
|
|
2014-11-17 03:54:40 -05:00
|
|
|
public static String getApplicationDeployment() {
|
2015-06-04 10:39:10 -04:00
|
|
|
return System.getProperty("application.deployment", "jar");
|
2014-08-10 02:31:47 -04:00
|
|
|
}
|
|
|
|
|
2017-06-18 02:42:19 -04:00
|
|
|
public static boolean isPortableApp() {
|
|
|
|
return isApplicationDeployment("portable", "jar");
|
2016-06-05 02:05:44 -04:00
|
|
|
}
|
|
|
|
|
2014-08-07 05:35:19 -04:00
|
|
|
public static boolean isAppStore() {
|
2016-09-19 03:00:18 -04:00
|
|
|
return isApplicationDeployment("mas", "appx");
|
2014-11-17 03:54:40 -05:00
|
|
|
}
|
|
|
|
|
2016-07-13 10:02:33 -04:00
|
|
|
public static boolean isWindowsApp() {
|
2016-09-19 03:00:18 -04:00
|
|
|
return isApplicationDeployment("appx", "msi");
|
2016-07-13 10:02:33 -04:00
|
|
|
}
|
|
|
|
|
2015-03-09 04:55:10 -04:00
|
|
|
public static boolean isUbuntuApp() {
|
2017-02-15 11:58:43 -05:00
|
|
|
return isApplicationDeployment("deb", "snap");
|
2015-03-09 04:55:10 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:54:40 -05:00
|
|
|
public static boolean isMacApp() {
|
2018-03-02 15:07:26 -05:00
|
|
|
return isApplicationDeployment("mas", "cask");
|
2014-07-28 08:54:34 -04:00
|
|
|
}
|
|
|
|
|
2014-07-30 21:20:27 -04:00
|
|
|
public static boolean isMacSandbox() {
|
2014-11-17 03:54:40 -05:00
|
|
|
return isApplicationDeployment("mas");
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:05:41 -05:00
|
|
|
public static boolean isAutoUpdateEnabled() {
|
|
|
|
return isApplicationDeployment("mas", "appx", "snap", "spk", "aur");
|
2014-11-17 03:54:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isApplicationDeployment(String... ids) {
|
|
|
|
String current = getApplicationDeployment();
|
|
|
|
for (String id : ids) {
|
|
|
|
if (current != null && current.equals(id))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-25 12:27:34 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2016-10-21 14:35:48 -04:00
|
|
|
public static String getApplicationUserModelID() {
|
|
|
|
return System.getProperty("net.filebot.AppUserModelID", getApplicationName());
|
|
|
|
}
|
|
|
|
|
2014-07-29 02:40:35 -04:00
|
|
|
public static FileChooser getPreferredFileChooser() {
|
2014-08-30 08:07:47 -04:00
|
|
|
return FileChooser.valueOf(System.getProperty("net.filebot.UserFiles.fileChooser", "Swing"));
|
2014-07-29 02:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-06-30 04:46:55 -04:00
|
|
|
public static int getPreferredThreadPoolSize() {
|
|
|
|
try {
|
2014-11-04 08:45:27 -05:00
|
|
|
String threadPool = System.getProperty("threadPool");
|
|
|
|
if (threadPool != null) {
|
|
|
|
return Integer.parseInt(threadPool);
|
|
|
|
}
|
2012-06-30 04:46:55 -04:00
|
|
|
} catch (Exception e) {
|
2016-03-09 15:36:28 -05:00
|
|
|
debug.log(Level.WARNING, e.getMessage(), e);
|
2012-06-30 04:46:55 -04:00
|
|
|
}
|
2014-11-04 08:45:27 -05:00
|
|
|
|
|
|
|
return Runtime.getRuntime().availableProcessors();
|
2012-06-30 04:46:55 -04:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2015-03-09 04:55:10 -04:00
|
|
|
public static String getAppStoreName() {
|
|
|
|
if (isMacApp())
|
|
|
|
return "Mac App Store";
|
2016-09-19 03:00:18 -04:00
|
|
|
if (isWindowsApp())
|
|
|
|
return "Windows Store";
|
2015-03-09 04:55:10 -04:00
|
|
|
if (isUbuntuApp())
|
|
|
|
return "Ubuntu Software Center";
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-07 07:30:12 -05:00
|
|
|
public static String getAppStoreLink() {
|
2015-03-09 04:55:10 -04:00
|
|
|
if (isMacApp())
|
2016-03-07 07:30:12 -05:00
|
|
|
return getApplicationProperty("link.mas");
|
2016-09-19 03:00:18 -04:00
|
|
|
if (isWindowsApp())
|
2016-10-05 09:48:59 -04:00
|
|
|
return getApplicationProperty("link.mws");
|
2015-03-09 04:55:10 -04:00
|
|
|
if (isUbuntuApp())
|
2016-09-19 03:00:18 -04:00
|
|
|
return null;
|
2015-03-09 04:55:10 -04:00
|
|
|
|
|
|
|
return null;
|
2015-05-09 04:07:38 -04:00
|
|
|
}
|
|
|
|
|
2015-06-04 10:39:10 -04:00
|
|
|
public static String getDonateURL() {
|
2015-06-04 11:59:36 -04:00
|
|
|
return getApplicationProperty("donate.url") + "?src=" + getApplicationDeployment();
|
2015-06-04 10:39:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getEmbeddedHelpURL() {
|
2015-05-11 13:41:37 -04:00
|
|
|
// add #hash so we can dynamically adjust the slides for the various platforms via JavaScript
|
|
|
|
return getApplicationProperty("link.app.help") + '#' + getApplicationDeployment();
|
2015-05-10 14:06:04 -04:00
|
|
|
}
|
|
|
|
|
2016-03-11 06:14:50 -05:00
|
|
|
public static String getApplicationIdentifier() {
|
|
|
|
return String.format("%s %s (r%d)", getApplicationName(), getApplicationVersion(), getApplicationRevisionNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getJavaRuntimeIdentifier() {
|
2016-10-18 14:30:07 -04:00
|
|
|
return String.format("%s %s", System.getProperty("java.runtime.name"), System.getProperty("java.version"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getSystemIdentifier() {
|
|
|
|
return String.format("%s %s (%s)", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
|
2016-03-11 06:14:50 -05:00
|
|
|
}
|
|
|
|
|
2016-10-18 13:02:51 -04:00
|
|
|
private static ArgumentBean applicationArguments;
|
2016-03-11 06:14:50 -05:00
|
|
|
|
2016-10-18 13:02:51 -04:00
|
|
|
public static void setApplicationArguments(ArgumentBean args) {
|
|
|
|
applicationArguments = args;
|
2016-03-11 06:14:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public static ArgumentBean getApplicationArguments() {
|
2016-10-18 13:02:51 -04:00
|
|
|
return applicationArguments;
|
2016-03-11 06:14:50 -05:00
|
|
|
}
|
|
|
|
|
2009-07-29 16:31:08 -04:00
|
|
|
public static Settings forPackage(Class<?> type) {
|
|
|
|
return new Settings(Preferences.userNodeForPackage(type));
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
private final Preferences prefs;
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-02-22 05:45:41 -05:00
|
|
|
private Settings(Preferences prefs) {
|
|
|
|
this.prefs = prefs;
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
public Settings node(String nodeName) {
|
2009-03-15 13:44:39 -04:00
|
|
|
return new Settings(prefs.node(nodeName));
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-03-12 16:08:42 -04:00
|
|
|
public String get(String key) {
|
|
|
|
return get(key, null);
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-03-12 16:08:42 -04:00
|
|
|
public String get(String key, String def) {
|
|
|
|
return prefs.get(key, def);
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
public void put(String key, String value) {
|
2013-02-26 01:21:02 -05:00
|
|
|
if (value != null) {
|
|
|
|
prefs.put(key, value);
|
|
|
|
} else {
|
|
|
|
remove(key);
|
|
|
|
}
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-03-12 16:08:42 -04:00
|
|
|
public void remove(String key) {
|
|
|
|
prefs.remove(key);
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-03-12 16:08:42 -04:00
|
|
|
public PreferencesEntry<String> entry(String key) {
|
|
|
|
return new PreferencesEntry<String>(prefs, key, new StringAdapter());
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-07-18 18:06:32 -04:00
|
|
|
public PreferencesMap<String> asMap() {
|
2009-03-08 14:41:11 -04:00
|
|
|
return PreferencesMap.map(prefs);
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2016-08-10 22:19:12 -04:00
|
|
|
public <T> PreferencesMap<T> asMap(Class<T> cls) {
|
2016-08-10 19:06:18 -04:00
|
|
|
return PreferencesMap.map(prefs, new JsonAdapter(cls));
|
|
|
|
}
|
|
|
|
|
2009-07-18 18:06:32 -04:00
|
|
|
public PreferencesList<String> asList() {
|
2009-03-08 14:41:11 -04:00
|
|
|
return PreferencesList.map(prefs);
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2016-08-10 22:19:12 -04:00
|
|
|
public <T> PreferencesList<T> asList(Class<T> cls) {
|
2016-08-10 19:06:18 -04:00
|
|
|
return PreferencesList.map(prefs, new JsonAdapter(cls));
|
|
|
|
}
|
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
public void clear() {
|
|
|
|
try {
|
|
|
|
// remove child nodes
|
|
|
|
for (String nodeName : prefs.childrenNames()) {
|
|
|
|
prefs.node(nodeName).removeNode();
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
// remove entries
|
|
|
|
prefs.clear();
|
|
|
|
} catch (BackingStoreException e) {
|
2016-03-27 16:40:27 -04:00
|
|
|
debug.warning(e.getMessage());
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|
|
|
|
}
|
2014-01-25 22:51:47 -05:00
|
|
|
|
2018-03-17 08:43:06 -04:00
|
|
|
public static void store(File f) {
|
|
|
|
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(f))) {
|
|
|
|
Preferences.userRoot().exportSubtree(out);
|
|
|
|
} catch (Exception e) {
|
|
|
|
debug.log(Level.SEVERE, e, e::toString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void restore(File f) {
|
|
|
|
try (InputStream in = new BufferedInputStream(new FileInputStream(f))) {
|
|
|
|
Preferences.importPreferences(in);
|
|
|
|
} catch (Exception e) {
|
|
|
|
debug.log(Level.SEVERE, e, e::toString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
}
|