From 18dd3c5871e56a0a21bc503957becb1321846e80 Mon Sep 17 00:00:00 2001 From: Chusslove Illich Date: Sat, 3 Oct 2009 16:18:21 +0000 Subject: [PATCH] Localized image states are now checked at runtime, ...so that fuzzy localized images are not used if present. This requires installing the l10n-track file as well. --- CMakeLists.txt | 3 +++ Makefile.am | 2 +- SConstruct | 1 + src/image.cpp | 31 ++++++++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57e6936cbb5..3ef808e67ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,6 +339,9 @@ if(ENABLE_SERVER AND FIFO_DIR) endif() endif() +# Index for checking states of localized images at runtime. +install(FILES l10n-track DESTINATION ${DATADIR}) + # # uninstall # diff --git a/Makefile.am b/Makefile.am index 273a0245e4b..4f236fb3d23 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ bin_SCRIPTS = findfilterflags=! \( -name .svn -prune -o -name ".\#*" -o -name "*~" -o -name "*bak" -o -name 'Makefile' -o -name '*Makefile' -o -type d -o -regex "data/test/*" \) # List all datafiles, ignoring junk -finddata=(cd $(top_srcdir) && find data fonts icons images sounds $(findfilterflags) -print ) +finddata=(cd $(top_srcdir) && find data fonts icons images sounds l10n-track $(findfilterflags) -print ) # List all data subdirectories finddatadirs=(cd $(top_srcdir) && find data fonts icons images sounds -type d \! \( -name .svn -prune \) -print ) # List non-installable utility files diff --git a/SConstruct b/SConstruct index 76844e3f68e..7d0851b4c6d 100755 --- a/SConstruct +++ b/SConstruct @@ -534,6 +534,7 @@ env.InstallData("datadir", "wesnoth", map(Dir, installable_subs)) env.InstallData("docdir", "wesnoth", [Glob("doc/manual/*.html"), Dir("doc/manual/styles"), Dir("doc/manual/images")]) if env["nls"]: env.InstallData("localedir", "wesnoth", Dir("translations")) + env.InstallData("datadir", "wesnoth", "l10n-track") InstallManpages(env, "wesnoth") if have_client_prereqs and have_X and env["desktop_entry"]: if sys.platform == "darwin": diff --git a/src/image.cpp b/src/image.cpp index c2d7311e26c..d125b464fd2 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -316,6 +316,35 @@ size_t hash_value(const locator::value& val) { return hash; } +// Check if localized file is uptodate according to l10n track index. +static std::set uptodate_localized_files; +static bool localized_file_uptodate (const std::string& loc_file) +{ + if (uptodate_localized_files.size() == 0) { + // First call, parse track index to collect uptodate files by path. + std::string fsep = "\xC2\xA6"; // UTF-8 for "broken bar" + std::string trackpath = get_binary_file_location("", "l10n-track"); + std::string contents = read_file(trackpath); + std::vector lines = utils::split(contents, '\n'); + foreach (const std::string &line, lines) { + size_t p1 = line.find(fsep); + if (p1 == std::string::npos) + continue; + std::string state = line.substr(0, p1); + utils::strip(state); + if (state == "ok") { + size_t p2 = line.find(fsep, p1 + fsep.length()); + if (p2 == std::string::npos) + continue; + std::string relpath = line.substr(p1 + fsep.length(), p2 - p1 - fsep.length()); + uptodate_localized_files.insert(game_config::path + '/' + relpath); + } + } + uptodate_localized_files.insert(""); // make sure not empty any more + } + return uptodate_localized_files.count(loc_file) == 1; +} + // Return path to localized counterpart of the given file, if any, or empty string. // Localized counterpart may also be requested to have a suffix to base name. static std::string get_localized_path (const std::string& file, const std::string& suff = "") @@ -346,7 +375,7 @@ static std::string get_localized_path (const std::string& file, const std::strin langs.push_back("en_US"); foreach (const std::string &lang, langs) { std::string loc_file = dir + "l10n" + "/" + lang + "/" + loc_base; - if (file_exists(loc_file)) { + if (file_exists(loc_file) && localized_file_uptodate(loc_file)) { return loc_file; } }