cfg目录和log目录首先通过配置文件获取

This commit is contained in:
luoliangyi 2022-07-05 18:22:21 +08:00
parent e5d86f4878
commit 5b17ef350d
3 changed files with 57 additions and 2 deletions

View File

@ -164,6 +164,7 @@ SOURCES += \
../../../app/upgrade/HGUpgrade.cpp \
../../../app/upgrade/main.cpp \
../../../app/upgrade/mainwindow.cpp \
../../../modules/base/HGIni.cpp \
../../../modules/base/HGMd5.cpp \
../../../modules/base/HGUtility.cpp \
../../../modules/base/HGThread.cpp \
@ -172,6 +173,7 @@ SOURCES += \
HEADERS += \
../../../app/upgrade/HGUpgrade.h \
../../../app/upgrade/mainwindow.h \
../../../modules/base/HGIni.h \
../../../modules/base/HGMd5.h \
../../../modules/base/HGUtility.h \
../../../modules/base/HGThread.h \

View File

@ -19,11 +19,13 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\modules\base\HGIni.cpp" />
<ClCompile Include="..\..\..\modules\base\HGUtility.cpp" />
<ClCompile Include="..\..\..\sdk\upload\main.cpp" />
<ClCompile Include="..\..\..\third_party\cgic\cgic.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\modules\base\HGIni.h" />
<ClInclude Include="..\..\..\modules\base\HGUtility.h" />
<ClInclude Include="..\..\..\third_party\cgic\cgic.h" />
</ItemGroup>

View File

@ -1,5 +1,6 @@
#include "HGUtility.h"
#include "HGInc.h"
#include "HGIni.h"
#if defined(HG_CMP_MSC)
#include <shlobj.h>
#include <atlstr.h>
@ -180,8 +181,6 @@ HGResult HGAPI HGBase_GetModuleName(HGPointer addr, HGChar* name, HGUInt maxLen)
HMODULE hModule = NULL;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)addr, &hModule);
if (NULL == hModule)
return HGBASE_ERR_FAIL;
CHAR moduleName[MAX_PATH] = { 0 };
DWORD len = GetModuleFileNameA(hModule, moduleName, MAX_PATH);
@ -253,6 +252,32 @@ HGResult HGAPI HGBase_GetConfigPath(HGChar* configPath, HGUInt maxLen)
return HGBASE_ERR_INVALIDARG;
}
HGChar moduleName[56];
HGBase_GetModuleName(NULL, moduleName, 256);
HGChar modulePath[256];
HGBase_GetFilePath(moduleName, modulePath, 256);
strcat(modulePath, "first.cfg");
HGChar dataPath[256] = {0};
HGBase_GetProfileString(modulePath, "constraints", "local_data_path", "", dataPath, 256);
if ('\0' != *dataPath)
{
#if defined(HG_CMP_MSC)
if (dataPath[strlen(dataPath) - 1] != '\\')
strcat(dataPath, "\\");
strcat(dataPath, "Cfg\\");
#else
if (dataPath[strlen(dataPath) - 1] != '/')
strcat(dataPath, "/");
strcat(cfgPath, "Cfg/");
#endif
if (maxLen < strlen(dataPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(configPath, dataPath);
return HGBASE_ERR_OK;
}
#if defined(HG_CMP_MSC)
CHAR cfgPath[MAX_PATH] = { 0 };
BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE);
@ -291,6 +316,32 @@ HGResult HGAPI HGBase_GetLogFilePath(HGChar* logFilePath, HGUInt maxLen)
return HGBASE_ERR_INVALIDARG;
}
HGChar moduleName[56];
HGBase_GetModuleName(NULL, moduleName, 256);
HGChar modulePath[256];
HGBase_GetFilePath(moduleName, modulePath, 256);
strcat(modulePath, "first.cfg");
HGChar dataPath[256] = { 0 };
HGBase_GetProfileString(modulePath, "constraints", "local_data_path", "", dataPath, 256);
if ('\0' != *dataPath)
{
#if defined(HG_CMP_MSC)
if (dataPath[strlen(dataPath) - 1] != '\\')
strcat(dataPath, "\\");
strcat(dataPath, "Cfg\\");
#else
if (dataPath[strlen(dataPath) - 1] != '/')
strcat(dataPath, "/");
strcat(cfgPath, "Cfg/");
#endif
if (maxLen < strlen(dataPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(logFilePath, dataPath);
return HGBASE_ERR_OK;
}
#if defined(HG_CMP_MSC)
CHAR logPath[MAX_PATH] = { 0 };
BOOL ret = SHGetSpecialFolderPathA(NULL, logPath, CSIDL_APPDATA, FALSE);