老版本浮点配置不能恢复,直接恢复为默认值并提醒用户

This commit is contained in:
gb 2022-09-27 12:35:37 +08:00
parent 32b61ba139
commit 5a5404e018
3 changed files with 40 additions and 11 deletions

View File

@ -1035,6 +1035,12 @@ namespace gb
jsn_->set_value(hex_t.c_str(), hex_v.c_str());
}
}
void sane_config::remove_config(const char* title)
{
std::string hex_t(to_hex_letter(title, lstrlenA(title)));
if (jsn_)
jsn_->remove(hex_t.c_str());
}
void sane_config::end_setting(bool cancel)
{
if (in_setting_)

View File

@ -110,6 +110,7 @@ namespace gb
void begin_setting(bool restore = false);
void config_changed(const char* title, const char* val, size_t bytes);
void config_changed(int sn, const char* val, size_t bytes);
void remove_config(const char* title);
void end_setting(bool cancel);
int id_from_title(const char* title);
std::string to_text_stream(void);

View File

@ -237,8 +237,10 @@ void scanner::save_config(const wchar_t* file)
void scanner::apply_config(void)
{
std::string t(""), v(""), ver(cfg_->get_version());
std::wstring notice(L"");
if (cfg_->first_config(t, v))
{
bool rewrite = false;
do
{
int id = cfg_->id_from_title(t.c_str());
@ -249,7 +251,8 @@ void scanner::apply_config(void)
const SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, id);
if (desc)
{
char* buf = NULL;
char* buf = NULL;
bool omit = false;
if (desc->type == SANE_TYPE_STRING)
{
buf = new char[desc->size + 4];
@ -259,26 +262,40 @@ void scanner::apply_config(void)
}
else if (ver.empty() && desc->type == SANE_TYPE_FIXED) // 升级早期版本没将float转为SANE_Fixed的BUG
{
fixed = SANE_FIX(*(float*)data);
cfg_->config_changed(t.c_str(), (char*)&fixed, sizeof(fixed));
data = &fixed;
cfg_->remove_config(t.c_str());
rewrite = true;
omit = true;
{
wchar_t msg[128] = { 0 };
unsigned char* f = (unsigned char*)&v[0], * to = (unsigned char*)data;
swprintf_s(msg, _countof(msg) - 1, L"Upgrage '%s' from '%02X%02X%02X%02X' to '%02X%02X%02X%02X'\r\n"
, local_trans::a2u(t.c_str(), CP_UTF8).c_str(), f[0], f[1], f[2], f[3]
, to[0], to[1], to[2], to[3]);
log_info(msg, 0);
std::wstring name(local_trans::a2u(t.c_str(), CP_UTF8));
unsigned char* f = (unsigned char*)&v[0];
notice += name + L"\r\n";
name.insert(0, L"Discard old configuration '");
swprintf_s(msg, _countof(msg) - 1, L"' of value '%02X%02X%02X%02X'\r\n", f[0], f[1], f[2], f[3]);
log_info((name + msg).c_str(), 0);
}
}
SANE_Int after = 0;
hg_sane_middleware::instance()->set_option(handle_, id, SANE_ACTION_SET_VALUE, data, &after);
if (!omit)
{
SANE_Int after = 0;
hg_sane_middleware::instance()->set_option(handle_, id, SANE_ACTION_SET_VALUE, data, &after);
}
if (buf)
delete[] buf;
}
}
} while (cfg_->next_config(t, v));
if (rewrite)
{
cfg_->save_to(NULL);
if (notice.length())
{
notice.insert(0, L"\u4E0B\u5217\u914D\u7F6E\u6570\u636E\u9519\u8BEF\uFF0C\u5DF2\u7ECF\u6062\u590D\u5230\u9ED8\u8BA4\u503C\u3002\u5982\u679C\u9700\u8981\uFF0C\u8BF7\u91CD\u65B0\u8BBE\u7F6E\uFF1A\r\n\r\n");
MessageBoxW(NULL, notice.c_str(), L"\u52A0\u8F7D\u914D\u7F6E", MB_OK | MB_ICONINFORMATION);
}
}
}
}
void scanner::on_ui_event(int uev, void* sender)
@ -2358,6 +2375,11 @@ void init_log(void)
path = std::string(name) + "_twain.log";
g_file_ = fopen(path.c_str(), "wb");
}
if (g_file_)
{
unsigned short bom = 0x0feff;
fwrite(&bom, sizeof(bom), 1, g_file_);
}
}
void close_log(void)
{