+ public static File getRemoteDir(String host) {
+ return getRemoteDir(remoteDir, host);
+ }
+
+ /**
+ * Return the directory where to store temporary files for the remote
+ * {@link LocalLibrary}.
+ *
+ * @param remoteDir
+ * the base remote directory
+ * @param host
+ * the remote for this host
+ *
+ * @return the directory
+ */
+ private static File getRemoteDir(File remoteDir, String host) {
+ remoteDir.mkdirs();
+
+ if (host != null) {
+ return new File(remoteDir, host);
+ }
+
+ return remoteDir;
+ }
+
+ /**
+ * Check if we need to check that a new version of Fanfix is available.
+ *
+ * @return TRUE if we need to
+ */
+ public static boolean isVersionCheckNeeded() {
+ try {
+ long wait = config.getInteger(Config.UPDATE_INTERVAL, 1) * 24 * 60
+ * 60 * 1000;
+ if (wait >= 0) {
+ String lastUpString = IOUtils.readSmallFile(new File(configDir,
+ "LAST_UPDATE"));
+ long delay = new Date().getTime()
+ - Long.parseLong(lastUpString);
+ if (delay > wait) {
+ return true;
+ }
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ // No file or bad file:
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Notify that we checked for a new version of Fanfix.
+ */
+ public static void setVersionChecked() {
+ try {
+ IOUtils.writeSmallFile(new File(configDir), "LAST_UPDATE",
+ Long.toString(new Date().getTime()));
+ } catch (IOException e) {
+ tracer.error(e);
+ }
+ }
+
+ /**
+ * The facility to use temporary files in this program.
+ * <p>
+ * <b>MUST</b> be closed at end of program.
+ *
+ * @return the facility
+ */
+ public static TempFiles getTempFiles() {
+ return tempFiles;
+ }
+
+ /**
+ * The configuration directory (will check, in order of preference,
+ * {@link Bundles#getDirectory()}, the system properties, the environment
+ * and then defaults to $HOME/.fanfix).
+ *
+ * @return the config directory
+ */
+ private static String getConfigDir() {
+ String configDir = Bundles.getDirectory();
+
+ if (configDir == null) {
+ configDir = System.getProperty("CONFIG_DIR");
+ }
+
+ if (configDir == null) {
+ configDir = System.getenv("CONFIG_DIR");
+ }
+
+ if (configDir == null) {
+ configDir = new File(getHome(), ".fanfix").getPath();
+ }
+
+ return configDir;
+ }
+
+ /**
+ * Create the config variables ({@link Instance#config},
+ * {@link Instance#uiconfig}, {@link Instance#trans} and
+ * {@link Instance#transGui}).
+ *
+ * @param configDir
+ * the directory where to find the configuration files
+ * @param refresh
+ * TRUE to reset the configuration files from the default
+ * included ones
+ */
+ private static void createConfigs(String configDir, boolean refresh) {
+ if (!refresh) {
+ Bundles.setDirectory(configDir);
+ }
+
+ try {
+ config = new ConfigBundle();
+ config.updateFile(configDir);
+ } catch (IOException e) {
+ tracer.error(e);
+ }
+
+ try {
+ uiconfig = new UiConfigBundle();
+ uiconfig.updateFile(configDir);
+ } catch (IOException e) {
+ tracer.error(e);
+ }
+
+ // No updateFile for this one! (we do not want the user to have custom
+ // translations that won't accept updates from newer versions)
+ trans = new StringIdBundle(getLang());
+ transGui = new StringIdGuiBundle(getLang());
+
+ // Fix an old bug (we used to store custom translation files by
+ // default):
+ if (trans.getString(StringId.INPUT_DESC_CBZ) == null) {
+ trans.deleteFile(configDir);
+ }
+
+ Boolean noutf = checkEnv("NOUTF");
+ if (noutf != null && noutf) {
+ trans.setUnicode(false);
+ transGui.setUnicode(false);
+ }
+
+ Bundles.setDirectory(configDir);
+ }
+
+ /**
+ * Create the default library as specified by the config.
+ *
+ * @param remoteDir
+ * the base remote directory if needed
+ *
+ * @return the default {@link BasicLibrary}
+ */
+ private static BasicLibrary createDefaultLibrary(File remoteDir) {
+ BasicLibrary lib = null;
+
+ String remoteLib = config.getString(Config.DEFAULT_LIBRARY);
+ if (remoteLib == null || remoteLib.trim().isEmpty()) {
+ String libDir = System.getProperty("fanfix.libdir");
+ if (libDir == null || libDir.isEmpty()) {
+ libDir = config.getString(Config.LIBRARY_DIR);
+ }
+ try {
+ lib = new LocalLibrary(getFile(libDir));
+ } catch (Exception e) {
+ tracer.error(new IOException(
+ "Cannot create library for directory: "
+ + getFile(libDir), e));
+ }