From 9d6a7e5027e0b35fc58443cb42d2f8c766af60ca Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Mon, 27 Mar 2023 12:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BB=9F=E4=B8=80=E5=88=B0debug.cfg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twain/twain/huagaods.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index 31ab725..2e1809e 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -3270,27 +3270,47 @@ void huagao_ds::init_support_caps_ex(void) } std::wstring huagao_ds::get_config_file(void) { - wchar_t path[MAX_PATH] = { 0 }, * name = NULL; + char* tmp = getenv("LOCALAPPDATA"); + if (tmp) + { + std::wstring str(L""); + std::string path(tmp); - GetModuleFileNameW(me_, path, _countof(path) - 1); - name = wcsrchr(path, L'\\'); - if (name++ == NULL) - name = path; - wcscpy_s(name, _countof(path) - 1 - (name - path), L"first.cfg"); + path += std::string("\\") + PRODUCT_VENDOR + "Scan\\config\\debug.cfg"; - return path; + return std::move(load_sane_util::ansi2unic(path.c_str())); + } + else + { + wchar_t path[MAX_PATH] = { 0 }, * name = NULL; + + GetModuleFileNameW(me_, path, _countof(path) - 1); + name = wcsrchr(path, L'\\'); + if (name++ == NULL) + name = path; + wcscpy_s(name, _countof(path) - 1 - (name - path), L"debug.cfg"); + + return path; + } } std::wstring huagao_ds::get_config_value(const wchar_t* sec, const wchar_t* key) { wchar_t v[256] = { 0 }; + std::wstring cfg_f(get_config_file()); - GetPrivateProfileStringW(sec, key, L"", v, _countof(v) - 1, get_config_file().c_str()); + if(!cfg_f.empty()) + GetPrivateProfileStringW(sec, key, L"", v, _countof(v) - 1, get_config_file().c_str()); return v; } DWORD huagao_ds::get_config_number(const wchar_t* sec, const wchar_t* key) { - return GetPrivateProfileIntW(sec, key, 0, get_config_file().c_str()); + std::wstring cfg_f(get_config_file()); + + if (cfg_f.empty()) + return 0; + else + return GetPrivateProfileIntW(sec, key, 0, get_config_file().c_str()); } int huagao_ds::handle_scanner_event(int ev) {