diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/i18n.cpp | 43 | ||||
-rw-r--r-- | src/common/stack_trace.cpp | 3 | ||||
-rw-r--r-- | src/common/threadpool.cpp | 8 |
3 files changed, 40 insertions, 14 deletions
diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp index 4a76e76fc..28a186bf0 100644 --- a/src/common/i18n.cpp +++ b/src/common/i18n.cpp @@ -35,6 +35,7 @@ #include "file_io_utils.h" #include "common/util.h" #include "common/i18n.h" +#include "translation_files.h" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "i18n" @@ -62,6 +63,7 @@ std::string i18n_get_language() e = "en"; std::string language = e; + language = language.substr(0, language.find(".")); std::transform(language.begin(), language.end(), language.begin(), tolower); return language; } @@ -137,25 +139,40 @@ int i18n_set_language(const char *directory, const char *base, std::string langu i18n_log("Loading translations for language " << language); boost::system::error_code ignored_ec; - if (!boost::filesystem::exists(filename, ignored_ec)) { + if (boost::filesystem::exists(filename, ignored_ec)) { + if (!epee::file_io_utils::load_file_to_string(filename, contents)) { + i18n_log("Failed to load translations file: " << filename); + return -1; + } + } else { i18n_log("Translations file not found: " << filename); - const char *underscore = strchr(language.c_str(), '_'); - if (underscore) { - std::string fallback_language = std::string(language, 0, underscore - language.c_str()); - filename = std::string(directory) + "/" + base + "_" + fallback_language + ".qm"; - i18n_log("Not found, loading translations for language " << fallback_language); - if (!boost::filesystem::exists(filename, ignored_ec)) { - i18n_log("Translations file not found: " << filename); + filename = std::string(base) + "_" + language + ".qm"; + if (!find_embedded_file(filename, contents)) { + i18n_log("Embedded translations file not found: " << filename); + const char *underscore = strchr(language.c_str(), '_'); + if (underscore) { + std::string fallback_language = std::string(language, 0, underscore - language.c_str()); + filename = std::string(directory) + "/" + base + "_" + fallback_language + ".qm"; + i18n_log("Loading translations for language " << fallback_language); + if (boost::filesystem::exists(filename, ignored_ec)) { + if (!epee::file_io_utils::load_file_to_string(filename, contents)) { + i18n_log("Failed to load translations file: " << filename); + return -1; + } + } else { + i18n_log("Translations file not found: " << filename); + filename = std::string(base) + "_" + fallback_language + ".qm"; + if (!find_embedded_file(filename, contents)) { + i18n_log("Embedded translations file not found: " << filename); + return -1; + } + } + } else { return -1; } } } - if (!epee::file_io_utils::load_file_to_string(filename, contents)) { - i18n_log("Failed to load translations file: " << filename); - return -1; - } - data = (const unsigned char*)contents.c_str(); datalen = contents.size(); idx = 0; diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp index bcdf72b60..ed1093309 100644 --- a/src/common/stack_trace.cpp +++ b/src/common/stack_trace.cpp @@ -28,7 +28,10 @@ #if !defined __GNUC__ || defined __MINGW32__ || defined __MINGW64__ || defined __ANDROID__ #define USE_UNWIND +#else +#define ELPP_FEATURE_CRASH_LOG 1 #endif +#include "easylogging++/easylogging++.h" #include <stdexcept> #ifdef USE_UNWIND diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp index 20c5765b0..5d749e08e 100644 --- a/src/common/threadpool.cpp +++ b/src/common/threadpool.cpp @@ -34,6 +34,8 @@ #include "cryptonote_config.h" #include "common/util.h" +static __thread int depth = 0; + namespace tools { threadpool::threadpool() : running(true), active(0) { @@ -60,11 +62,13 @@ threadpool::~threadpool() { void threadpool::submit(waiter *obj, std::function<void()> f) { entry e = {obj, f}; boost::unique_lock<boost::mutex> lock(mutex); - if (active == max && !queue.empty()) { + if ((active == max && !queue.empty()) || depth > 0) { // if all available threads are already running // and there's work waiting, just run in current thread lock.unlock(); + ++depth; f(); + --depth; } else { if (obj) obj->inc(); @@ -106,7 +110,9 @@ void threadpool::run() { e = queue.front(); queue.pop_front(); lock.unlock(); + ++depth; e.f(); + --depth; if (e.wo) e.wo->dec(); |