bool AddFile( M_OutputFile& files, const std::string& fileName, Stream stream, ThreadId threadId, bool append ) { Helium::MutexScopeLock mutex (g_Mutex); M_OutputFile::iterator found = files.find( fileName ); if ( found != files.end() ) { if ( found->second.m_StreamType != stream ) { HELIUM_BREAK(); // trying to add the same file, but with a different stream type } if ( found->second.m_ThreadId != threadId ) { HELIUM_BREAK(); // trying to add the same file with a different thread id } found->second.m_RefCount++; // another reference } else { if (fileName != TXT( "" )) { File* f = new File; if ( f->Open( fileName.c_str(), FileModes::Write ) ) { if ( append ) { f->Seek( 0, SeekOrigins::End ); } g_FileManager.Opened( fileName, f ); OutputFile info; info.m_StreamType = stream; info.m_RefCount = 1; info.m_ThreadId = threadId; files[ fileName ] = info; return true; } else { delete f; f = NULL; } } } return false; }
void RemoveFile( M_OutputFile& files, const tstring& fileName ) { Helium::MutexScopeLock mutex (g_Mutex); M_OutputFile::iterator found = files.find( fileName ); if ( found != files.end() ) { found->second.m_RefCount--; if ( found->second.m_RefCount == 0 ) { g_FileManager.Close( fileName ); files.erase( found ); } } }
bool AddFile( M_OutputFile& files, const tstring& fileName, Stream stream, uint32_t threadId, bool append ) { Helium::MutexScopeLock mutex (g_Mutex); M_OutputFile::iterator found = files.find( fileName ); if ( found != files.end() ) { if ( found->second.m_StreamType != stream ) { HELIUM_BREAK(); // trying to add the same file, but with a different stream type } if ( found->second.m_ThreadId != threadId ) { HELIUM_BREAK(); // trying to add the same file with a different thread id } found->second.m_RefCount++; // another reference } else { FILE* f = NULL; if (fileName != TXT( "" )) { tchar_t *mode = append ? TXT( "at+" ) : TXT( "wt+" ); f = _tfopen( fileName.c_str(), mode ); } if ( f ) { g_FileManager.Opened( fileName, f ); OutputFile info; info.m_StreamType = stream; info.m_RefCount = 1; info.m_ThreadId = threadId; files[ fileName ] = info; return true; } } return false; }