2014-04-19 06:30:29 +00:00
|
|
|
package net.filebot;
|
2009-01-25 00:08:57 +00:00
|
|
|
|
2016-03-09 20:36:28 +00:00
|
|
|
import static net.filebot.Logging.*;
|
2011-11-29 03:14:39 +00:00
|
|
|
|
|
|
|
import java.awt.GraphicsEnvironment;
|
2009-07-27 22:34:42 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.Locale;
|
2014-08-07 09:35:19 +00:00
|
|
|
import java.util.MissingResourceException;
|
2009-07-27 22:34:42 +00:00
|
|
|
import java.util.ResourceBundle;
|
2014-11-04 13:45:27 +00:00
|
|
|
import java.util.logging.Level;
|
2009-01-25 00:08:57 +00:00
|
|
|
import java.util.prefs.BackingStoreException;
|
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
2014-07-29 06:40:35 +00:00
|
|
|
import net.filebot.UserFiles.FileChooser;
|
2015-03-25 22:38:15 +00:00
|
|
|
import net.filebot.archive.Archive.Extractor;
|
2014-04-19 06:30:29 +00:00
|
|
|
import net.filebot.cli.ArgumentBean;
|
|
|
|
import net.filebot.util.PreferencesList;
|
|
|
|
import net.filebot.util.PreferencesMap;
|
|
|
|
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
|
|
|
import net.filebot.util.PreferencesMap.StringAdapter;
|
2009-01-25 00:08:57 +00:00
|
|
|
|
|
|
|
public final class Settings {
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
public static String getApplicationName() {
|
2009-07-27 22:34:42 +00:00
|
|
|
return getApplicationProperty("application.name");
|
2011-12-24 07:30:54 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
public static String getApplicationVersion() {
|
2009-07-27 22:34:42 +00:00
|
|
|
return getApplicationProperty("application.version");
|
2011-12-24 07:30:54 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2012-02-22 08:11:56 +00:00
|
|
|
public static int getApplicationRevisionNumber() {
|
2012-03-07 14:06:10 +00:00
|
|
|
try {
|
|
|
|
return Integer.parseInt(getApplicationProperty("application.revision"));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-22 08:11:56 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-07-27 22:34:42 +00:00
|
|
|
public static String getApplicationProperty(String key) {
|
|
|
|
return ResourceBundle.getBundle(Settings.class.getName(), Locale.ROOT).getString(key);
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2014-08-07 09:35:19 +00:00
|
|
|
public static String getApiKey(String name) {
|
|
|
|
ResourceBundle bundle = ResourceBundle.getBundle(Settings.class.getName(), Locale.ROOT);
|
|
|
|
if (isAppStore()) {
|
|
|
|
try {
|
2014-08-11 05:51:58 +00:00
|
|
|
return bundle.getString("apikey.appstore." + name);
|
2014-08-07 09:35:19 +00:00
|
|
|
} catch (MissingResourceException e) {
|
2016-03-08 09:43:59 +00:00
|
|
|
// use default value
|
2014-08-07 09:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bundle.getString("apikey." + name);
|
|
|
|
}
|
|
|
|
|
2012-06-30 08:46:55 +00:00
|
|
|
public static boolean isUnixFS() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("unixfs"));
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2012-07-17 20:52:03 +00:00
|
|
|
public static boolean useNativeShell() {
|
2012-07-20 03:38:47 +00:00
|
|
|
return Boolean.parseBoolean(System.getProperty("useNativeShell"));
|
2012-07-17 20:52:03 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2013-01-12 02:19:47 +00:00
|
|
|
public static boolean useGVFS() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useGVFS"));
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2012-10-23 19:05:55 +00:00
|
|
|
public static boolean useExtendedFileAttributes() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useExtendedFileAttributes"));
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
|
|
|
public static boolean useCreationDate() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("useCreationDate"));
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:06:26 +00:00
|
|
|
public static boolean useRenameHistory() {
|
|
|
|
return Boolean.parseBoolean(System.getProperty("application.rename.history", "true"));
|
|
|
|
}
|
|
|
|
|
2014-11-17 08:54:40 +00:00
|
|
|
public static String getApplicationDeployment() {
|
2015-06-04 14:39:10 +00:00
|
|
|
return System.getProperty("application.deployment", "jar");
|
2014-08-10 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 14:05:44 +08:00
|
|
|
public static boolean isExecutableJar() {
|
|
|
|
return isApplicationDeployment("jar");
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:35:19 +00:00
|
|
|
public static boolean isAppStore() {
|
2014-11-17 08:54:40 +00:00
|
|
|
return isApplicationDeployment("mas", "usc");
|
|
|
|
}
|
|
|
|
|
2016-07-13 22:02:33 +08:00
|
|
|
public static boolean isWindowsApp() {
|
|
|
|
return isApplicationDeployment("msi");
|
|
|
|
}
|
|
|
|
|
2015-03-09 08:55:10 +00:00
|
|
|
public static boolean isUbuntuApp() {
|
|
|
|
return isApplicationDeployment("usc");
|
|
|
|
}
|
|
|
|
|
2014-11-17 08:54:40 +00:00
|
|
|
public static boolean isMacApp() {
|
|
|
|
return isApplicationDeployment("mas", "app");
|
2014-07-28 12:54:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-31 01:20:27 +00:00
|
|
|
public static boolean isMacSandbox() {
|
2014-11-17 08:54:40 +00:00
|
|
|
return isApplicationDeployment("mas");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInstalled() {
|
|
|
|
return isApplicationDeployment("mas", "usc", "msi", "spk", "aur");
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:27:34 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2014-07-29 06:40:35 +00:00
|
|
|
public static FileChooser getPreferredFileChooser() {
|
2014-08-30 12:07:47 +00:00
|
|
|
return FileChooser.valueOf(System.getProperty("net.filebot.UserFiles.fileChooser", "Swing"));
|
2014-07-29 06:40:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 22:38:15 +00:00
|
|
|
public static Extractor getPreferredArchiveExtractor() {
|
|
|
|
return Extractor.valueOf(System.getProperty("net.filebot.Archive.extractor", "SevenZipNativeBindings"));
|
|
|
|
}
|
|
|
|
|
2012-06-30 08:46:55 +00:00
|
|
|
public static int getPreferredThreadPoolSize() {
|
|
|
|
try {
|
2014-11-04 13:45:27 +00:00
|
|
|
String threadPool = System.getProperty("threadPool");
|
|
|
|
if (threadPool != null) {
|
|
|
|
return Integer.parseInt(threadPool);
|
|
|
|
}
|
2012-06-30 08:46:55 +00:00
|
|
|
} catch (Exception e) {
|
2016-03-09 20:36:28 +00:00
|
|
|
debug.log(Level.WARNING, e.getMessage(), e);
|
2012-06-30 08:46:55 +00:00
|
|
|
}
|
2014-11-04 13:45:27 +00:00
|
|
|
|
|
|
|
return Runtime.getRuntime().availableProcessors();
|
2012-06-30 08:46:55 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2015-03-09 08:55:10 +00:00
|
|
|
public static String getAppStoreName() {
|
|
|
|
if (isMacApp())
|
|
|
|
return "Mac App Store";
|
|
|
|
if (isUbuntuApp())
|
|
|
|
return "Ubuntu Software Center";
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-07 12:30:12 +00:00
|
|
|
public static String getAppStoreLink() {
|
2015-03-09 08:55:10 +00:00
|
|
|
if (isMacApp())
|
2016-03-07 12:30:12 +00:00
|
|
|
return getApplicationProperty("link.mas");
|
2015-03-09 08:55:10 +00:00
|
|
|
if (isUbuntuApp())
|
2016-03-07 12:30:12 +00:00
|
|
|
return getApplicationProperty("link.usc");
|
2015-03-09 08:55:10 +00:00
|
|
|
|
|
|
|
return null;
|
2015-05-09 08:07:38 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 14:39:10 +00:00
|
|
|
public static String getDonateURL() {
|
2015-06-04 15:59:36 +00:00
|
|
|
return getApplicationProperty("donate.url") + "?src=" + getApplicationDeployment();
|
2015-06-04 14:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getEmbeddedHelpURL() {
|
2015-05-11 17:41:37 +00: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 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 11:14:50 +00:00
|
|
|
public static String getApplicationIdentifier() {
|
|
|
|
return String.format("%s %s (r%d)", getApplicationName(), getApplicationVersion(), getApplicationRevisionNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getJavaRuntimeIdentifier() {
|
|
|
|
return String.format("%s %s %s", System.getProperty("java.runtime.name"), System.getProperty("java.version"), GraphicsEnvironment.isHeadless() ? "(headless)" : "").trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String[] applicationArgumentArray;
|
|
|
|
|
|
|
|
protected static void setApplicationArgumentArray(String[] args) {
|
|
|
|
applicationArgumentArray = args;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ArgumentBean getApplicationArguments() {
|
|
|
|
try {
|
|
|
|
return ArgumentBean.parse(applicationArgumentArray);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new IllegalStateException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 18:26:27 +00:00
|
|
|
public static File getApplicationFolder() {
|
|
|
|
return ApplicationFolder.AppData.get(); // added for script compatibility
|
2016-03-12 15:19:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 20:31:08 +00:00
|
|
|
public static Settings forPackage(Class<?> type) {
|
|
|
|
return new Settings(Preferences.userNodeForPackage(type));
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
private final Preferences prefs;
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-02-22 10:45:41 +00:00
|
|
|
private Settings(Preferences prefs) {
|
|
|
|
this.prefs = prefs;
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
public Settings node(String nodeName) {
|
2009-03-15 17:44:39 +00:00
|
|
|
return new Settings(prefs.node(nodeName));
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-03-12 20:08:42 +00:00
|
|
|
public String get(String key) {
|
|
|
|
return get(key, null);
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-03-12 20:08:42 +00:00
|
|
|
public String get(String key, String def) {
|
|
|
|
return prefs.get(key, def);
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
public void put(String key, String value) {
|
2013-02-26 06:21:02 +00:00
|
|
|
if (value != null) {
|
|
|
|
prefs.put(key, value);
|
|
|
|
} else {
|
|
|
|
remove(key);
|
|
|
|
}
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-03-12 20:08:42 +00:00
|
|
|
public void remove(String key) {
|
|
|
|
prefs.remove(key);
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-03-12 20:08:42 +00:00
|
|
|
public PreferencesEntry<String> entry(String key) {
|
|
|
|
return new PreferencesEntry<String>(prefs, key, new StringAdapter());
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-07-18 22:06:32 +00:00
|
|
|
public PreferencesMap<String> asMap() {
|
2009-03-08 18:41:11 +00:00
|
|
|
return PreferencesMap.map(prefs);
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-07-18 22:06:32 +00:00
|
|
|
public PreferencesList<String> asList() {
|
2009-03-08 18:41:11 +00:00
|
|
|
return PreferencesList.map(prefs);
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
public void clear() {
|
|
|
|
try {
|
|
|
|
// remove child nodes
|
|
|
|
for (String nodeName : prefs.childrenNames()) {
|
|
|
|
prefs.node(nodeName).removeNode();
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
// remove entries
|
|
|
|
prefs.clear();
|
|
|
|
} catch (BackingStoreException e) {
|
2016-03-27 20:40:27 +00:00
|
|
|
debug.warning(e.getMessage());
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:51:47 +00:00
|
|
|
|
2009-01-25 00:08:57 +00:00
|
|
|
}
|