linux上实现从配置文件中获取cfg和log目录

This commit is contained in:
luoliangyi 2022-07-05 18:51:44 +08:00
parent 5b17ef350d
commit d4408d530f
4 changed files with 27 additions and 13 deletions

View File

@ -168,7 +168,7 @@ SOURCES += \
../../../modules/base/HGMd5.cpp \
../../../modules/base/HGUtility.cpp \
../../../modules/base/HGThread.cpp \
../../../utility/HGString.cpp
../../../utility/HGString.cpp \
HEADERS += \
../../../app/upgrade/HGUpgrade.h \
@ -177,7 +177,7 @@ HEADERS += \
../../../modules/base/HGMd5.h \
../../../modules/base/HGUtility.h \
../../../modules/base/HGThread.h \
../../../utility/HGString.h
../../../utility/HGString.h \
FORMS += \
../../../app/upgrade/mainwindow.ui

View File

@ -168,6 +168,8 @@
<Add option="-z defs" />
<Add option="-B direct" />
</Linker>
<Unit filename="../../../modules/base/HGIni.cpp" />
<Unit filename="../../../modules/base/HGIni.h" />
<Unit filename="../../../modules/base/HGUtility.cpp" />
<Unit filename="../../../modules/base/HGUtility.h" />
<Unit filename="../../../sdk/upload/main.cpp" />

View File

@ -171,12 +171,24 @@ HGResult HGAPI HGBase_GetModuleName(HGPointer addr, HGChar* name, HGUInt maxLen)
}
#if !defined(HG_CMP_MSC)
Dl_info dlinfo;
if (0 == dladdr(addr, &dlinfo))
return HGBASE_ERR_FAIL;
if (maxLen < strlen(dlinfo.dli_fname) + 1)
return HGBASE_ERR_FAIL;
strcpy(name, dlinfo.dli_fname);
if (NULL == addr)
{
char dir[PATH_MAX] = {0};
if (0 == readlink("/proc/self/exe", dir, PATH_MAX))
return HGBASE_ERR_FAIL;
if (maxLen < strlen(dir) + 1)
return HGBASE_ERR_FAIL;
strcpy(name, dir);
}
else
{
Dl_info dlinfo;
if (0 == dladdr(addr, &dlinfo))
return HGBASE_ERR_FAIL;
if (maxLen < strlen(dlinfo.dli_fname) + 1)
return HGBASE_ERR_FAIL;
strcpy(name, dlinfo.dli_fname);
}
#else
HMODULE hModule = NULL;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
@ -252,7 +264,7 @@ HGResult HGAPI HGBase_GetConfigPath(HGChar* configPath, HGUInt maxLen)
return HGBASE_ERR_INVALIDARG;
}
HGChar moduleName[56];
HGChar moduleName[256];
HGBase_GetModuleName(NULL, moduleName, 256);
HGChar modulePath[256];
HGBase_GetFilePath(moduleName, modulePath, 256);
@ -269,7 +281,7 @@ HGResult HGAPI HGBase_GetConfigPath(HGChar* configPath, HGUInt maxLen)
#else
if (dataPath[strlen(dataPath) - 1] != '/')
strcat(dataPath, "/");
strcat(cfgPath, "Cfg/");
strcat(dataPath, "Cfg/");
#endif
if (maxLen < strlen(dataPath) + 1)
@ -316,7 +328,7 @@ HGResult HGAPI HGBase_GetLogFilePath(HGChar* logFilePath, HGUInt maxLen)
return HGBASE_ERR_INVALIDARG;
}
HGChar moduleName[56];
HGChar moduleName[256];
HGBase_GetModuleName(NULL, moduleName, 256);
HGChar modulePath[256];
HGBase_GetFilePath(moduleName, modulePath, 256);
@ -333,7 +345,7 @@ HGResult HGAPI HGBase_GetLogFilePath(HGChar* logFilePath, HGUInt maxLen)
#else
if (dataPath[strlen(dataPath) - 1] != '/')
strcat(dataPath, "/");
strcat(cfgPath, "Cfg/");
strcat(dataPath, "Cfg/");
#endif
if (maxLen < strlen(dataPath) + 1)

View File

@ -108,4 +108,4 @@ int cgiMain()
//打印输出
fprintf(cgiOut, "<p> upload file success. </p>\n");
return cgiFormSuccess;
}
}