From d0d684a71b8e00d4d18f571dec0c32839871c32b Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Mon, 26 Jun 2023 18:23:09 +0800 Subject: [PATCH] =?UTF-8?q?HGIni=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2keyNam?= =?UTF-8?q?e=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build2/qt/HGBase/HGBase.def | 1 + modules/base/HGIni.cpp | 35 +++++++++++++++++++++++++++++++++++ modules/base/HGIni.h | 6 +++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/build2/qt/HGBase/HGBase.def b/build2/qt/HGBase/HGBase.def index d2d1de4b..c8ad0e4d 100644 --- a/build2/qt/HGBase/HGBase.def +++ b/build2/qt/HGBase/HGBase.def @@ -83,6 +83,7 @@ HGBase_SetProfileString HGBase_RemoveProfileSection HGBase_RenameProfileSection HGBase_RemoveProfileConfig +HGBase_SearchProfileConfig HGBase_GetProfileInt HGBase_GetProfileString diff --git a/modules/base/HGIni.cpp b/modules/base/HGIni.cpp index e33e1872..23206eb3 100644 --- a/modules/base/HGIni.cpp +++ b/modules/base/HGIni.cpp @@ -270,6 +270,41 @@ HGResult HGAPI HGBase_RemoveProfileConfig(const HGChar* fileName, const HGChar* return SaveIni(fileName, sectList); } +HGResult HGAPI HGBase_SearchProfileConfig(const HGChar* fileName, const HGChar* appName, const HGChar* keyName) +{ + if (NULL == fileName || NULL == appName || NULL == keyName) + { + return HGBASE_ERR_INVALIDARG; + } + + HGResult ret = HGBASE_ERR_FAIL; + + char sect[256]; + sprintf(sect, "[%s]", appName); + + SectionList sectList; + LoadIni(fileName, sectList); + + for (size_t i = 0; i < sectList.size(); ++i) + { + if (strcmp(sectList[i].first.c_str(), sect) == 0) + { + for (size_t j = 0; j < sectList[i].second.size(); ++j) + { + if (strcmp(sectList[i].second[j].first.c_str(), keyName) == 0) + { + ret = HGBASE_ERR_OK; + break; + } + } + + break; + } + } + + return ret; +} + static HGResult IniReadValue(const char* section, const char* key, char* val, unsigned int maxLen, const char* def, const char* file) { #if defined(HG_CMP_MSC) diff --git a/modules/base/HGIni.h b/modules/base/HGIni.h index 66ac98b2..488a062c 100644 --- a/modules/base/HGIni.h +++ b/modules/base/HGIni.h @@ -26,6 +26,10 @@ HGEXPORT HGResult HGAPI HGBase_RenameProfileSection(const HGChar* fileName, cons */ HGEXPORT HGResult HGAPI HGBase_RemoveProfileConfig(const HGChar* fileName, const HGChar* appName, const HGChar* keyName); +/* 查询ini文件的config +*/ +HGEXPORT HGResult HGAPI HGBase_SearchProfileConfig(const HGChar* fileName, const HGChar* appName, const HGChar* keyName); + /* 获取ini文件的值 */ HGEXPORT HGResult HGAPI HGBase_GetProfileInt(const HGChar* fileName, const HGChar* appName, @@ -36,4 +40,4 @@ HGEXPORT HGResult HGAPI HGBase_GetProfileInt(const HGChar* fileName, const HGCha HGEXPORT HGResult HGAPI HGBase_GetProfileString(const HGChar* fileName, const HGChar* appName, const HGChar* keyName, const HGChar* def, HGChar* value, HGUInt maxLen); -#endif /* __HGINI_H__ */ \ No newline at end of file +#endif /* __HGINI_H__ */