bool CLanguage::Load ( const CString& szLangName ) { CString szPath ( "../lang/%s/", szLangName.c_str () ); CDirectory dir ( szPath ); if ( !dir.IsOk ( ) ) return false; for ( CDirectory::CIterator iter = dir.Begin (); iter != dir.End (); ++iter ) { CString szCur = iter.GetName (); size_t iExt = szCur.rfind ( '.' ); if ( iExt != CString::npos ) { if ( szCur.substr ( iExt ) == ".txt" ) { LoadFile ( szLangName, szCur.substr ( 0, iExt ) ); } } } m_bIsOk = true; return true; }
CString Directory::GetFolderPath(const CString& strFolderPath) { int n1 = strFolderPath.rfind(FILE_SEPARATOR_STR); if (n1 < 0 ) return _T(""); return strFolderPath.substr(0,n1); }
// 从注册表取ECC 服务端安装目录 CString GetRootPath() { CString resultStr = _T(""); string rootPath = _T(""); try { HKEY hKey = NULL; LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,KEY_PATH,0,KEY_READ,&hKey); if(lRet != ERROR_SUCCESS) return resultStr; LPTSTR lpName = NULL, lpValue = NULL; TCHAR strSubKey[1024]={0}; TCHAR strValKey[1024]={0}; DWORD dwIndex = 0, dwS1 = 1024, dwS2 = 1024, dwType = REG_SZ; BOOL bFindFlag = FALSE; TCHAR szAppRoot[1024] = {0}; while(lRet == ERROR_SUCCESS) { lpName = (LPTSTR)strSubKey; lpValue = (LPTSTR)strValKey; lRet = RegEnumValue(hKey, dwIndex++, lpName , &dwS1,NULL, &dwType ,(LPBYTE)lpValue, &dwS2); dwS1 = 1024; dwS2 = 1024; if(lRet == ERROR_NO_MORE_ITEMS) break; if(::_stricmp(strSubKey,KEY_NAME)==0) { bFindFlag = TRUE; rootPath = strValKey;// //strcpy(rootPath,strValKey); break; } } RegCloseKey(hKey); } catch(...) { return resultStr; } int pos = rootPath.rfind("\\"); if(pos == rootPath.size()-1) rootPath.erase(pos,1); resultStr = rootPath.c_str(); return resultStr; }
void CClient::ParseUser(const CString& sAuthLine) { // user[@identifier][/network] const size_t uSlash = sAuthLine.rfind("/"); if (uSlash != CString::npos) { m_sNetwork = sAuthLine.substr(uSlash + 1); ParseIdentifier(sAuthLine.substr(0, uSlash)); } else { ParseIdentifier(sAuthLine); } }
CString GetExtension( const CString &sPath ) { size_t pos = sPath.rfind( '.' ); if( pos == sPath.npos ) return ""; size_t slash = sPath.find( '/', pos ); if( slash != sPath.npos ) return ""; /* rare: path/dir.ext/fn */ return sPath.substr( pos+1, sPath.size()-pos+1 ); }
void CIniFile::Path(const CString& newPath){ //альтернатива basename, dirname int lastSlashPos = newPath.rfind('/'); CString fname = newPath.substr(lastSlashPos+1, CString::npos); archive_path = backup_path = newPath.substr(0, lastSlashPos); backup_path += "/backup/" + fname; archive_path += "/archive/" + fname; path = newPath; };
void CClient::ParseIdentifier(const CString& sAuthLine) { // user[@identifier] const size_t uAt = sAuthLine.rfind("@"); if (uAt != CString::npos) { const CString sId = sAuthLine.substr(uAt + 1); if (IsValidIdentifier(sId)) { m_sIdentifier = sId; m_sUser = sAuthLine.substr(0, uAt); } else { m_sUser = sAuthLine; } } else { m_sUser = sAuthLine; } }
CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString& sHome) { CString sHomeDir(sHome); if (sHomeDir.empty()) { sHomeDir = CFile::GetHomePath(); } if (sAdd == "~") { return sHomeDir; } CString sAddDir(sAdd); if (sAddDir.Left(2) == "~/") { sAddDir.LeftChomp(); sAddDir = sHomeDir + sAddDir; } CString sRet = ((sAddDir.size()) && (sAddDir[0] == '/')) ? "" : sPath; sAddDir += "/"; CString sCurDir; if (sRet.Right(1) == "/") { sRet.RightChomp(); } for (unsigned int a = 0; a < sAddDir.size(); a++) { switch (sAddDir[a]) { case '/': if (sCurDir == "..") { sRet = sRet.substr(0, sRet.rfind('/')); } else if ((sCurDir != "") && (sCurDir != ".")) { sRet += "/" + sCurDir; } sCurDir = ""; break; default: sCurDir += sAddDir[a]; break; } } return (sRet.empty()) ? "/" : sRet; }
CString BacktraceNames::Format() const { CString ShortenedPath = File; if( ShortenedPath != "" ) { /* Abbreviate the module name. */ size_t slash = ShortenedPath.rfind('/'); if( slash != ShortenedPath.npos ) ShortenedPath = ShortenedPath.substr(slash+1); ShortenedPath = CString("(") + ShortenedPath + ")"; } CString ret = ssprintf( "%0*lx: ", int(sizeof(void*)*2), (long) Address ); if( Symbol != "" ) ret += Symbol + " "; ret += ShortenedPath; return ret; }
CString CDir::ChangeDir(const CString& sPathIn, const CString& sAddIn, const CString& sHomeIn) { /* this function is pretty crappy but needed to fix ZNC's strange way of handling file paths */ CString sResult; CString sPath(sPathIn); CString sAdd(sAddIn); CString sHomeDir(sHomeIn); if (sHomeDir.empty()) { // use the default home dir, if no custom home dir has been passed in. sHomeDir = CZNC::Get().GetHomePath(); } // we want to use backslashes for this function's inner workings. sHomeDir.Replace("/", "\\"); sPath.Replace("/", "\\"); sAdd.Replace("/", "\\"); if (sAdd == "~") { // if the add dir is the home dir (why?!), use that as result... sResult = sHomeDir; } else { if(!PathIsRelative(sAdd.c_str())) { // if add already is an absolute path, use it for the result... // ... however, it can still contain ./ or ../ stuff, // which will be resolved later. sResult = sAdd; } else { // if the first part of the path (sPath) is relative, // make it absolute, starting from the znc.exe directory: if(PathIsRelative(sPath.c_str())) { char szLocalPath[1024] = {0}; // get the full path to znc.exe and strip off "znc.exe" from the end: if(GetModuleFileName(NULL, szLocalPath, 1023) != 0 && szLocalPath[0]) { PathRemoveFileSpec(szLocalPath); if(PathIsDirectory(szLocalPath)) { // append the relative sPath to our znc.exe dir, // thereby making it absolute. char szAbsolutePathBuffer[1024] = {0}; PathCombine(szAbsolutePathBuffer, szLocalPath, sPath.c_str()); // PathCombine will also resolve any ./ or ../ parts in the path. // use the now-absolute path: sPath = szAbsolutePathBuffer; } } } // append the (relative) sAdd path to the (absolute) sPath path: char szAbsoluteResultBuffer[1024] = {0}; PathCombine(szAbsoluteResultBuffer, sPath.c_str(), sAdd.c_str()); sResult = szAbsoluteResultBuffer; } } char szResultBuffer[1024] = {0}; // make sure no ./ or ../ stuff survives this function. never. if(!sResult.empty() && PathCanonicalize(szResultBuffer, sResult.c_str())) { if(sAdd.empty() || sAdd[sAdd.length() - 1] != '\\') { PathRemoveBackslash(szResultBuffer); } else { PathAddBackslash(szResultBuffer); } sResult = szResultBuffer; sResult.Replace("\\", "/"); return sResult; } else { abort(); return ""; // to shut up compiler warning } #else CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString& sHome) { CString sHomeDir(sHome); if (sHomeDir.empty()) { sHomeDir = CZNC::Get().GetHomePath(); } if (sAdd == "~") { return sHomeDir; } CString sAddDir(sAdd); if (sAddDir.Left(2) == "~/") { sAddDir.LeftChomp(); sAddDir = sHomeDir + sAddDir; } CString sRet = ((sAddDir.size()) && (sAddDir[0] == '/')) ? "" : sPath; sAddDir += "/"; CString sCurDir; if (sRet.Right(1) == "/") { sRet.RightChomp(); } for (unsigned int a = 0; a < sAddDir.size(); a++) { switch (sAddDir[a]) { case '/': if (sCurDir == "..") { sRet = sRet.substr(0, sRet.rfind('/')); } else if ((sCurDir != "") && (sCurDir != ".")) { sRet += "/" + sCurDir; } sCurDir = ""; break; default: sCurDir += sAddDir[a]; break; } } return (sRet.empty()) ? "/" : sRet; #endif }