load user specified language; set debug.cfg as default config file, move initializing language to driver component
This commit is contained in:
parent
cdb0c19298
commit
6c1bd8a84c
|
@ -110,6 +110,15 @@ extern "C"
|
|||
utils::to_log(LOG_LEVEL_FATAL, "No language package found!\n");
|
||||
return SCANNER_ERR_LANG_PAK_LOST;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string lang(utils::get_ini_value("language", "code-page", nullptr));
|
||||
if(!lang.empty())
|
||||
{
|
||||
lang_set_code_page(atoi(lang.c_str()));
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "Found the language specified by user: %s, code-page after set = %d\n", lang.c_str(), lang_get_cur_code_page());
|
||||
}
|
||||
}
|
||||
register_language_changed_notify(language_changed, true);
|
||||
|
||||
hg_scanner_mgr::set_version(VERSION_MAJOR, VERSION_MINOR, VERSION_YEAR, GET_BUILD_VER);
|
||||
|
|
|
@ -540,11 +540,6 @@ const SANE_Device** hg_sane_middleware::dev_list_ = NULL;
|
|||
|
||||
hg_sane_middleware::hg_sane_middleware(void) : opt_0_(nullptr), init_ok_(false)
|
||||
{
|
||||
if (lang_initialize() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char sane_ver[40] = { 0 };
|
||||
|
||||
init_ok_ = true;
|
||||
|
|
|
@ -68,16 +68,33 @@ int gettimeofday(TIMEV* tv, struct timezone* tz)
|
|||
|
||||
static std::mutex ini_lock_;
|
||||
static std::map<std::string, simple_ini*> ini_files_;
|
||||
static std::string debug_cfg_file_ = "";
|
||||
|
||||
static void init_default_config_file_path(void)
|
||||
{
|
||||
if(debug_cfg_file_.empty())
|
||||
{
|
||||
debug_cfg_file_ = utils::get_local_data_path() + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg";
|
||||
}
|
||||
}
|
||||
static simple_ini* get_ini_object(const char* file)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ini_lock_);
|
||||
|
||||
if (ini_files_.count(file) == 0)
|
||||
if(!file || file[0] == 0)
|
||||
{
|
||||
simple_ini* ini = new simple_ini();
|
||||
ini->load(file);
|
||||
init_default_config_file_path();
|
||||
file = debug_cfg_file_.c_str();
|
||||
}
|
||||
|
||||
ini_files_[file] = ini;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ini_lock_);
|
||||
|
||||
if (ini_files_.count(file) == 0)
|
||||
{
|
||||
simple_ini* ini = new simple_ini();
|
||||
ini->load(file);
|
||||
|
||||
ini_files_[file] = ini;
|
||||
}
|
||||
}
|
||||
|
||||
return ini_files_[file];
|
||||
|
@ -472,7 +489,7 @@ namespace utils
|
|||
}
|
||||
#else
|
||||
// This function will return 'in' string if failed !
|
||||
static std::string transform_between_gbk_and_utf8(const char* in, bool to_utf8, int *err)
|
||||
static std::string transform_between_gbk_and_utf8(const char* in, bool to_utf8, int *err, const char* ansi = "GBK")
|
||||
{
|
||||
size_t len = strlen(in) + 8, ol = len * 2;
|
||||
char *buf = (char*)malloc(len), *oper = buf, *out = nullptr, *oper1 = nullptr;
|
||||
|
@ -481,9 +498,9 @@ namespace utils
|
|||
memset(buf, 0, len);
|
||||
strcpy(buf, in);
|
||||
if(to_utf8)
|
||||
conv = iconv_open("UTF-8", "GBK");
|
||||
conv = iconv_open("UTF-8", ansi);
|
||||
else
|
||||
conv = iconv_open("GBK", "UTF-8");
|
||||
conv = iconv_open(ansi, "UTF-8");
|
||||
if(conv == (iconv_t)-1)
|
||||
{
|
||||
if(err)
|
||||
|
@ -687,6 +704,7 @@ namespace utils
|
|||
std::string get_ini_value(const char* seg, const char* key, const char* cfg_file)
|
||||
{
|
||||
char buf[512] = { 0 };
|
||||
PRODUCT_VENDOR
|
||||
|
||||
GetPrivateProfileStringA(seg, key, "", buf, sizeof(buf) - 1, cfg_file);
|
||||
|
||||
|
@ -696,6 +714,7 @@ namespace utils
|
|||
{
|
||||
std::string cont("");
|
||||
FILE* src = fopen(file, "rb");
|
||||
int en = 0;
|
||||
|
||||
if (src)
|
||||
{
|
||||
|
@ -706,8 +725,7 @@ namespace utils
|
|||
fseek(src, 0, SEEK_SET);
|
||||
if (len > SIZE_MB(1))
|
||||
{
|
||||
if (err)
|
||||
*err = E2BIG;
|
||||
en = E2BIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -716,17 +734,19 @@ namespace utils
|
|||
{
|
||||
len = fread(buf, 1, len, src);
|
||||
cont = std::string(buf, len);
|
||||
if (err)
|
||||
*err = 0;
|
||||
en = 0;
|
||||
delete[] buf;
|
||||
}
|
||||
else if (err)
|
||||
*err = ENOMEM;
|
||||
else
|
||||
en = ENOMEM;
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
else if (err)
|
||||
*err = errno;
|
||||
else
|
||||
en = errno;
|
||||
|
||||
if(err)
|
||||
*err = en;
|
||||
|
||||
return std::move(cont);
|
||||
}
|
||||
|
@ -1170,3 +1190,4 @@ void chronograph::reset()
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue