fix bug
This commit is contained in:
parent
dde8bc9a2a
commit
dc45ae8342
|
@ -169,15 +169,15 @@ known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void)
|
|||
else if (type == L"string")
|
||||
{
|
||||
int len = def_val.length();
|
||||
jsn->set_value(L"cur", def_val.c_str());
|
||||
jsn->set_value(L"default", def_val.c_str());
|
||||
jsn->set_value(L"cur", (const wchar_t*)def_val.c_str());
|
||||
jsn->set_value(L"default", (const wchar_t*)def_val.c_str());
|
||||
if (range.size())
|
||||
{
|
||||
known_file_util::IJsonW* rng = known_file_util::create_jsonW();
|
||||
rng->set_as_array(true);
|
||||
for (auto& v : range)
|
||||
{
|
||||
*rng += v.c_str();
|
||||
*rng += (const wchar_t*)v.c_str();
|
||||
if (len < v.length())
|
||||
len = v.length();
|
||||
}
|
||||
|
@ -261,25 +261,30 @@ bool CDlgOptJson::SANEOPT::from_json(known_file_util::IJsonW* jsn)
|
|||
bool v = false;
|
||||
std::wstring sv(L"");
|
||||
|
||||
jsn->get_value(L"default", v);
|
||||
if (!jsn->get_value(L"default", v))
|
||||
jsn->get_value(L"cur", v);
|
||||
sv = v ? L"true" : L"false";
|
||||
def_val = std::string((char*)&sv[0], sv.length() * 2 + 2);
|
||||
}
|
||||
else if(type == L"int")
|
||||
{
|
||||
int v = false;
|
||||
jsn->get_value(L"default", v);
|
||||
if (!jsn->get_value(L"default", v))
|
||||
jsn->get_value(L"cur", v);
|
||||
def_val = std::string((char*)&v, sizeof(v));
|
||||
}
|
||||
else if(type == L"float")
|
||||
{
|
||||
double v = false;
|
||||
jsn->get_value(L"default", v);
|
||||
if (!jsn->get_value(L"default", v))
|
||||
jsn->get_value(L"cur", v);
|
||||
def_val = std::string((char*)&v, sizeof(v));
|
||||
}
|
||||
else if(type == L"string")
|
||||
{
|
||||
jsn->get_value(L"default", &strv);
|
||||
strv = NULL;
|
||||
if (!jsn->get_value(L"default", &strv))
|
||||
jsn->get_value(L"cur", &strv);
|
||||
def_val = strv ? std::string((const char*)strv, lstrlenW(strv) * 2 + 2) : "";
|
||||
}
|
||||
|
||||
|
@ -694,8 +699,31 @@ bool CDlgOptJson::load_from_json_text(const wchar_t* txt, std::wstring* err_msg)
|
|||
int pos = 0;
|
||||
known_file_util::IJsonW* jsn = known_file_util::create_jsonW(txt, &pos), * child = NULL;
|
||||
|
||||
if (!jsn)
|
||||
while (!jsn)
|
||||
{
|
||||
// try code-text ...
|
||||
{
|
||||
std::wstring code(txt);
|
||||
size_t splash = code.find(L"\\\\");
|
||||
|
||||
while (splash != std::wstring::npos)
|
||||
{
|
||||
code.erase(splash++, 1);
|
||||
splash = code.find(L"\\\\", splash);
|
||||
}
|
||||
|
||||
splash = code.find(L"\\\"");
|
||||
while (splash != std::wstring::npos)
|
||||
{
|
||||
code.erase(splash++, 1);
|
||||
splash = code.find(L"\\\"", splash);
|
||||
}
|
||||
splash = 0;
|
||||
jsn = known_file_util::create_jsonW(&code[0], (int*)&splash);
|
||||
if (jsn)
|
||||
break;
|
||||
}
|
||||
|
||||
int ep = 10, len = 10;
|
||||
if (lstrlenW(txt + pos) < 10)
|
||||
len = lstrlenW(txt + pos);
|
||||
|
@ -1448,5 +1476,5 @@ void CDlgOptJson::OnBnClickedButtonExport()
|
|||
}
|
||||
|
||||
int n = file_util::set_clipboard(cont.c_str(), cont.length() * 2, CF_UNICODETEXT);
|
||||
MessageBox(TEXT("JSON text has set to clipboard already"));
|
||||
MessageBox(TEXT("JSON text has set to clipboard already"), std::to_wstring(cont.length()).c_str());
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue