📄 myinifile.cpp
字号:
{
if(!strRuleSectionList.IsEmpty())
{
strRuleSectionList+=",";
}
strRuleSectionList+=RuleSectionList[l].c_str();
}
INI_META_DATA* pIniMetaData=IniMetaDataMgr.GetMetaDataByName(RuleSectionList[0].c_str());
WritePrivateProfileString(
"RuleList",
"IniList",
pIniMetaData->IniFormat.strIniFile.c_str(),
pszMetaDataFilePath
);
WritePrivateProfileString(
"RuleList",
pIniMetaData->IniFormat.strIniFile.c_str(),
strRuleSectionList,
pszMetaDataFilePath
);
for(l=0;l<RuleSectionList.size();l++)
{
pIniMetaData=IniMetaDataMgr.GetMetaDataByName(RuleSectionList[l].c_str());
ASSERT(pIniMetaData);
SaveIniMetaDataSection(pszMetaDataFilePath,RuleSectionList[l].c_str(),pIniMetaData);
}
return TRUE;
}
BOOL CMyIniFile::SaveIniMetaDataSection(
const char * pszMetaDataFilePath,
const char* strSect,
INI_META_DATA* pIniMetaData
)
{
//strIniFile
WritePrivateProfileString(
strSect,
"IniFile",
pIniMetaData->IniFormat.strIniFile.c_str(),
pszMetaDataFilePath
);
char szTxt[1024]={0,};
///
//SectionNamingRule
if(!pIniMetaData->IniCheckRule.strSectionNamingRule.empty())
{
WritePrivateProfileString(
strSect,
"SectionNamingRule",
pIniMetaData->IniCheckRule.strSectionNamingRule.c_str(),
pszMetaDataFilePath
);
}
//HasCPlusPlusStyleComment
//
//////////////////////////////////IniCheckRule
//strFileRedirectToSubFolder
if(!pIniMetaData->IniCheckRule.strFileRedirectToSubFolder.empty())
{
WritePrivateProfileString(
strSect,
"FileRedirectToSubFolder",
pIniMetaData->IniCheckRule.strFileRedirectToSubFolder.c_str(),
pszMetaDataFilePath
);
}
//bApplyToSectionByNamingRule
sprintf(szTxt,"%d",pIniMetaData->IniCheckRule.bApplyToSectionByNamingRule);
WritePrivateProfileString(
strSect,
"ApplyToSectionByNamingRule",
szTxt,
pszMetaDataFilePath
);
//RestrictKeySequence
sprintf(szTxt,"%d",pIniMetaData->IniCheckRule.bRestrictKeySequence);
WritePrivateProfileString(
strSect,
"RestrictKeySequence",
szTxt,
pszMetaDataFilePath
);
//ApplyToSectionList
WritePrivateProfileString(
strSect,
"ApplyToSectionList",
pIniMetaData->IniCheckRule.strApplyToSectionList.c_str(),
pszMetaDataFilePath
);
//AutoCheckBegin
WritePrivateProfileString(
strSect,
"AutoCheckBegin",
pIniMetaData->IniCheckRule.strAutoCheckBegin.c_str(),
pszMetaDataFilePath
);
//// write all key pair first
for(STRING_LIST::iterator itr=pIniMetaData->IniCheckRule.Keys.begin();
itr!=pIniMetaData->IniCheckRule.Keys.end();itr++)
{
STD_MAP_STRING_2_STRING::iterator itrMapKeysToRule=pIniMetaData->IniCheckRule.MapKeysToRule.find(*itr);
if(pIniMetaData->IniCheckRule.MapKeysToRule.end()==itrMapKeysToRule)
{
WritePrivateProfileString(
strSect,
(*itr).c_str(),
"",
pszMetaDataFilePath
);
}
else
{
WritePrivateProfileString(
strSect,
(*itr).c_str(),
(*itrMapKeysToRule).second.c_str(),
pszMetaDataFilePath
);
}
}
return TRUE;
}
BOOL CMyIniFile::LoadIniMetaData(
const char * pszMetaDataFilePath,
INI_META_DATA_MGR* pIniMetaDataMgr,
IBasicMsgUI* pIBasicMsgUI
)
{
char szTxt[1024]={0,};
GetPrivateProfileString(
"RuleList",
"IniList",
"",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
CString strIniList=szTxt;
strIniList.TrimLeft();
strIniList.TrimRight();
if(strIniList.IsEmpty())
{
return FALSE;
}
strIniList.MakeLower();
STRING_LIST IniList;
ParseString((const char*)strIniList,",",IniList);
for(STRING_LIST::iterator itrIniList=IniList.begin();itrIniList!=IniList.end();itrIniList++)
{
CString strIniFile=(*itrIniList).c_str();
char szIniRuleList[1024]={0,};
GetPrivateProfileString(
"RuleList",
strIniFile,
"",
szIniRuleList,
sizeof(szIniRuleList),
pszMetaDataFilePath
);
strlwr(szIniRuleList);
STRING_LIST RuleList;
ParseString(szIniRuleList,",",RuleList);
if(RuleList.size()<1)
{
ASSERT(false);
continue;
}
if(pIniMetaDataMgr->IniFileList.end()==std::find(pIniMetaDataMgr->IniFileList.begin(),pIniMetaDataMgr->IniFileList.end(),(const char*)strIniFile))
{
pIniMetaDataMgr->IniFileList.push_back((const char*)strIniFile);
}
for(long l=0;l<RuleList.size();l++)
{
CString strRuleSection=RuleList[l].c_str();
if(LoadIniMetaDataSection(pszMetaDataFilePath,strRuleSection,pIniMetaDataMgr,pIBasicMsgUI))
{
}
else
{
ASSERT(false);
};
}
pIniMetaDataMgr->MapIniFile2MetaDataNameList[(const char*)strIniFile]=szIniRuleList;
}
return TRUE;
}
BOOL CMyIniFile::LoadIniMetaDataSection(
const char * pszMetaDataFilePath,
const char* strSect,
INI_META_DATA_MGR* pIniMetaDataMgr,
IBasicMsgUI* pIBasicMsgUI
)
{
TraceOut("LoadIniMetaDataSection(strSect:%s %s )",strSect,pszMetaDataFilePath);
CString strTxt;
char szTxt[1024]={0,};
CString strSectLower=strSect;
strSectLower.MakeLower();
////section name is Setting Name
MAP_NAME_2_INI_META_DATA::iterator itrName2IniMetaData=pIniMetaDataMgr->MapName2IniMetaData.find((const char*)strSectLower);
INI_META_DATA* pIniMetaData=0;
if(pIniMetaDataMgr->MapName2IniMetaData.end()!=itrName2IniMetaData)
{
pIniMetaData=(*itrName2IniMetaData).second;
}
else
{
pIniMetaData=new INI_META_DATA;
}
CAutoDelete<INI_META_DATA> IniMetaDataAutoDelete(pIniMetaData);
if(pIniMetaDataMgr->MapName2IniMetaData.end()!=itrName2IniMetaData)
{
//如果是重新加载,不删除
IniMetaDataAutoDelete.ClearPtr();
}
pIniMetaData->IniCheckRule.strName=(const char*)strSectLower;
pIniMetaData->strMetaDataFilePath=pszMetaDataFilePath;
//////////////////////////////////get ini format
//strIniFile
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"IniFile",
"",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
strTxt.MakeLower();
pIniMetaData->IniFormat.strIniFile=strTxt;
//
//////////////////////////////////IniCheckRule
//strFileRedirectToSubFolder
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"FileRedirectToSubFolder",
"",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
strTxt.MakeLower();
pIniMetaData->IniCheckRule.strFileRedirectToSubFolder=(const char*)strTxt;
//RestrictKeySequence
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"RestrictKeySequence",
"0",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
pIniMetaData->IniCheckRule.bRestrictKeySequence=(atol(szTxt)==1);
//bApplyToSectionByNamingRule
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"ApplyToSectionByNamingRule",
"0",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
pIniMetaData->IniCheckRule.bApplyToSectionByNamingRule=(atol(szTxt)==1);
//SectionNamingRule
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"SectionNamingRule",
"",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
pIniMetaData->IniCheckRule.strSectionNamingRule=strTxt;
//ApplyToSectionList
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"ApplyToSectionList",
"",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
pIniMetaData->IniCheckRule.SetApplyToSectionList(strTxt);
//AutoCheckBegin
szTxt[0]=0;
GetPrivateProfileString(
strSect,
"AutoCheckBegin",
"1",
szTxt,
sizeof(szTxt),
pszMetaDataFilePath
);
strTxt=szTxt;
strTxt.TrimLeft();strTxt.TrimRight();
char szSectionCfg[512*1024]={0,};
GetPrivateProfileSection(
strSect,
szSectionCfg,
sizeof(szSectionCfg),
pszMetaDataFilePath
);
STRING_LIST StrList;
MultiSZToStringList(szSectionCfg,StrList);
if(strTxt.IsEmpty())
{
pIniMetaData->IniCheckRule.strAutoCheckBegin=="";
}
else
{
pIniMetaData->IniCheckRule.strAutoCheckBegin=(const char*)strTxt;
}
for(long k=0;k<StrList.size();k++)
{
CString strKeyInfo=StrList[k].c_str();
long lPos=strKeyInfo.Find("=");
if(lPos<0)
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
" no AutoCheck field.strSect:%s MetaDataFilePath;%s",strSect,pszMetaDataFilePath
).c_str());
ASSERT(false);
return FALSE;
}
CString strKey=strKeyInfo.Left(lPos);
strKey.TrimLeft();strKey.TrimRight();
if(strKey.IsEmpty())
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
"AutoCheck field key is empty.strSect:%s MetaDataFilePath;%s",strSect,pszMetaDataFilePath
).c_str());
ASSERT(false);
return FALSE;
}
CString strRule=strKeyInfo.Mid(lPos+1);
strRule.TrimLeft();strRule.TrimRight();
if(pIniMetaData->IniCheckRule.Keys.end()==std::find(pIniMetaData->IniCheckRule.Keys.begin(),pIniMetaData->IniCheckRule.Keys.end(),(const char*)strKey))
{
pIniMetaData->IniCheckRule.Keys.push_back((const char*)strKey);
}
pIniMetaData->IniCheckRule.MapKeysToRule[(const char*)strKey]=(const char*)strRule;
}
STRING_LIST::iterator itrAutoCheckKey;
if(pIniMetaData->IniCheckRule.strAutoCheckBegin.empty())
{
itrAutoCheckKey=std::find(pIniMetaData->IniCheckRule.Keys.begin(),
pIniMetaData->IniCheckRule.Keys.end(),
"AutoCheckBegin"
);
if(pIniMetaData->IniCheckRule.Keys.end()==itrAutoCheckKey)
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
"AutoCheckBegin key not found.strSect:%s MetaDataFilePath;%s",strSect,pszMetaDataFilePath
).c_str());
ASSERT(false);
return FALSE;
};
++itrAutoCheckKey;
if(pIniMetaData->IniCheckRule.Keys.end()==itrAutoCheckKey)
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
"AutoCheckBegin 之后没有KEY.Title:%s MetaDataFilePath;%s",strSect,pszMetaDataFilePath
).c_str());
ASSERT(false);
return FALSE;
};
pIniMetaData->IniCheckRule.strAutoCheckBegin=*itrAutoCheckKey;
}
else
{
itrAutoCheckKey=std::find(pIniMetaData->IniCheckRule.Keys.begin(),
pIniMetaData->IniCheckRule.Keys.end(),
pIniMetaData->IniCheckRule.strAutoCheckBegin
);
if(pIniMetaData->IniCheckRule.Keys.end()==itrAutoCheckKey)
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
"AutoCheckBegin key %s not found.strSect:%s MetaDataFilePath;%s",strSect,pszMetaDataFilePath,
pIniMetaData->IniCheckRule.strAutoCheckBegin.c_str()
).c_str());
ASSERT(false);
return FALSE;
};
}
pIniMetaDataMgr->MapName2IniMetaData[pIniMetaData->IniCheckRule.strName]=(INI_META_DATA*)pIniMetaData;
if(pIniMetaDataMgr->IniMetaDataNameList.end()==std::find(pIniMetaDataMgr->IniMetaDataNameList.begin(),pIniMetaDataMgr->IniMetaDataNameList.end(),pIniMetaData->IniCheckRule.strName))
{
pIniMetaDataMgr->IniMetaDataNameList.push_back(pIniMetaData->IniCheckRule.strName);
}
IniMetaDataAutoDelete.ClearPtr();
return TRUE;
}
const char* CMyIniFile::GetFilePath()
{
return m_strFilePath;
}
BOOL CMyIniFile::GetSectionList(STRING_LIST &StrList)
{
char szSectionnames[256*1024]={0,};
GetPrivateProfileSectionNames(
szSectionnames,
sizeof(szSectionnames),
GetFilePath()
);
MultiSZToStringList(szSectionnames,StrList);
return TRUE;
}
INI_SECTION* CMyIniFile::GetSection(const char *pszSection)
{
MAP_NAME_TO_INI_SECTION::iterator itr=m_MapNameToIniSection.find(pszSection);
if(m_MapNameToIniSection.end()==itr)
{
return FALSE;
}
return (*itr).second;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -