/// <summary> /// <para name='Name'>SLog::openLog</para> /// <para name='Purpose'>Open a log for output</para> /// </summary> /// <param name='szFullPathToLog'>the full path to the log file to open</param> /// <param name='makeUnique'>Whether to append a date/time stamp to the file name</param> /// <returns>S_OK if successful, failure if it failed</returns> /// <remarks> /// <para name='Notes'></para> /// <para name='Author'>Kenn Guilstorf</para> /// <para name='LastModified'>2015-10-26</para> /// </remarks> HRESULT SLog::openLog(TSTRING szFullPathToLog, bool makeUnique) { HRESULT hrRetVal = S_OK; TSTRING szFullLogPath = TSTRING(); // If we're trying to open when a log is already open... // Let's flush and close the main OSTREAM first... if (NULL != m_pO) { m_pO->flush(); delete m_pO; m_pO = NULL; } // Now, close the file stream... if (NULL != m_log) { if (m_log->is_open()) { m_log->flush(); m_log->close(); delete m_log; m_log = NULL; } } // Split the path into path, name and ext hrRetVal = splitFullPath(szFullPathToLog); if (hrRetVal == ERROR_BAD_ARGUMENTS) goto EXIT; // Do we want to add date/time to the file? if (makeUnique) m_szLogFileName->append(getDateTimeString(false)); szFullLogPath.append(m_szLogFilePath->c_str()); szFullLogPath.append(m_szLogFileName->c_str()); szFullLogPath.append(m_szLogFileExt->c_str()); // Enter our critical section EnterCriticalSection(&m_CriticalSection); // Open our file stream m_log = new TOFSTREAM(szFullLogPath.c_str(), TOFSTREAM::app | TOFSTREAM::out); // Open a new output stream m_pO = new TOSTREAM(m_log->rdbuf()); // Leave our critical section LeaveCriticalSection(&m_CriticalSection); EXIT: return hrRetVal; }
STATIC enum cacheRet maybeCache( const char *fullpath, CENTRYPTR *pc ) /********************************************************************/ { char path[_MAX_PATH]; char name[NAME_MAX + 1]; DHEADPTR dcur; CENTRYPTR centry; enum cacheRet ret; assert( fullpath != NULL ); splitFullPath( fullpath, path, name ); FixName( path ); FixName( name ); dcur = findDir( path ); if( dcur == NULL ) { /* must cache new directory */ ret = cacheDir( &dcur, path ); if( ret != CACHE_OK ) { return( ret ); } dcur->dh_next = cacheHead; cacheHead = dcur; } /* now dcur points to Cached directory */ assert( dcur != NULL ); centry = findFile( dcur, name ); if( centry == NULL ) { return( CACHE_FILE_NOT_FOUND ); } if( pc != NULL ) { *pc = centry; } return( CACHE_OK ); }