// static bool OTPaths::AppendFile(String& out_strPath, const String& strBasePath, const String& strFileName) { if (!strBasePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strBasePath" << " passed in!\n"; OT_FAIL; } if (!strFileName.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strFileName" << " passed in!\n"; OT_FAIL; } String l_strBasePath_fix(""), l_strFileName_fix(""); if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false; if (!FixPath(strFileName, l_strFileName_fix, false)) return false; std::string l_strBasePath(l_strBasePath_fix.Get()), l_strFileName(l_strFileName_fix.Get()); l_strBasePath.append(l_strFileName); const String l_strPath(l_strBasePath); out_strPath = l_strPath; return true; }
void ProcessingDlg::FoundLibrary(const wxString& OldBasePath,const wxStringStringMap& OldVars,const wxArrayString& Compilers,const LibraryDetectionConfig* Config,const LibraryDetectionConfigSet* Set) { wxStringStringMap Vars = OldVars; wxString BasePath = OldBasePath; BasePath.RemoveLast(); Vars[_T("BASE_DIR")] = BasePath; LibraryResult* Result = new LibraryResult(); Result->Type = rtDetected; Result->ShortCode = Set->ShortCode; Result->LibraryName = FixVars(Set->LibraryName,Vars); Result->BasePath = FixPath(BasePath); Result->PkgConfigVar = Config->PkgConfigVar; Result->Description = FixVars(Config->Description,Vars); Result->Compilers = Compilers; Result->Categories = Set->Categories; for ( size_t i=0; i<Config->IncludePaths.Count(); i++ ) { Result->IncludePath.Add(FixPath(FixVars(Config->IncludePaths[i],Vars))); } for ( size_t i=0; i<Config->LibPaths.Count(); i++ ) { Result->LibPath.Add(FixPath(FixVars(Config->LibPaths[i],Vars))); } for ( size_t i=0; i<Config->ObjPaths.Count(); i++ ) { Result->ObjPath.Add(FixPath(FixVars(Config->ObjPaths[i],Vars))); } for ( size_t i=0; i<Config->Libs.Count(); i++ ) { Result->Libs.Add(FixVars(Config->Libs[i],Vars)); } for ( size_t i=0; i<Config->Defines.Count(); i++ ) { Result->Defines.Add(FixVars(Config->Defines[i],Vars)); } for ( size_t i=0; i<Config->CFlags.Count(); i++ ) { Result->CFlags.Add(FixVars(Config->CFlags[i],Vars)); } for ( size_t i=0; i<Config->LFlags.Count(); i++ ) { Result->LFlags.Add(FixVars(Config->LFlags[i],Vars)); } Result->Headers = Config->Headers; Result->Require = Config->Require; ResultArray& Array = m_FoundResults.GetShortCode(Set->ShortCode); Array.Add(Result); }
BOOL GetIniPath( LPSTR lpIniFile ) /************************************************************************/ { FNAME szFileName; BOOL bRet; #ifdef _MAC // The macintosh ALWAYS uses the "Root:System:Preferences:" path when // acessing preferences - ALWAYS. // Do not use path information in the INI filename. return TRUE; #else if ( GetProfileString( "Micrografx", PRIVATE_INI, "", szFileName, sizeof(FNAME) ) > 2 ) { FixPath( szFileName ); lstrcat( szFileName, lpIniFile ); if ( bRet = FileExists( szFileName ) ) goto Found; } #ifdef CDBUILD if ( GetWindowsDirectory( szFileName, sizeof(FNAME) ) > 2 ) { FixPath( szFileName ); lstrcat( szFileName, lpIniFile ); if ( bRet = FileExists( szFileName ) ) goto Found; } #endif lstrcpy( szFileName, Control.ProgHome ); lstrcat( szFileName, lpIniFile ); if ( !(bRet = FileExists( szFileName )) ) Message( IDS_INI_NOEXIST, Lowercase(lpIniFile) ); Found: lstrcpy( lpIniFile, szFileName ); #ifndef CDBUILD if ( bRet && !FilePermission( lpIniFile, 2 /*WRITE*/ ) ) Message( IDS_INI_NOWRITE, Lowercase(lpIniFile) ); #endif // Set the network variable if the INI and EXE are not in the same place lstrcpy( szFileName, lpIniFile ); stripfile( szFileName ); FixPath( szFileName ); Control.bNetworkInstall = !StringsEqual( Control.ProgHome, szFileName ); return( bRet ); #endif // #ifdef _MAC }
char* findfile (Tcl_Interp *interp, char *name) { int i; char *library, *file; static Tcl_DString *dsPtr = NULL; static char *dirs[] = { "/bitmaps/", "/site/", "/apps/", "/", NULL }; if (! dsPtr) { dsPtr = (Tcl_DString *) ckalloc(sizeof(Tcl_DString)); Tcl_DStringInit(dsPtr); } file = Tcl_TranslateFileName(interp, name, dsPtr); if (file && access(file, R_OK) == 0) { Tcl_ResetResult(interp); return FixPath(file); } buffersize(strlen(name)+20); strcpy(buffer, "~/.tkined/"); strcat(buffer, name); file = Tcl_TranslateFileName(interp, buffer, dsPtr); if (file && access(file, R_OK) == 0) { Tcl_ResetResult(interp); return FixPath(file); } library = Tcl_GetVar2(interp, "tkined", "library", TCL_GLOBAL_ONLY); if (! library) { Tcl_ResetResult(interp); return (char *) NULL; } buffersize(strlen(library)+strlen(name)+20); for (i = 0; dirs[i]; i++) { strcpy(buffer, library); strcat(buffer, dirs[i]); strcat(buffer, name); file = Tcl_TranslateFileName(interp, buffer, dsPtr); if (file && access(file, R_OK) == 0) { Tcl_ResetResult(interp); return FixPath(file); } } return (char *) NULL; }
///////////////////////////////////////////////////////////////////////////// // Populates a tProcessesList with the help of ToolHelp API // Returns an error code paeXXXX DWORD CProcessApi::ProcessesPopulateToolHelp(tProcessesData* pd) { // create a process snapshot HANDLE hSnap = tlhlp_CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnap == INVALID_HANDLE_VALUE) return paeNoSnap; BOOL bMore; tProcessInfo pi = {0}; PROCESSENTRY32 pe32 = {sizeof(PROCESSENTRY32), 0}; // clear the list pd->pl->clear(); // initialize position pd->Pos = 0; bMore = tlhlp_Process32First(hSnap, &pe32); while (bMore) { // convert from PROCESSENTRY32 to my unified tProcessInfo struct pi.pid = pe32.th32ProcessID; _tcscpy_s(pi.FileName, MAX_PATH, pe32.szExeFile); FixPath(pi.FileName); pd->pl->push_back(pi); bMore = tlhlp_Process32Next(hSnap, &pe32); } CloseHandle(hSnap); return paeSuccess; }
const OTString & OTPaths::AppDataFolder() { if (m_strAppDataFolder.Exists()) return m_strAppDataFolder; // already got it, just return it. OTString strHomeDataFolder(""), strAppDataFolder(""); // eg. /home/user/ (the folder that the OT appdata folder will be in.) if(!GetHomeFromSystem(strHomeDataFolder)) { OT_ASSERT(false); return m_strAppDataFolder; } // now lets change all the '\' into '/' // then check that the path /home/user indeed exists, and is a folder. FixPath(strHomeDataFolder,strHomeDataFolder,true); if(!PathExists(strHomeDataFolder)) OT_ASSERT(false); // ok, we have the HomeData Folder, lets append our OT folder to it. if(!AppendFolder(strAppDataFolder,strHomeDataFolder,OT_APPDATA_DIR)) OT_ASSERT(false); bool bFolderCreated; if(!BuildFolderPath(strAppDataFolder,bFolderCreated)) OT_ASSERT(false); m_strAppDataFolder = strAppDataFolder; // all good lets set it. return m_strAppDataFolder; }
bool CreateRecursionDir(std::string path) { if (path.length() == 0) return true; std::string sub; FixPath(path); std::string::size_type pos = path.find('/'); while (pos != std::string::npos) { std::string cur = path.substr(0, pos-0); if (cur.length() > 0 && !IsDirectory(cur)) { bool ret = false; #ifdef WIN32 ret = CreateDirectoryA(cur.c_str(), NULL) ? true : false; #else ret = (mkdir(cur.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == 0); #endif if (!ret) { return false; } } pos = path.find('/', pos+1); } return true; }
VOID CProcessManager::FindTheHideProcess() { ULONG i = 0; HANDLE hProcess = NULL; BOOL bRet = FALSE; DWORD dwReturn = 0; int iHideProcessCount = 0; EnableDebugPri(); for ( i= 4;i<100000;i+=4) { BOOL bHide = TRUE; hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,i); if (hProcess!=0) { CloseHandle(hProcess); for (vector <PROCESS_INFO>::iterator Iter = m_Vector.begin( ); Iter != m_Vector.end( ); Iter++ ) { if (i==Iter->ulProcessID) { bHide = FALSE; } } if(bHide==TRUE) { PROCESS_INFO ProcessInfor = {0} ; bRet = DeviceIoControl(g_hDevice,IOCTL_ENUMHIDEPROCESSINFOR, &i, sizeof(ULONG), &ProcessInfor, sizeof(PROCESS_INFO), &dwReturn, NULL); if(bRet&&wcslen(ProcessInfor.wzProcessName)!=0) { CString strTemp; FixPath(ProcessInfor.wzProcessFileName); strTemp = GetFileCompanyName(ProcessInfor.wzProcessFileName); wcscpy(ProcessInfor.wzCompanyName,strTemp.GetBuffer()); m_Vector.push_back(ProcessInfor); iHideProcessCount++; } } } } g_HideProcessCount = iHideProcessCount; }
bool DirectoryIterator::IsDirectory() { char dtmp[_MAX_PATH]; GetFullPath(dtmp); //this is needed on windows!!! FixPath(dtmp, false); return dir_exists(dtmp); }
const bool OTPaths::AppendFile(OTString & out_strPath, const OTString & strBasePath, const OTString & strFileName) { if (!strBasePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strBasePath"); OT_ASSERT(false); } if (!strFileName.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strFileName"); OT_ASSERT(false); } OTString l_strBasePath_fix(""), l_strFileName_fix(""); if(!FixPath(strBasePath,l_strBasePath_fix,true)) return false; if(!FixPath(strFileName,l_strFileName_fix,false)) return false; std::string l_strBasePath(l_strBasePath_fix.Get()), l_strFileName(l_strFileName_fix.Get()); l_strBasePath.append(l_strFileName); const OTString l_strPath(l_strBasePath); out_strPath = l_strPath; return true; }
BOOL CPluginPrefPage::OnCommand(WPARAM wParam, LPARAM lParam) { HWND hActiveWnd = GetActiveDoc(); HWND hDlg = GetSafeHwnd(); int id = GET_WM_COMMAND_ID(wParam, lParam); UINT codeNotify = GET_WM_COMMAND_CMD(wParam, lParam); switch (id) { case IDC_PREF_USEPLUGINS: Control.UsePlugins = !Control.UsePlugins; ::CheckDlgButton( hDlg, id, Control.UsePlugins ); SetModified(TRUE); break; case IDC_PREF_PLUGINPATH1: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; ::GetDlgItemText( hDlg, id, Control.PluginPath1, sizeof(Control.PluginPath1)); FixPath( Lowercase( Control.PluginPath1 ) ); SetModified(TRUE); break; case IDC_PREF_PLUGINPATH2: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; ::GetDlgItemText( hDlg, id, Control.PluginPath2, sizeof(Control.PluginPath2)); FixPath( Lowercase( Control.PluginPath2 ) ); SetModified(TRUE); break; default: return (CPPPropertyPage::OnCommand(wParam, lParam)); break; } return(TRUE); }
///////////////////////////////////////////////////////////////////////////// // Populates the list using PsApi functions DWORD CProcessApi::ProcessesPopulatePsApi(tProcessesData* pd) { DWORD nProcess, // number of processes returned nCount(4096); // maximum number of processes (defined by me) // Dynamic array for storing returned processes IDs DWORD* processes = new DWORD[nCount]; // enum all processes if (!psapi_EnumProcesses(processes, nCount * sizeof(DWORD), &nProcess)) { delete processes; return paeNoSnap; } // convert fron bytes count to items count nProcess /= 4; tProcessInfo pi = {0}; // walk in process list for (DWORD i=0; i < nProcess; i++) { // open process for querying only HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processes[i]); if (!hProcess) continue; // get the process's image name by getting first module DWORD nmod; HMODULE mod1; if (!psapi_EnumProcessModules(hProcess, &mod1, sizeof(mod1), &nmod)) _tcscpy_s(pi.FileName, MAX_PATH, _T("-")); else { psapi_GetModuleFileNameEx(hProcess, mod1, pi.FileName, sizeof(pi.FileName)); FixPath(pi.FileName); } // get the process ID pi.pid = processes[i]; // store in the list pd->pl->push_back(pi); CloseHandle(hProcess); } // reposition list to 0 pd->Pos = 0; delete processes; return paeSuccess; }
//! 覆写式创建 LoggerId CLogerManager::CreateLogger(std::string name,std::string path,int nLevel,bool display, bool monthdir, unsigned int limitsize) { std::string _tmp; std::string _pid; GetProcessInfo(_tmp, _pid); if (name.length() == 0) { ShowColorText("log4z: create logger error, name is empty ! \r\n", LOG_LEVEL_FATAL); return -1; } TrimLogConfig(path); FixPath(path); LoggerId newID = -1; { std::map<std::string, LoggerId>::iterator iter = m_ids.find(name); if (iter != m_ids.end()) { newID = iter->second; } } if (newID == -1) { if (m_lastId +1 >= LOG4Z_LOGGER_MAX) { ShowColorText("log4z: CreateLogger can not create|writeover, because loggerid need < LOGGER_MAX! \r\n", LOG_LEVEL_FATAL); return -1; } newID = ++ m_lastId; m_ids[name] = newID; } if (!path.empty()) { m_loggers[newID]._path = path; } if (newID > LOG4Z_MAIN_LOGGER_ID) { m_loggers[newID]._name = name; } m_loggers[newID]._pid = _pid; m_loggers[newID]._level = nLevel; m_loggers[newID]._enable = true; m_loggers[newID]._display = display; m_loggers[newID]._monthdir = monthdir; m_loggers[newID]._limitsize = limitsize; if (limitsize == 0) { m_loggers[newID]._limitsize = 4000; } return newID; }
BOOL CMemoryPrefPage::OnCommand(WPARAM wParam, LPARAM lParam) { BOOL Bool; HWND hActiveWnd = GetActiveDoc(); HWND hDlg = GetSafeHwnd(); int id = GET_WM_COMMAND_ID(wParam, lParam); UINT codeNotify = GET_WM_COMMAND_CMD(wParam, lParam); switch (id) { case IDC_PREF_RAMDISK: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; ::GetDlgItemText( hDlg, id, Control.RamDisk, sizeof(Control.RamDisk)); FixPath( Lowercase( Control.RamDisk ) ); SetModified(TRUE); break; case IDC_PREF_MEMMIN: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; Control.MainMemMin = ::GetDlgItemSpin( hDlg, id, &Bool, NO ); SetModified(TRUE); break; case IDC_PREF_MEMFACTOR: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; Control.MainMemFactor = ::GetDlgItemSpin( hDlg, id, &Bool, NO ); SetModified(TRUE); break; case IDC_PREF_LINEART: Control.LineArtAsGray = !Control.LineArtAsGray; ::CheckDlgButton( hDlg, id, Control.LineArtAsGray ); SetModified(TRUE); break; default: return (CPPPropertyPage::OnCommand(wParam, lParam)); break; } return(TRUE); }
// static bool OTPaths::BuildFilePath(const String& strFolderPath, bool& out_bFolderCreated) { out_bFolderCreated = false; String l_strFilePath_fix(""), l_strFilePath_real(""); if (!ToReal(strFolderPath, l_strFilePath_real)) return false; // path to real if (!FixPath(l_strFilePath_real, l_strFilePath_fix, false)) return false; // real to fixed real std::string l_strFilePath(l_strFilePath_fix.Get()); // fixed real path. std::vector<std::string> vFolders; split_byChar(vFolders, l_strFilePath, "/", split::no_empties); size_t nSize = vFolders.size(); std::string l_strPathPart(""); bool l_FolderExists(false), l_bBuiltFolder(false); const bool bLog(Log::IsInitialized()); for (size_t i = 0; i < nSize; i++) { #ifndef _WIN32 // aka UNIX if (0 == i) l_strPathPart += "/"; // add annother / for root. #endif l_strPathPart += vFolders[i]; if ((i + 1) == nSize) continue; // file should be skipped l_strPathPart += "/"; // is a folder, so should append / if (0 == i) continue; // / or x:/ should be skiped. String strPathPart(l_strPathPart); if (!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder)) return false; if (bLog && l_bBuiltFolder) otOut << __FUNCTION__ << ": Made new folder: " << l_strPathPart << ""; if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true; } return true; }
//************************************************************************ UINT CLGBApp::GetSettingInt(LPCTSTR lpEntry, int iDefault, BOOL fUserSetting) //************************************************************************ { FNAME szPath; STRING szIni, szSection; szIni[0] = '\0'; LoadString( GetApp()->GetInstance(), IDS_INI, szIni, sizeof(szIni) ); szSection[0] = '\0'; LoadString( GetApp()->GetInstance(), IDS_SECTION, szSection, sizeof(szSection) ); GetWindowsDirectory(szPath, sizeof(szPath)); FixPath(szPath); lstrcat(szPath, szIni); return(GetPrivateProfileInt(szSection, lpEntry, iDefault, szPath)); }
///////////////////////////////////////////////////////////////////////////// // Populates the modules of a process using PsApi api DWORD CProcessApi::ModulesPopulatePsApi(DWORD pid, tModulesData* md) { DWORD nModules, nCount = 4096; // allocate memory for modules HMODULE* modules = new HMODULE[nCount]; // open process for querying only HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid); if (!hProcess) return paeNoSnap; // now try to enum all modules if (!psapi_EnumProcessModules(hProcess, modules, nCount * sizeof(DWORD), &nModules)) { CloseHandle(hProcess); return paeNoSnap; } // because nModules returned from EnumProcessModules() is in bytes, I divid by 4 to return n DWORDs nModules /= 4; tModuleInfo mi = {0}; MODULEINFO psapiMi = {0}; for (DWORD i=0; i < nModules; i++) { // get module name psapi_GetModuleFileNameEx(hProcess, modules[i], mi.FileName, sizeof(mi.FileName)); FixPath(mi.FileName); // get module information psapi_GetModuleInformation(hProcess, modules[i], &psapiMi, sizeof(MODULEINFO)); // get relevant data mi.ImageBase = psapiMi.lpBaseOfDll; mi.ImageSize = psapiMi.SizeOfImage; // save item md->ml->push_back(mi); } md->Pos = 0; CloseHandle(hProcess); delete modules; return paeSuccess; }
LPSTR GetFileName( /***********************************************************************/ HWND hDlg, LPSTR lpFileName) { FNAME szFileName; STRING szString; GetDlgItemText( hDlg, IDC_FNAME, szFileName, sizeof(szFileName) ); FixFileName(szFileName); GetDlgItemText( hDlg, IDC_FPATH, szString, sizeof(szString) ); FixPath( szString ); lstrcat( szString, szFileName ); Lowercase(szString); lstrcpy(lpFileName, szString); return(lpFileName); }
//************************************************************************ BOOL CLGBApp::WriteSettingString(LPCTSTR lpEntry, LPCTSTR lpValue, BOOL fUserSetting) //************************************************************************ { FNAME szPath; STRING szIni, szSection; szIni[0] = '\0'; LoadString( GetApp()->GetInstance(), IDS_INI, szIni, sizeof(szIni) ); szSection[0] = '\0'; LoadString( GetApp()->GetInstance(), IDS_SECTION, szSection, sizeof(szSection) ); GetWindowsDirectory(szPath, sizeof(szPath)); FixPath(szPath); lstrcat(szPath, szIni); return(WritePrivateProfileString(szSection, lpEntry, lpValue, szPath)); }
void CLocationsPrefPage::HandleOK() { FixPath(m_Clipbits); PictPubApp.WriteLocalProfileFileName( "ClipBit", m_Clipbits ); FixPath( m_Printstyles ); PictPubApp.WriteLocalProfileFileName( "PrnStyle", m_Printstyles ); FixPath( m_Brushes ); PictPubApp.WriteLocalProfileFileName( "Brush", m_Brushes ); FixPath( m_Palettes ); PictPubApp.WriteLocalProfileFileName( "Palette", m_Palettes ); FixPath( m_Textures ); PictPubApp.WriteLocalProfileFileName( "Texture", m_Textures ); FixPath( m_Devices ); PictPubApp.WriteLocalProfileFileName( "Device", m_Devices ); FixPath( m_Effects ); PictPubApp.WriteLocalProfileFileName( "Effects", m_Effects ); FixPath( m_Macros ); PictPubApp.WriteLocalProfileFileName( "Macros", m_Macros ); FixPath( m_Importfilters ); PictPubApp.WriteLocalProfileFileName( "Filters", m_Importfilters ); LoadAllExtNamePaths( NO ); CPPPropertyPage::HandleOK(); }
const bool OTPaths::BuildFolderPath(const OTString & strFolderPath, bool & out_bFolderCreated) { out_bFolderCreated = false; OTString l_strFolderPath_fix(""), l_strFolderPath_real(""); if (!ToReal(strFolderPath,l_strFolderPath_real)) return false; // path to real if (!FixPath(l_strFolderPath_real,l_strFolderPath_fix,true)) return false; // real to fixed real std::string l_strFolderPath(l_strFolderPath_fix.Get()); // fixed real path. std::vector<std::string> vFolders; OTString::split_byChar(vFolders,l_strFolderPath,"/",OTString::split::no_empties); size_t nSize = vFolders.size(); std::string l_strPathPart(""); bool l_FolderExists(false), l_bBuiltFolder(false); const bool bLog(OTLog::IsInitialized()); for (int i = 0; i < nSize; i++) { #ifndef _WIN32 // aka UNIX if(0 == i) l_strPathPart += "/"; //add annother / for root. #endif l_strPathPart += vFolders[i]; l_strPathPart += "/"; if(0 == i) continue; // / or x:/ should be skiped. OTString strPathPart(l_strPathPart); if(!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder)) return false; if (bLog && l_bBuiltFolder) OTLog::vOutput(0,"%s: Made new folder: %s\n", __FUNCTION__, l_strPathPart.c_str()); if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true; } return true; }
BOOL GetFileLocation( /************************************************************************/ WORD idFileType, LPSTR lpPath) { FNAME szExtension, szFileName, szTemp; if ( !LookupExtension( idFileType, szExtension ) ) return( NO ); /* Find out where the user was last, so we can change over to that directory */ lstrcpy( szTemp, szExtension ); lstrcat( szTemp, "temp" ); GetDefaultString( szTemp, szExtension, szFileName, sizeof(FNAME) ); stripfile( szFileName ); FixPath( szFileName ); lstrcat( szFileName, szExtension ); lstrcpy( lpPath, szFileName ); return( YES ); }
// this function dosn't change the "strRelativePath" so. It will only fix the strBasePath. const bool OTPaths::RelativeToCanonical(OTString & out_strCanonicalPath, const OTString & strBasePath, const OTString & strRelativePath) { if (!strBasePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strBasePath" ); OT_ASSERT(false); } if (!strRelativePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strRelativePath" ); OT_ASSERT(false); } OTString l_strBasePath_fix(""); if(!FixPath(strBasePath,l_strBasePath_fix,true)) return false; if(strRelativePath.Compare(".")) { out_strCanonicalPath = strBasePath; return true; } // if ".", return base path. std::string l_strBasePath(l_strBasePath_fix.Get()), l_strRelativePath(strRelativePath.Get()); l_strBasePath.append(l_strRelativePath); OTString l_strPath(l_strBasePath), l_strCanonicalPath(""); if(!ToReal(l_strPath,l_strCanonicalPath)) return false; out_strCanonicalPath = l_strCanonicalPath; return true; }
BOOL SetFileLocation( /************************************************************************/ WORD idFileType, LPSTR lpPath) { FNAME szFileName, szExtension; if ( !LookupExtension( idFileType, szExtension ) ) return( NO ); /* Whatever disk and directory the user changed to, */ /* store it away so we come back to the same place next time */ lstrcpy( szFileName, lpPath ); stripfile( szFileName ); FixPath( szFileName ); lstrcat( szFileName, szExtension ); if ( Save.OKtoSavePath ) PutDefaultString( szExtension, szFileName ); lstrcat( szExtension, "temp" ); PutDefaultString( szExtension, szFileName ); return( TRUE ); }
virtual LoggerId DynamicCreateLogger( std::string path, std::string name, int nLevel, bool display) { TrimString(path); if (path.length() == 0) { path = "./log/"; } else { FixPath(path); } if (name.length() == 0) { name = GetMainLoggerName(); } CAutoLock l(m_idLock); m_lastId++; if (m_lastId >= LOGGER_MAX) { return -1; } if (m_ids.find(name) != m_ids.end()) { return -1; } m_ids.insert(std::pair<std::string, LoggerId>(name, m_lastId)); m_loggers[m_lastId]._path = path; m_loggers[m_lastId]._name = name; m_loggers[m_lastId]._level = nLevel; m_loggers[m_lastId]._enable = true; m_loggers[m_lastId]._display = display; return m_lastId; }
// this function dosn't change the "strRelativePath" so. It will only fix the // strBasePath. // static bool OTPaths::RelativeToCanonical(String& out_strCanonicalPath, const String& strBasePath, const String& strRelativePath) { if (!strBasePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strBasePath" << " passed in!\n"; OT_FAIL; } if (!strRelativePath.Exists()) { otErr << __FUNCTION__ << ": Null: " << "strRelativePath" << " passed in!\n"; OT_FAIL; } String l_strBasePath_fix(""); if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false; if (strRelativePath.Compare(".")) { out_strCanonicalPath = strBasePath; return true; } // if ".", return base path. std::string l_strBasePath(l_strBasePath_fix.Get()), l_strRelativePath(strRelativePath.Get()); l_strBasePath.append(l_strRelativePath); String l_strPath(l_strBasePath), l_strCanonicalPath(""); if (!ToReal(l_strPath, l_strCanonicalPath)) return false; out_strCanonicalPath = l_strCanonicalPath; return true; }
///////////////////////////////////////////////////////////////////////////// // Populates the modules of a process using ToolHelp api DWORD CProcessApi::ModulesPopulateToolHelp(DWORD pid, tModulesData* md) { MODULEENTRY32 me32 = {sizeof(MODULEENTRY32), 0}; tModuleInfo mi = {0}; // Take a snapshot of all modules in the specified process. HANDLE hModuleSnap = INVALID_HANDLE_VALUE; try { hModuleSnap = tlhlp_CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); } catch(...) { } if (hModuleSnap == INVALID_HANDLE_VALUE) return paeNoSnap; // Start walking BOOL bMore = tlhlp_Module32First(hModuleSnap, &me32); do { _tcscpy_s(mi.FileName, MAX_PATH, me32.szExePath); FixPath(mi.FileName); mi.ImageBase = me32.modBaseAddr; mi.ImageSize = me32.modBaseSize; // save item md->ml->push_back(mi); // search next bMore = tlhlp_Module32Next(hModuleSnap, &me32); } while (bMore); CloseHandle (hModuleSnap); md->Pos = 0; return paeSuccess; }
//若是不存在上级文件夹则自动创建 bool zs_ut_s::CreateRecursionDir(std::string path) { if (path.length() == 0) return true; std::string sub; char lastchar=0; //预处理 FixPath(path); std::string::size_type pos = path.find('/'); while (pos != std::string::npos) { std::string cur = path.substr(0, pos-0); if (cur.length() > 0 && !IsDirectory(cur)) { if (!CreateDir(cur)) { return false; } } pos = path.find('/', pos+1); } return true; }
virtual bool ConfigMainLogger(std::string path,std::string name,int nLevel,bool display) { TrimString(path); if (path.length() == 0) { path = "./log/"; } else { FixPath(path); } if (name.length() == 0) { name = GetMainLoggerName(); } CAutoLock l(m_idLock); m_loggers[m_main]._path = path; m_loggers[m_main]._name = name; m_loggers[m_main]._level = nLevel; m_loggers[m_main]._enable = true; m_loggers[m_main]._display = display; return true; }
void SetFileName( /***********************************************************************/ HWND hDlg, int idCtl, LPSTR lpFileSpec, LPSTR lpSaveName, BOOL bSaving) { FNAME szName, szSpec, szExt; if (bSaving && !fUntitled) { lstrcpy( szName, stripdir(lpSaveName) ); stripext( szName ); lstrcpy( szExt, extension(lpFileSpec) ); lstrcpy( szSpec, lpFileSpec ); stripfile( szSpec ); FixPath( szSpec ); lstrcat( szSpec, szName ); lstrcat( szSpec, szExt ); SetDlgItemText( hDlg, idCtl, Lowercase(szSpec) ); } else SetDlgItemText( hDlg, idCtl, Lowercase(lpFileSpec) ); }