📄 myinifile.cpp
字号:
{
strErr=FormatString(
"%s %s 小于最小值 %d",
(const char*)strContext,
(const char*)strVal,lIntMin
).c_str();
return FALSE;
}
}
}
std::string strSubStringStringBeginWith;
GetSubString(
strRule,
"StringBeginWith(",
")",
strSubStringStringBeginWith
);
if(!strSubStringStringBeginWith.empty())
{
if(0!=strcmpi(strVal.Left(strSubStringStringBeginWith.size()),strSubStringStringBeginWith.c_str()))
{
strErr=FormatString(
"%s 字符串 %s 没有以 %s 开始",
(const char*)strContext,
(const char*)strVal,strSubStringStringBeginWith.c_str()
).c_str();
return FALSE;
}
}
std::string strSubStringIntegerWithLeadingString;
GetSubString(
strRule,
"IntegerWithLeadingString(",
")",
strSubStringIntegerWithLeadingString
);
if(!strSubStringIntegerWithLeadingString.empty())
{
if(0!=strcmpi(strVal.Left(strSubStringIntegerWithLeadingString.size()),strSubStringIntegerWithLeadingString.c_str()))
{
strErr=FormatString(
"%s 字符串 %s 没有以 %s 开始",
(const char*)strContext,
(const char*)strVal,strSubStringIntegerWithLeadingString.c_str()
).c_str();
return FALSE;
}
if(!strVal.Mid(strSubStringIntegerWithLeadingString.size()))
{
strErr=FormatString(
"%s 字符串 %s 开始部分为 %s 但后续的部分不都是整数",
(const char*)strContext,
(const char*)strVal,strSubStringIntegerWithLeadingString.c_str()
).c_str();
return FALSE;
}
}
std::string strSubStringStringMaxLength;
GetSubString(
strRule,
"StringMaxLength(",
")",
strSubStringStringMaxLength
);
if(!strSubStringStringMaxLength.empty())
{
long lStringMaxLength=atol(strSubStringStringMaxLength.c_str());
if(lStringMaxLength>0)
{
if(strVal.GetLength()>=lStringMaxLength)
{
strErr=FormatString(
"%s %s 长度超过最大值 %d",
(const char*)strContext,
(const char*)strVal,lStringMaxLength
).c_str();
return FALSE;
}
}
}
return TRUE;
}
BOOL CMyIniFile::SimplifyExpression(
STD_MAP_STRING_2_STRING& ReplaceMapping,
const const char* strExpression,
CString& strExpressionNew,
std::string& strErr
)
{
strErr="";
strExpressionNew=strExpression;
long lGetVar=-1;
long lEnd=-1;
for(STD_MAP_STRING_2_STRING::iterator itr=ReplaceMapping.begin();itr!=ReplaceMapping.end();itr++)
{
strExpressionNew.Replace((*itr).first.c_str(),(*itr).second.c_str());
}
return TRUE;
}
void CMyIniFile::CheckIniFile(
INI_META_DATA_LIST& IniMetaDataList,
const char* strFile,
const char* pszBaseDir,
IBasicMsgUI* pIBasicMsgUI
)
{
// pIBasicMsgUI->ShowErrorMsg(FormatString(
// "检查 %s 开始。",strFile
// ).c_str());
if(IniMetaDataList.size()<1)
{
pIBasicMsgUI->ShowErrorMsg(FormatString(
" %s 未定义INI规则。",strFile
).c_str());
}
else
{
CMyIniFile MyIniFile(pszBaseDir,pIBasicMsgUI);
CString strFileIni=strFile;
if(!MyIniFile.ReadAndParse(
strFileIni
))
{
pIBasicMsgUI->ShowErrorMsg(
FormatString("Ini文件 %s 打开失败",strFileIni).c_str()
);
return;
};
///
for(long l=0;l<IniMetaDataList.size();l++)
{
INI_META_DATA* pIniMetaData=IniMetaDataList[l];
MyIniFile.SetFileRedirectSubFolder(pIniMetaData->IniCheckRule.strFileRedirectToSubFolder.c_str());
////
MyIniFile.CheckAllIniSectionAutoCheck(pIniMetaData->IniCheckRule);
//CheckIniFile(*pIniMetaData,strFile,pszBaseDir,pIBasicMsgUI);
////
// pIBasicMsgUI->ShowErrorMsg(FormatString(
// ""
// ).c_str());
}
}
//
// pIBasicMsgUI->ShowErrorMsg(FormatString(
// "检查 %s 结束。",strFile
// ).c_str());
}
void CMyIniFile::CheckIniFile(
INI_META_DATA& IniMetaData,
const char* strFile,
const char* pszBaseDir,
IBasicMsgUI* pIBasicMsgUI
)
{
CMyIniFile MyIniFile(pszBaseDir,pIBasicMsgUI,IniMetaData.IniCheckRule.strFileRedirectToSubFolder.c_str());
CString strFileIni=strFile;
if(!MyIniFile.ReadAndParse(
strFileIni
))
{
pIBasicMsgUI->ShowErrorMsg(
FormatString("Ini文件 %s 打开失败",strFileIni).c_str()
);
return;
};
MyIniFile.CheckAllIniSectionAutoCheck(IniMetaData.IniCheckRule);
}
void SaveIniStringList(
const char* pszIniFile,
const char* pszSection,
STRING_LIST& StringList
)
{
WritePrivateProfileString(
pszSection,
"StringItemCount",
FormatString("%d",StringList.size()).c_str(),
pszIniFile
);
for(long l=0;l<StringList.size();l++)
{
WritePrivateProfileString(
pszSection,
FormatString("StringItem%d",l).c_str(),
StringList[l].c_str(),
pszIniFile
);
}
}
void LoadIniStringList(
const char* pszIniFile,
const char* pszSection,
STRING_LIST& StringList,
const BOOL bRemoveDuplicated
)
{
StringList.clear();
char szTxt[1024]={0,};
szTxt[0]=0;
GetPrivateProfileString(
pszSection,
"StringItemCount",
"",
szTxt,
sizeof(szTxt),
pszIniFile
);
DWORD dwStringItemCount=atol(szTxt);
for(long l=0;l<dwStringItemCount;l++)
{
szTxt[0]=0;
GetPrivateProfileString(
pszSection,
FormatString("StringItem%d",l).c_str(),
"",
szTxt,
sizeof(szTxt),
pszIniFile
);
std::string strLastSelectedItem=szTxt;
StringTrimLeft(strLastSelectedItem);
StringTrimRight(strLastSelectedItem);
if(strLastSelectedItem.empty())
{
continue;
}
if(bRemoveDuplicated)
{
if(StringList.end()!=std::find(StringList.begin(),StringList.end(),strLastSelectedItem))
{
continue;
}
}
StringList.push_back(strLastSelectedItem);
}
}
CString GetRelativeFilePath(CString strFilePath, CString strDir,const BOOL bReplaceBackSlashWithSlash)
{
if(strFilePath.IsEmpty())
{
return strFilePath;
}
CString strFilePathNew=strFilePath;
CString strDirNew=strDir;
if(strDirNew.Right(1)!='\\')
{
strDirNew+="\\";
}
if(bReplaceBackSlashWithSlash)
{
strFilePathNew.Replace("\\","/");
strDirNew.Replace("\\","/");
}
else
{
strFilePathNew.Replace("/","\\");
strDirNew.Replace("/","\\");
}
if(strFilePathNew.GetLength()<strDirNew.GetLength())
{
return strFilePathNew;
}
if(0==strFilePathNew.Left(strDirNew.GetLength()).CompareNoCase(strDirNew))
{
strFilePathNew=strFilePathNew.Mid(strDirNew.GetLength());
}
return strFilePathNew;
}
long FindStringInFile(const char* pszFilePath,const char* pszPattern,const bool bCompareNoCase,const bool bMatchPartial)
{
CStdioFile f;
if(!f.Open(GetFullPath(pszFilePath).c_str(),CFile::modeRead|CFile::typeText|CFile::shareDenyNone))
{
return -1;
}
CString strPattern=pszPattern;
if(bCompareNoCase)
{
strPattern.MakeLower();
}
long l=0;
CString strTxt;
while(f.ReadString(strTxt))
{
if(bCompareNoCase)
{
strTxt.MakeLower();
}
if(bMatchPartial)
{
if(strTxt.Find(strPattern)>=0)
{
return l;
}
}
else
{
if(strTxt==strPattern)
{
return l;
}
}
++l;
}
return -1;
}
BOOL OpenFileAndAutoLocateWithEditPlus(
const char* strFilePath,
const DWORD dwLineToLocate,
const DWORD dwColumnToLocate,
const HWND hWnd,
const char* pszFileExt
)
{
HKEY key=0;
LONG lRet=0;
char szReg[1024]={0,};
sprintf(szReg,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",pszFileExt);
lRet=RegOpenKeyEx(HKEY_CURRENT_USER,szReg, 0, KEY_READ, &key);
if( lRet== ERROR_SUCCESS)
{
char szApplication[1024]={0,};
DWORD cbSize=0;
cbSize=sizeof(szApplication);
lRet=RegQueryValueEx(key, "Application", NULL, 0, (LPBYTE)szApplication, &cbSize);
if(lRet == ERROR_SUCCESS)
{
if(0==strcmpi(szApplication,"editplus.exe"))
{
char szAppReg[1024]={0,};
sprintf(szAppReg,"Applications\\%s\\shell\\open\\command",szApplication);
RegCloseKey(key);
key=0;
lRet=RegOpenKeyEx(HKEY_CLASSES_ROOT,szAppReg, 0, KEY_READ, &key);
if( lRet== ERROR_SUCCESS)
{
char szCmdLine[1024]={0,};
DWORD cbSize=sizeof(szCmdLine);
lRet=RegQueryValueEx(key, 0, NULL, 0, (LPBYTE)szCmdLine, &cbSize);
if(lRet == ERROR_SUCCESS)
{
CString strCmdLineFull=szCmdLine;
long lPos=strCmdLineFull.Find("\"%1\"");
if(lPos>0)
{
CString strApp=strCmdLineFull.Left(lPos);
strApp.TrimLeft();strApp.TrimRight();
if(strApp.Left(1)=="\"")
{
strApp=strApp.Mid(1);
}
if(strApp.Right(1)=="\"")
{
strApp=strApp.Left(strApp.GetLength()-1);
}
strApp.MakeUpper();
CString strCmdLine;
//edit plush
strCmdLine.Format("%s -cursor %u:%u",strFilePath,dwLineToLocate,dwColumnToLocate);
long lRet=(long)ShellExecute(hWnd,0,strApp,strCmdLine,"",SW_SHOWNORMAL);
if(lRet>32)
{
RegCloseKey(key);
return TRUE;
}
}
}
}
}
}
}
RegCloseKey(key);
key=0;
return FALSE;
}
BOOL OpenFileAndAutoLocateWithUltraEdit(
const char* strFilePath,
const DWORD dwLineToLocate,
const DWORD dwColumnToLocate,
const HWND hWnd,
const char* pszFileExt
)
{
HKEY key=0;
LONG lRet=0;
lRet=RegOpenKeyEx(HKEY_CLASSES_ROOT,".log", 0, KEY_READ, &key);
if( lRet== ERROR_SUCCESS)
{
char szDefaultHandler[1024]={0,};
DWORD cbSize=0;
cbSize=sizeof(szDefaultHandler);
lRet=RegQueryValueEx(key, 0, NULL, 0, (LPBYTE)szDefaultHandler, &cbSize);
if(lRet == ERROR_SUCCESS)
{
if(0==strcmpi(szDefaultHandler,"UltraEdit.log"))
{
RegCloseKey(key);
key=0;
lRet=RegOpenKeyEx(HKEY_CLASSES_ROOT,"UltraEdit.log\\shell\\open\\command", 0, KEY_READ, &key);
if( lRet== ERROR_SUCCESS)
{
char szCmdLine[1024]={0,};
DWORD cbSize=sizeof(szCmdLine);
lRet=RegQueryValueEx(key, 0, NULL, 0, (LPBYTE)szCmdLine, &cbSize);
if(lRet == ERROR_SUCCESS)
{
CString strCmdLineFull=szCmdLine;
long lPos=strCmdLineFull.Find("\"%1\"");
if(lPos>0)
{
CString strApp=strCmdLineFull.Left(lPos);
strApp.TrimLeft();strApp.TrimRight();
if(strApp.Left(1)=="\"")
{
strApp=strApp.Mid(1);
}
if(strApp.Right(1)=="\"")
{
strApp=strApp.Left(strApp.GetLength()-1);
}
strApp.MakeUpper();
CString strCmdLine;
//ultra edit
strCmdLine.Format("%s/%u/%u",strFilePath,dwLineToLocate,dwColumnToLocate);
long lRet=(long)ShellExecute(hWnd,0,strApp,strCmdLine,"",SW_SHOWNORMAL);
if(lRet>32)
{
RegCloseKey(key);
return TRUE;
}
}
}
}
}
}
}
RegCloseKey(key);
key=0;
return FALSE;
}
BOOL OpenFileAndAutoLocate(
const char* strFilePath,
const DWORD dwLineToLocate,
const DWORD dwColumnToLocate,
const HWND hWnd
)
{
const char* pszFileExt=strrchr(strFilePath,'.');
if(!pszFileExt)
{
return FALSE;
}
if(OpenFileAndAutoLocateWithEditPlus(strFilePath,dwLineToLocate,dwColumnToLocate,hW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -