打开帮助文档改为绝对路径

This commit is contained in:
yangjiaxuan 2023-08-02 14:48:42 +08:00
parent a974ab1c58
commit 4d9e451d0e
1 changed files with 79 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#include "hg_scanner.h" #include "hg_scanner.h"
#include "../wrapper/hg_log.h" #include "../wrapper/hg_log.h"
#include "sane/sane_option_definitions.h" #include "sane/sane_option_definitions.h"
#include "scanner_setting.h" #include "scanner_setting.h"
@ -1475,16 +1475,92 @@ int hg_scanner::setting_restore(void* data, long* len)
return SCANNER_ERR_CONFIGURATION_CHANGED; return SCANNER_ERR_CONFIGURATION_CHANGED;
} }
static int GetModuleName(void* addr, char* name, int maxLen)
{
if (NULL == name || 0 == maxLen)
{
return -1;
}
#if !defined(_WIN32)
if (NULL == addr)
{
char dir[PATH_MAX] = { 0 };
if (0 == readlink("/proc/self/exe", dir, PATH_MAX))
return -1;
if (maxLen < strlen(dir) + 1)
return -1;
strcpy(name, dir);
}
else
{
Dl_info dlinfo;
if (0 == dladdr(addr, &dlinfo))
return -1;
if (maxLen < strlen(dlinfo.dli_fname) + 1)
return -1;
strcpy(name, dlinfo.dli_fname);
}
#else
HMODULE hModule = NULL;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)addr, &hModule);
CHAR moduleName[MAX_PATH] = { 0 };
DWORD len = GetModuleFileNameA(hModule, moduleName, MAX_PATH);
if (0 == len || maxLen < strlen(moduleName) + 1)
return -1;
strcpy(name, moduleName);
#endif
return 0;
}
static int GetFilePath(const char* fileName, char* path, int maxLen)
{
if (NULL == fileName || NULL == path || 0 == maxLen)
{
return -1;
}
#if defined(_WIN32)
const char* pcName = strrchr(fileName, '\\');
if (NULL == pcName)
{
pcName = strrchr(fileName, '/');
if (NULL == pcName)
return -1;
}
#else
const char* pcName = strrchr(fileName, '/');
if (NULL == pcName)
return -1;
#endif
++pcName;
if (maxLen < (int)(pcName - fileName + 1))
return -1;
memcpy(path, fileName, pcName - fileName);
path[pcName - fileName] = 0;
return 0;
}
int hg_scanner::setting_help(void* data, long* len) int hg_scanner::setting_help(void* data, long* len)
{ {
std::string helpfile = HELP_PATH; char moduleName[256];
GetModuleName(NULL, moduleName, 256);
char exePath[256];
GetFilePath(moduleName, exePath, 256);
std:string exePath2 = exePath;
std::string helpfile = exePath2 + HELP_PATH;
std::string com = "xdg-open ";//注意空格保留 std::string com = "xdg-open ";//注意空格保留
int code_page = lang_get_cur_code_page(); int code_page = lang_get_cur_code_page();
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
if (code_page == 20127) if (code_page == 20127)
{ {
helpfile = HELP_PATH_EN; helpfile = exePath2 + HELP_PATH_EN;
} }
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)