From 459b4c289549a464f9add6e49a2742009e1db4ef Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 18 Sep 2019 22:21:40 +0200 Subject: [PATCH] change config format to config5 --- src/be/nikiroo/fanfix/Instance.java | 51 +++---- src/be/nikiroo/fanfix/bundles/Config.java | 21 ++- .../nikiroo/fanfix/bundles/ConfigBundle.java | 2 +- src/be/nikiroo/fanfix/bundles/Target.java | 4 +- .../nikiroo/fanfix/bundles/config.properties | 125 ------------------ src/be/nikiroo/fanfix/bundles/ui.properties | 30 ----- .../fanfix/reader/ui/GuiReaderFrame.java | 2 +- .../reader/ui/GuiReaderPropertiesFrame.java | 2 +- 8 files changed, 43 insertions(+), 194 deletions(-) delete mode 100644 src/be/nikiroo/fanfix/bundles/config.properties delete mode 100644 src/be/nikiroo/fanfix/bundles/ui.properties diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index a646232..561e2f6 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -451,8 +451,26 @@ public class Instance { private static BasicLibrary createDefaultLibrary(File remoteDir) { BasicLibrary lib = null; - String remoteLib = config.getString(Config.DEFAULT_LIBRARY); - if (remoteLib == null || remoteLib.trim().isEmpty()) { + boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED, + false); + + if (useRemote) { + String host = null; + int port = -1; + try { + host = config.getString(Config.REMOTE_LIBRARY_HOST); + port = config.getInteger(Config.REMOTE_LIBRARY_PORT, -1); + String key = config.getString(Config.REMOTE_LIBRARY_KEY); + + tracer.trace("Selecting remote library " + host + ":" + port); + lib = new RemoteLibrary(key, host, port); + lib = new CacheLibrary(getRemoteDir(remoteDir, host), lib); + } catch (Exception e) { + tracer.error(new IOException( + "Cannot create remote library for: " + host + ":" + + port, e)); + } + } else { String libDir = System.getenv("BOOKS_DIR"); if (libDir == null || libDir.isEmpty()) { libDir = config.getString(Config.LIBRARY_DIR, "$HOME/Books"); @@ -467,35 +485,6 @@ public class Instance { "Cannot create library for directory: " + getFile(libDir), e)); } - } else { - Exception ex = null; - int pos = remoteLib.lastIndexOf(":"); - if (pos >= 0) { - String port = remoteLib.substring(pos + 1).trim(); - remoteLib = remoteLib.substring(0, pos); - pos = remoteLib.lastIndexOf(":"); - if (pos >= 0) { - String host = remoteLib.substring(pos + 1).trim(); - String key = remoteLib.substring(0, pos).trim(); - - try { - tracer.trace("Selecting remote library " + host + ":" - + port); - lib = new RemoteLibrary(key, host, - Integer.parseInt(port)); - lib = new CacheLibrary(getRemoteDir(remoteDir, host), - lib); - - } catch (Exception e) { - ex = e; - } - } - } - - if (lib == null) { - tracer.error(new IOException( - "Cannot create remote library for: " + remoteLib, ex)); - } } return lib; diff --git a/src/be/nikiroo/fanfix/bundles/Config.java b/src/be/nikiroo/fanfix/bundles/Config.java index e62a524..7360f39 100644 --- a/src/be/nikiroo/fanfix/bundles/Config.java +++ b/src/be/nikiroo/fanfix/bundles/Config.java @@ -11,7 +11,7 @@ import be.nikiroo.utils.resources.Meta.Format; @SuppressWarnings("javadoc") public enum Config { @Meta(description = "The language to use for in the program (example: en-GB, fr-BE...) or nothing for default system language (can be overwritten with the variable $LANG)",// - format = Format.LOCALE) + format = Format.LOCALE, list = { "en-GB", "fr-BE" }) LANG, // @Meta(description = "The default reader type to use to read stories:\nCLI = simple output to console\nTUI = a Text User Interface with menus and windows, based upon Jexer\nGUI = a GUI with locally stored files, based upon Swing", // format = Format.FIXED_LIST, list = { "CLI", "GUI", "TUI" }, def = "GUI") @@ -52,9 +52,22 @@ public enum Config { @Meta(description = "The directory where to store the library (can be overriden by the envvironment variable \"BOOKS_DIR\"; any relative path uses the applciation config directory as base, $HOME notation is supported, / is always accepted as directory separator",// format = Format.DIRECTORY, def = "$HOME/Books/") LIBRARY_DIR, // - @Meta(description = "The default library to use (KEY:SERVER:PORT), or empty for the local library",// - format = Format.STRING, def = "") - DEFAULT_LIBRARY, // + + @Meta(description = "Remote library\nA remote library can be configured to fetch the stories from a remote Fanfix server",// + group = true) + REMOTE_LIBRARY, // + @Meta(description = "Use the remote Fanfix server configured here instead of the local library (if FALSE, the local library will be used instead)",// + format = Format.BOOLEAN, def = "false") + REMOTE_LIBRARY_ENABLED, // + @Meta(description = "The remote Fanfix server to connect to",// + format = Format.STRING) + REMOTE_LIBRARY_HOST, // + @Meta(description = "The port to use for the remote Fanfix server",// + format = Format.INT, def = "58365") + REMOTE_LIBRARY_PORT, // + @Meta(description = "The key is structured: \"KEY|SUBKEY|wl|rw\"\n- \"KEY\" is the actual encryption key (it can actually be empty, which will still encrypt the messages but of course it will be easier to guess the key)\n- \"SUBKEY\" is the (optional) subkey to use to get additional privileges\n- \"wl\" is a special privilege that allows that subkey to ignore white lists\n- \"rw\" is a special privilege that allows that subkey to modify the library, even if it is not in RW (by default) mode\n\nSome examples:\n- \"super-secret\": a normal key, no special privileges\n- \"you-will-not-guess|azOpd8|wl\": a white-list ignoring key\n- \"new-password|subpass|rw\": a key that allows modifications on the library",// + format = Format.PASSWORD) + REMOTE_LIBRARY_KEY, // @Meta(description = "Network configuration",// group = true) diff --git a/src/be/nikiroo/fanfix/bundles/ConfigBundle.java b/src/be/nikiroo/fanfix/bundles/ConfigBundle.java index cfe064e..ce72b3d 100644 --- a/src/be/nikiroo/fanfix/bundles/ConfigBundle.java +++ b/src/be/nikiroo/fanfix/bundles/ConfigBundle.java @@ -15,7 +15,7 @@ public class ConfigBundle extends Bundle { * Create a new {@link ConfigBundle}. */ public ConfigBundle() { - super(Config.class, Target.config, null); + super(Config.class, Target.config5, null); } /** diff --git a/src/be/nikiroo/fanfix/bundles/Target.java b/src/be/nikiroo/fanfix/bundles/Target.java index b530c07..64284c6 100644 --- a/src/be/nikiroo/fanfix/bundles/Target.java +++ b/src/be/nikiroo/fanfix/bundles/Target.java @@ -5,6 +5,8 @@ import be.nikiroo.utils.resources.Bundle; /** * The type of configuration information the associated {@link Bundle} will * convey. + *

+ * Those values can change when the file is not compatible anymore. * * @author niki */ @@ -13,7 +15,7 @@ public enum Target { * Configuration options that the user can change in the * .properties file */ - config, + config5, /** Translation resources (Core) */ resources_core, /** Translation resources (GUI) */ diff --git a/src/be/nikiroo/fanfix/bundles/config.properties b/src/be/nikiroo/fanfix/bundles/config.properties deleted file mode 100644 index 604483f..0000000 --- a/src/be/nikiroo/fanfix/bundles/config.properties +++ /dev/null @@ -1,125 +0,0 @@ -# Configuration options -# - - -# The language (example: en-GB, fr-BE...) or nothing for default system language (can be overwritten with the variable $LANG) -# (FORMAT: LOCALE) -#LANG = -# The default reader type to use to read stories: -# CLI = simple output to console -# TUI = a Text User Interface with menus and windows, based upon Jexer -# GUI = a GUI with locally stored files, based upon Swing -# (FORMAT: FIXED_LIST) -# ALLOWED VALUES: "CLI", "GUI", "TUI" -#READER_TYPE = GUI -# The type of output for the Local Reader for non-images documents -# (FORMAT: FIXED_LIST) -# ALLOWED VALUES: "INFO_TEXT", "EPUB", "HTML", "TEXT" -#NON_IMAGES_DOCUMENT_TYPE = INFO_TEXT -# The type of output for the Local Reader for non-images documents -# (FORMAT: FIXED_LIST) -# ALLOWED VALUES: "CBZ", "HTML" -#IMAGES_DOCUMENT_TYPE = CBZ -# The directory where to store temporary files; any relative path uses the applciation config directory as base, $HOME notation is supported, / is always accepted as directory separator -# (FORMAT: DIRECTORY) -#CACHE_DIR = tmp/ -# The delay in hours after which a cached resource that is thought to change ~often is considered too old and triggers a refresh delay (or 0 for no cache, or -1 for infinite time) -# (FORMAT: INT) -#CACHE_MAX_TIME_CHANGING = 24 -# The delay in hours after which a cached resource that is thought to change rarely is considered too old and triggers a refresh delay (or 0 for no cache, or -1 for infinite time) -# (FORMAT: INT) -#CACHE_MAX_TIME_STABLE = 720 -# The user-agent to use to download files -# (FORMAT: STRING) -#USER_AGENT = Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0 -- ELinks/0.9.3 (Linux 2.6.11 i686; 80x24) -- Fanfix (https://github.com/nikiroo/fanfix/) -# The directory where to get the default story covers; any relative path uses the applciation config directory as base, $HOME notation is supported, / is always accepted as directory separator -# (FORMAT: DIRECTORY) -#DEFAULT_COVERS_DIR = covers/ -# The default library to use (KEY:SERVER:PORT), or empty for the local library -# (FORMAT: STRING) -#DEFAULT_LIBRARY = -# The port on which we can start the server (must be a valid port, from 1 to 65535) -# (FORMAT: INT) -#SERVER_PORT = 58365 -# The encryption key for the server (NOT including a subkey), it cannot contain the pipe character "|" but can be empty (it is *still* encrypted, but with an empty, easy to guess key) -# (FORMAT: PASSWORD) -#SERVER_KEY = -# Allow write access to the clients (download story, move story...) without RW subkeys -# (FORMAT: BOOLEAN) -#SERVER_RW = true -# If not empty, only the EXACT listed sources will be available for clients without BL subkeys -# (FORMAT: STRING) -# (This item accepts a list of escaped comma-separated values) -#SERVER_WHITELIST = -# The subkeys that the server will allow, including the modes -# (FORMAT: STRING) -# (This item accepts a list of escaped comma-separated values) -#SERVER_ALLOWED_SUBKEYS = -# The directory where to store the library (can be overriden by the envvironment variable "BOOKS_DIR"; any relative path uses the applciation config directory as base, $HOME notation is supported, / is always accepted as directory separator -# (FORMAT: DIRECTORY) -#LIBRARY_DIR = $HOME/Books/ -# Show debug information on errors -# (FORMAT: BOOLEAN) -#DEBUG_ERR = false -# Show debug trace information -# (FORMAT: BOOLEAN) -#DEBUG_TRACE = false -# Image format to use for cover images -# (FORMAT: FIXED_LIST) -# ALLOWED VALUES: "PNG", "JPG", "BMP" -#IMAGE_FORMAT_COVER = PNG -# Image format to use for content images -# (FORMAT: FIXED_LIST) -# ALLOWED VALUES: "PNG", "JPG", "BMP" -#IMAGE_FORMAT_CONTENT = jpg -# -# This item is used as a group, its content is not expected to be used. -#LATEX_LANG = -# LaTeX output language (full name) for "English" -# (FORMAT: STRING) -#LATEX_LANG_EN = english -# LaTeX output language (full name) for "French" -# (FORMAT: STRING) -#LATEX_LANG_FR = french -# other 'by' prefixes before author name, used to identify the author -# (FORMAT: STRING) -# (This item accepts a list of escaped comma-separated values) -#BYS = "by","par","de","©","(c)" -# List of languages codes used for chapter identification (should not be changed) -# (FORMAT: STRING) -# (This item accepts a list of escaped comma-separated values) -#CHAPTER = "EN","FR" -# Chapter identification string in English, used to identify a starting chapter in text mode -# (FORMAT: STRING) -#CHAPTER_EN = Chapter -# Chapter identification string in French, used to identify a starting chapter in text mode -# (FORMAT: STRING) -#CHAPTER_FR = Chapitre -# Login for YiffStar to have access to all the stories (should not be necessary anymore, but can still be used) -# (FORMAT: STRING) -#LOGIN_YIFFSTAR_USER = -# Password for YiffStar to have access to all the stories (should not be necessary anymore, but can still be used) -# (FORMAT: PASSWORD) -#LOGIN_YIFFSTAR_PASS = -# If the last update check was done at least that many days ago, check for updates at startup (-1 for 'no checks') -# (FORMAT: INT) -#UPDATE_INTERVAL = 1 -# The proxy server to use under the format 'user:pass@proxy:port', 'user@proxy:port', 'proxy:port' or ':' alone (system proxy); an empty String means no proxy -# (FORMAT: STRING) -#USE_PROXY = -# FimFiction APIKEY credentials -# FimFiction can be queried via an API, but requires an API key to do that. One has been created for this program, but if you have another API key you can set it here. You can also set a login and password instead, in that case, a new API key will be generated (and stored) if you still haven't set one. -# This item is used as a group, its content is not expected to be used. -#LOGIN_FIMFICTION_APIKEY = -# The login of the API key used to create a new token from FimFiction -# (FORMAT: STRING) -#LOGIN_FIMFICTION_APIKEY_CLIENT_ID = -# The password of the API key used to create a new token from FimFiction -# (FORMAT: PASSWORD) -#LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET = -# Do not use the new API, even if we have a token, and force HTML scraping -# (FORMAT: BOOLEAN) -#LOGIN_FIMFICTION_APIKEY_FORCE_HTML = false -# The token required to use the beta APIv2 from FimFiction (see APIKEY_CLIENT_* if you want to generate a new one from your own API key) -# (FORMAT: PASSWORD) -#LOGIN_FIMFICTION_APIKEY_TOKEN = Bearer WnZ5oHlzQoDocv1GcgHfcoqctHkSwL-D diff --git a/src/be/nikiroo/fanfix/bundles/ui.properties b/src/be/nikiroo/fanfix/bundles/ui.properties deleted file mode 100644 index dbb1bb8..0000000 --- a/src/be/nikiroo/fanfix/bundles/ui.properties +++ /dev/null @@ -1,30 +0,0 @@ -# UI configuration options -# - - -# The directory where to store temporary files for the GUI reader; any relative path uses the applciation config directory as base, $HOME notation is supported, / is always accepted as directory separator -# (FORMAT: DIRECTORY) -#CACHE_DIR_LOCAL_READER = tmp-reader/ -# How to save the cached stories for the GUI Reader (non-images documents) -- those files will be sent to the reader -# (FORMAT: COMBO_LIST) -# ALLOWED VALUES: "INFO_TEXT", "EPUB", "HTML", "TEXT" -#GUI_NON_IMAGES_DOCUMENT_TYPE = EPUB -# How to save the cached stories for the GUI Reader (images documents) -- those files will be sent to the reader -# (FORMAT: COMBO_LIST) -# ALLOWED VALUES: "CBZ", "HTML" -#GUI_IMAGES_DOCUMENT_TYPE = CBZ -# Use the internal reader for images documents -# (FORMAT: BOOLEAN) -#IMAGES_DOCUMENT_USE_INTERNAL_READER = true -# The external viewer for images documents (or empty to use the system default program for the given file type) -# (FORMAT: STRING) -#IMAGES_DOCUMENT_READER = -# Use the internal reader for non-images documents -# (FORMAT: BOOLEAN) -#NON_IMAGES_DOCUMENT_USE_INTERNAL_READER = true -# The external viewer for non-images documents (or empty to use the system default program for the given file type) -# (FORMAT: STRING) -#NON_IMAGES_DOCUMENT_READER = -# The background colour of the library if you don't like the default system one -# (FORMAT: COLOR) -#BACKGROUND_COLOR = diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index a28dc8a..c0e8ec6 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -390,7 +390,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { .trans(StringIdGui.SUBTITLE_CONFIG)); JFrame frame = new JFrame(title); frame.add(ed); - frame.setSize(800, 600); + frame.setSize(850, 600); frame.setVisible(true); } }); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java index 209d38e..9615d75 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java @@ -20,7 +20,7 @@ public class GuiReaderPropertiesFrame extends JFrame { /** * Create a new {@link GuiReaderPropertiesFrame}. * - * @param ib + * @param lib * the library to use for the cover image * @param meta * the meta to describe -- 2.27.0