X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FInstance.java;h=2479c612dc45b97cf224158c36640c88721ecc42;hb=b7cd9db81ba27c67fdd8dd5a42b5f9e4137622db;hp=c547a2b121bdf07ae3e48ad146ad28ea07ed9c04;hpb=e39e560faae7c7bf3cf6fb098be5c4b209ac29e3;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index c547a2b..2479c61 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -17,6 +17,7 @@ import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.library.RemoteLibrary; import be.nikiroo.utils.Cache; import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.Image; import be.nikiroo.utils.Proxy; import be.nikiroo.utils.TempFiles; import be.nikiroo.utils.TraceHandler; @@ -41,7 +42,42 @@ public class Instance { private static TraceHandler tracer; private static TempFiles tempFiles; - static { + private static boolean init; + + /** + * Initialise the instance -- if already initialised, nothing will happen. + *

+ * Before calling this method, you may call + * {@link Bundles#setDirectory(String)} if wanted. + */ + static public void init() { + init(false); + } + + /** + * Initialise the instance -- if already initialised, nothing will happen + * unless you pass TRUE to force. + *

+ * Before calling this method, you may call + * {@link Bundles#setDirectory(String)} if wanted. + *

+ * Note: forcing the initialisation can be dangerous, so make sure to only + * make it under controlled circumstances -- for instance, at the start of + * the program, you could call {@link Instance#init()}, change some settings + * because you want to force those settings (it will also forbid users to + * change them!) and then call {@link Instance#init(boolean)} with + * force set to TRUE. + * + * @param force + * force the initialisation even if already initialised + */ + static public void init(boolean force) { + if (init && !force) { + return; + } + + init = true; + // Before we can configure it: Boolean debug = checkEnv("DEBUG"); boolean trace = debug != null && debug; @@ -71,17 +107,17 @@ public class Instance { remoteDir = new File(configDir, "remote"); lib = createDefaultLibrary(remoteDir); - // create cache + // create cache and TMP + Image.setTemporaryFilesRoot(new File(configDir, "tmp.images")); File tmp = getFile(Config.CACHE_DIR); if (tmp == null) { // Could have used: System.getProperty("java.io.tmpdir") tmp = new File(configDir, "tmp"); } - String ua = config.getString(Config.USER_AGENT); + String ua = config.getString(Config.USER_AGENT, ""); try { - int hours = config.getInteger(Config.CACHE_MAX_TIME_CHANGING, -1); - int hoursLarge = config - .getInteger(Config.CACHE_MAX_TIME_STABLE, -1); + int hours = config.getInteger(Config.CACHE_MAX_TIME_CHANGING, 0); + int hoursLarge = config.getInteger(Config.CACHE_MAX_TIME_STABLE, 0); cache = new DataLoader(tmp, ua, hours, hoursLarge); } catch (IOException e) { tracer.error(new IOException( @@ -295,7 +331,7 @@ public class Instance { */ public static boolean isVersionCheckNeeded() { try { - long wait = config.getInteger(Config.UPDATE_INTERVAL, 1) * 24 * 60 + long wait = config.getInteger(Config.UPDATE_INTERVAL, 0) * 24 * 60 * 60 * 1000; if (wait >= 0) { String lastUpString = IOUtils.readSmallFile(new File(configDir, @@ -439,6 +475,7 @@ public class Instance { + getFile(libDir), e)); } } else { + Exception ex = null; int pos = remoteLib.lastIndexOf(":"); if (pos >= 0) { String port = remoteLib.substring(pos + 1).trim(); @@ -457,13 +494,14 @@ public class Instance { lib); } catch (Exception e) { + ex = e; } } } if (lib == null) { tracer.error(new IOException( - "Cannot create remote library for: " + remoteLib)); + "Cannot create remote library for: " + remoteLib, ex)); } } @@ -547,7 +585,7 @@ public class Instance { private static String getLang() { String lang = config.getString(Config.LANG); - if (lang == null | lang.isEmpty()) { + if (lang == null || lang.isEmpty()) { if (System.getenv("LANG") != null && !System.getenv("LANG").isEmpty()) { lang = System.getenv("LANG");