📄 myinifile.cpp
字号:
ParseString(strSubStringValueNoCheck.c_str(),",",FixValueList);
if(FixValueList.end()==std::find(FixValueList.begin(),FixValueList.end(),(const char*)strVal))
{
return TRUE;
}
}
BOOL bValueMaxLength=(strRule.Find("ValueMaxLength")>=0);
if(bValueMaxLength)
{
std::string strSubStringValueMaxLength;
GetSubString(
strRule,
"ValueMaxLength(",
")",
strSubStringValueMaxLength
);
long lMaxLength=atol(strSubStringValueMaxLength.c_str());
if(strVal.GetLength()>lMaxLength)
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值字符串 %s 长度为 %s 大于最大值 %d",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,(const char*)strKeyFull,
(const char*)strVal,strVal.GetLength(),lMaxLength
).c_str());
return FALSE;
}
}
BOOL bValueIsOneOfFixedValue=(strRule.Find("ValueIsOneOfFixedValue")>=0);
if(bValueIsOneOfFixedValue)
{
std::string strSubStringValueIsOneOfFixedValue;
GetSubString(
strRule,
"ValueIsOneOfFixedValue(",
")",
strSubStringValueIsOneOfFixedValue
);
STRING_LIST FixValueList;
ParseString(strSubStringValueIsOneOfFixedValue.c_str(),",",FixValueList);
if(FixValueList.end()==std::find(FixValueList.begin(),FixValueList.end(),(const char*)strVal))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值字符串 %s 不在固定值列表中:%s",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,(const char*)strKeyFull,(const char*)strVal,
strSubStringValueIsOneOfFixedValue.c_str()
).c_str());
return FALSE;
}
}
if(bValueIsInteger)
{
if(!IsNumber(strVal))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值 %s 不是整数",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,(const char*)strVal
).c_str());
return FALSE;
}
std::string strSubStringINT_VALUE_MAX;
GetSubString(
strRule,
"INT_VALUE_MAX(",
")",
strSubStringINT_VALUE_MAX
);
if(!strSubStringINT_VALUE_MAX.empty())
{
long lIntMax=atol(strSubStringINT_VALUE_MAX.c_str());
if(atol(strVal)>=lIntMax)
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值为 %s 大于最大值 %d",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,(const char*)strVal,lIntMax
).c_str());
return FALSE;
}
}
std::string strSubStringINT_VALUE_MIN;
GetSubString(
strRule,
"INT_VALUE_MIN(",
")",
strSubStringINT_VALUE_MIN
);
if(!strSubStringINT_VALUE_MIN.empty())
{
long lIntMin=atol(strSubStringINT_VALUE_MIN.c_str());
if(atol(strVal)>=lIntMin)
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值为 %s 小于最小值 %d",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,(const char*)strVal,lIntMin
).c_str());
return FALSE;
}
}
}
////
CString strRefIni;
long lPos=0;
BOOL bValueIsFile=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"ValueIsFile"));
BOOL bValueFirstPartIsFile=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"ValueFirstPartIsFile"));
BOOL bValueIsIniSectionName=(0!=strstr(strRule,"ValueIsIniSectionName("));
BOOL bValueFirstPartIsIniSectionName=(0!=strstr(strRule,"ValueFirstPartIsIniSectionName("));
BOOL bValueIsIniKeyName=(0!=strstr(strRule,"ValueIsIniKeyName("));
if(bValueIsFile)
{
//检查文件存在性
CString strFile=(*itrValue).second.c_str();
CString strFileFull=GET_FULLPATH_EX(strFile);
if( (_access( strFileFull , 0 )) != -1 )
{
//existes
}
else
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 指向的文件 %s 不存在",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,strFile
).c_str());
return FALSE;
};
}
if(bValueFirstPartIsFile)
{
//检查文件存在性
CString strFile=(*itrValue).second.c_str();
lPos=strFile.Find(" ");
if(lPos>=0)
{
strFile=strFile.Left(lPos);
}
CString strFileFull=GET_FULLPATH_EX(strFile);
if( (_access( strFileFull , 0 )) != -1 )
{
//existes
}
else
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 值 指向的文件 %s 不存在空",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,strFile
).c_str());
return FALSE;
};
}
if(bValueFirstPartIsIniSectionName)
{
std::string strSubStringRefIni;
GetSubString(
strRule,
"ValueFirstPartIsIniSectionName(",
")",
strSubStringRefIni
);
strRefIni=strSubStringRefIni.c_str();
strRefIni.TrimLeft();strRefIni.TrimRight();
if(strRefIni.IsEmpty())
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 引用的Ini 为空",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull
).c_str());
return FALSE;
}
CString strSectionNameBeginWith="";
lPos=strRule.Find("SectionNameFirstPartBeginWith(");
if(lPos>=0)
{
strSectionNameBeginWith=strRule.Mid(lPos+strlen("SectionNameFirstPartBeginWith("));
lPos=strSectionNameBeginWith.Find(")");
if(lPos>=0)
{
strSectionNameBeginWith=strSectionNameBeginWith.Left(lPos);
}
strSectionNameBeginWith.TrimLeft();strSectionNameBeginWith.TrimRight();
}
BOOL bIsSectionNameAmountKey=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"SectionNameFirstPartIsAmountKey"));
if(bIsSectionNameAmountKey)
{
DWORD dwAmount=atol(strVal);
for(long l=0;l<dwAmount;l++)
{
CString strTitle;
strTitle.Format("%u",(const char*)strSectionNameBeginWith,l);
//if(!CMyIniFile::IsSectionExistesEx(GET_FULLPATH(strRefIni),strTitle))
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
if(!pRefIni->IsSectionExistes(strTitle))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s AMOUNTKEY 引用的 %s 的TITLE %s 不存在",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,
(const char*)strRefIni,
(const char*)strTitle
).c_str());
return FALSE;
};
}
}
else
{
//if(!CMyIniFile::IsSectionExistesEx(GET_FULLPATH(strRefIni),strSectionNameBeginWith+strVal))
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
CString strRefTitle=strVal;
long lPosTemp=strRefTitle.Find(" ");
if(lPosTemp<0)
{
lPosTemp=strRefTitle.Find("\t");
}
if(lPosTemp>=0)
{
strRefTitle=strRefTitle.Left(lPosTemp);
}
if(!pRefIni->IsSectionExistes(strSectionNameBeginWith+strRefTitle))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 引用的 %s 的TITLE %s 不存在",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,
(const char*)strRefIni,
(const char*)(strSectionNameBeginWith+strRefTitle)
).c_str());
return FALSE;
};
}
}
if(bValueIsIniSectionName)
{
std::string strSubStringRefIni;
GetSubString(
strRule,
"ValueIsIniSectionName(",
")",
strSubStringRefIni
);
strRefIni=strSubStringRefIni.c_str();
strRefIni.TrimLeft();strRefIni.TrimRight();
if(strRefIni.IsEmpty())
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 引用的Ini 为空",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull
).c_str());
return FALSE;
}
CString strSectionNameBeginWith="";
lPos=strRule.Find("SectionNameBeginWith(");
if(lPos>=0)
{
strSectionNameBeginWith=strRule.Mid(lPos+strlen("SectionNameBeginWith("));
lPos=strSectionNameBeginWith.Find(")");
if(lPos>=0)
{
strSectionNameBeginWith=strSectionNameBeginWith.Left(lPos);
}
strSectionNameBeginWith.TrimLeft();strSectionNameBeginWith.TrimRight();
}
BOOL bIsSectionNameAmountKey=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"IsSectionNameAmountKey"));
if(bIsSectionNameAmountKey)
{
DWORD dwAmount=atol(strVal);
for(long l=0;l<dwAmount;l++)
{
CString strTitle;
strTitle.Format("%u",(const char*)strSectionNameBeginWith,l);
//if(!CMyIniFile::IsSectionExistesEx(GET_FULLPATH(strRefIni),strTitle))
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
if(!pRefIni->IsSectionExistes(strTitle))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s AMOUNTKEY 引用的 %s 的TITLE %s 不存在",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,
(const char*)strRefIni,
(const char*)strTitle
).c_str());
return FALSE;
};
}
}
else
{
//if(!CMyIniFile::IsSectionExistesEx(GET_FULLPATH(strRefIni),strSectionNameBeginWith+strVal))
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
if(!pRefIni->IsSectionExistes(strSectionNameBeginWith+strVal))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 引用的 %s 的TITLE %s 不存在",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,
(const char*)strRefIni,
(const char*)(strSectionNameBeginWith+strVal)
).c_str());
return FALSE;
};
}
}
if(bValueIsIniKeyName)
{
std::string strSubStringRefIni;
GetSubString(
strRule,
"ValueIsIniKeyName(",
")",
strSubStringRefIni
);
STRING_LIST ParmList;
ParseString(strSubStringRefIni,",",ParmList);
strRefIni=(ParmList.size()>0)?ParmList[0].c_str():"";
std::string strRefTitle=(ParmList.size()>1)?ParmList[1].c_str():"";
if(strRefTitle.empty())
{
strRefTitle=NO_SECTION_FILE_SECTION_NAME;
}
strRefIni.TrimLeft();strRefIni.TrimRight();
if(strRefIni.IsEmpty())
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 引用的Ini 为空",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull
).c_str());
return FALSE;
}
CString strKeyToFind=strVal;
std::string strSubStringFIX_LENGTH_WITH_PADDING;
GetSubString(
strRule,
"FIX_LENGTH_WITH_PADDING(",
")",
strSubStringFIX_LENGTH_WITH_PADDING
);
if(!strSubStringFIX_LENGTH_WITH_PADDING.empty())
{
STRING_LIST StrListPadding;
ParseString(strSubStringFIX_LENGTH_WITH_PADDING.c_str() ,",",StrListPadding);
if(StrListPadding.size()<2)
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的 FIX_LENGTH_WITH_PADDING 规则参数个数太少",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,(const char*)strRule
).c_str());
return FALSE;
}
long FIX_LENGTH=atol(StrListPadding[0].c_str());
if(FIX_LENGTH<1)
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的 FIX_LENGTH_WITH_PADDING 规则指定的长度不正确",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,(const char*)strRule
).c_str());
return FALSE;
}
CString strPaddingWith=StrListPadding[1].c_str();
while(strKeyToFind.GetLength()<FIX_LENGTH)
{
strKeyToFind=strPaddingWith+strKeyToFind;
}
}
if(strRefTitle!=NO_SECTION_FILE_SECTION_NAME)
{
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
if(!pRefIni->IsSectionExistes(strRefTitle.c_str()))
//if(!CMyIniFile::IsSectionExistesEx(GET_FULLPATH(strRefIni),strRefTitle.c_str()))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 所引用的 %s 不存在TITLE %s",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,(const char*)strRefIni,(strRefTitle==NO_SECTION_FILE_SECTION_NAME)?"":(const char*)strRefTitle.c_str()
).c_str());
return FALSE;
};
}
CMyIniFile * pRefIni=LoadIniIfNotFound(GET_FULLPATH(strRefIni));
if(!pRefIni->IsKeyExistes(strRefTitle.c_str(),strKeyToFind))
//if(!CMyIniFile::IsKeyExistesEx(GET_FULLPATH(strRefIni),strRefTitle.c_str(),strKeyToFind))
{
m_pIBasicMsgUI->ShowErrorMsg(FormatString(
"Title %s 的关键字 %s 所引用的ini %s %s 不存在指定的Key %s",
(pszSection==(CString)NO_SECTION_FILE_SECTION_NAME)?"":pszSection,
(const char*)strKeyFull,
(const char*)strRefIni,
(strRefTitle==NO_SECTION_FILE_SECTION_NAME)?"":("TITLE:"+strRefTitle).c_str(),
(const char*)strKeyToFind
).c_str());
return FALSE;
};
}
return TRUE;
}
BOOL CMyIniFile::CheckStringByRule(const CString strVal, const CString strRule,const CString strContext,std::string& strErr)
{
strErr="";
if(strRule.IsEmpty())
{
return TRUE;
}
STRING_LIST StrListRule;
ParseString((const char*)strRule,";",StrListRule);
BOOL bValueNonEmpty=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"NonEmpty"));
BOOL bValueIsInteger=(StrListRule.end()!=std::find(StrListRule.begin(),StrListRule.end(),"IsInteger"));
if(bValueNonEmpty)
{
if(strVal.IsEmpty())
{
strErr=FormatString(
"%s 字符串 不能为空 ",
(const char*)strContext
);
return FALSE;
}
}
if(bValueIsInteger)
{
if(!IsNumber(strVal))
{
strErr=FormatString(
"%s %s 不是整数",(const char*)strContext,(const char*)strVal
).c_str();
return FALSE;
}
std::string strSubStringINT_VALUE_MAX;
GetSubString(
strRule,
"INT_VALUE_MAX(",
")",
strSubStringINT_VALUE_MAX
);
if(!strSubStringINT_VALUE_MAX.empty())
{
long lIntMax=atol(strSubStringINT_VALUE_MAX.c_str());
if(atol(strVal)>=lIntMax)
{
strErr=FormatString(
"%s %s 大于最大值 %d",
(const char*)strContext,
(const char*)strVal,lIntMax
).c_str();
return FALSE;
}
}
std::string strSubStringINT_VALUE_MIN;
GetSubString(
strRule,
"INT_VALUE_MIN(",
")",
strSubStringINT_VALUE_MIN
);
if(!strSubStringINT_VALUE_MIN.empty())
{
long lIntMin=atol(strSubStringINT_VALUE_MIN.c_str());
if(atol(strVal)>=lIntMin)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -