TCHAR* GetFileTitlePtr( TCHAR* pszPath ) { // Given a full file path, get a pointer to its title. TCHAR* p = pszPath + lstrlen(pszPath); while ((p > pszPath) && ! FILE_IsDirSep(*p)) p--; if ( FILE_IsDirSep(*p)) p++; return p; }
bool CTaksiShared::InitShared() { // Call this only once the first time. // determine my file name ASSERT(g_hInst); DEBUG_MSG(( "CTaksiShared::InitShared" LOG_CR )); m_dwVersionStamp = TAKSI_VERSION_N; m_hMasterWnd = NULL; m_iMasterUpdateCount = 0; m_bMasterExiting = false; m_hHookCBT = NULL; m_iProcessCount = 0; // how many processes attached? m_dwHotKeyMask = 0; m_bRecordPause = false; #ifdef USE_DIRECTX8 m_nDX8_Present = 0; // offset from start of DLL to the interface element i want. m_nDX8_Reset = 0; #endif #ifdef USE_DIRECTX9 m_nDX9_Present = 0; m_nDX9_Reset = 0; #endif // determine my directory m_szIniDir[0] = '\0'; DWORD dwLen = GetCurrentDirectory( sizeof(m_szIniDir)-1, m_szIniDir ); if ( dwLen <= 0 ) { dwLen = GetModuleFileName( g_hInst, m_szIniDir, sizeof(m_szIniDir)-1 ); if ( dwLen > 0 ) { TCHAR* pszTitle = GetFileTitlePtr(m_szIniDir); ASSERT(pszTitle); *pszTitle = '\0'; } } if ( ! FILE_IsDirSep( m_szIniDir[dwLen-1] )) { m_szIniDir[dwLen++] = '\\'; m_szIniDir[dwLen] = '\0'; } // read optional configuration file. global init. m_dwConfigChangeCount = 0; // changed when the Custom stuff in m_Config changes. // ASSUME InitMasterWnd will be called shortly. return true; }
HRESULT CreateDirectoryX( const TCHAR* pszDir ) { // This is like CreateDirectory() except. // This will create intermediate directories if needed. // NOTE: like SHCreateDirectoryExA() but we cant use since thats only for Win2K+ ASSERT(pszDir); TCHAR szTmp[ _MAX_PATH ]; int iLen = 0; for (;;) { int iStart = iLen; TCHAR ch; for (;;) { if ( iLen >= COUNTOF(szTmp)-1 ) return HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); ch = pszDir[iLen]; szTmp[iLen] = ch; if ( ch == '\0' ) break; iLen++; if ( FILE_IsDirSep( ch )) break; } if ( iStart >= iLen ) { if ( ch == '\0' ) break; return HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME); // bad name! } szTmp[iLen] = '\0'; if ( ! CreateDirectory( szTmp, NULL )) { DWORD dwLastError = ::GetLastError(); if ( dwLastError == ERROR_ALREADY_EXISTS ) continue; if ( dwLastError == ERROR_ACCESS_DENIED && iStart==0 ) // create a drive? 'c:\' type thing. continue; return HRESULT_FROM_WIN32(dwLastError); } } return S_OK; }
HRESULT CTaksiConfigData::FixCaptureDir() { // RETURN: // <0 = bad name. // S_FALSE = no change. // S_OK = changed! int iLen = lstrlen(m_szCaptureDir); if (iLen<=0) { // If capture directory is still unknown at this point // set it to the current APP directory then. if ( ::GetModuleFileName(NULL,m_szCaptureDir, sizeof(m_szCaptureDir)-1 ) <= 0 ) { return HRes_GetLastErrorDef( HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)); } // strip off file name TCHAR* pTitle = GetFileTitlePtr(m_szCaptureDir); if(pTitle==NULL) return HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND); *pTitle = '\0'; return S_OK; // changed } // make sure it ends with backslash. if ( ! FILE_IsDirSep( m_szCaptureDir[iLen-1] )) { lstrcat(m_szCaptureDir, _T("\\")); return S_OK; // changed } // make sure it actually exists! try to create it if not. HRESULT hRes = CreateDirectoryX( m_szCaptureDir ); if ( FAILED(hRes)) { return hRes; } return S_FALSE; // no change. }