FileList& DirectoryInfo::getFiles(const char* _cmd,bool refresh) { if ( m_exist && (subFiles.size() == 0 || refresh)) { subFiles.clear(); std::string cmd(_cmd); std::string start_pos = fullname + "\\" + cmd; HANDLE hFind; WIN32_FIND_DATAA find_data = {0}; hFind = FindFirstFileA(start_pos.c_str(), &find_data); if (hFind != INVALID_HANDLE_VALUE) { if(!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) subFiles.push_back(FilePtr(createFileInfo(*this,find_data))); while (FindNextFileA(hFind, &find_data) != 0) { if(!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) subFiles.push_back(FilePtr(createFileInfo(*this,find_data))); } FindClose(hFind); } } return subFiles; }
FilePtr CFileManager::_CreateFile(const SFileCreateDesc& Desc) { CFile* pFile = nullptr; Threads::ScopedLock l( m_SyncObj ); hash_t hash = CFile::CalcHash( Desc.File ); FileBuffer::MapIterator Itr; if( !m_FileBuffer.Get( hash, &pFile, &Itr ) ) { if( VKE_SUCCEEDED( Memory::CreateObject( &m_FileAllocator, &pFile, this ) ) ) { if( !m_FileBuffer.Add( pFile, hash, Itr ) ) { VKE_LOG_ERR( "Unable to allocate memory for CFile object." ); } } else { VKE_LOG_ERR( "Unable to create memory for CFile object." ); } } if( pFile ) { const uint32_t resState = pFile->GetResourceState(); if( Desc.Create.stages & ResourceStageBits::INIT ) { pFile->Init( Desc.File ); } } return FilePtr( pFile ); }
CDirectory::FilePtr CDirectory::FindFile(xst_castring &strName) { FileMap::iterator Itr = m_mFiles.find( strName ); if( Itr == m_mFiles.end() ) { return FilePtr( xst_null ); } return Itr->second; }
FilePtr Directory::nextFile() { struct dirent *epdf; errno = 0; epdf = readdir(dir_); if (epdf == NULL) { if (errno) { THROW_SYSTEM_ERROR(); } return FilePtr(); } FilePtr file = std::make_shared<File>( std::string(path_ + epdf->d_name).c_str(), epdf->d_name); return file; }
//------------------------------------------------------ void DatabaseService::save(const std::string &filename, uint32_t saveMask) { // just prepare the progress and delegate to the broadcast FilePtr fp = FilePtr(new StdFile(filename, File::FILE_RW)); FileGroupPtr tgtdb = FileGroupPtr(new DarkFileGroup()); LOG_DEBUG("DatabaseService::save - Save to file %s, mask %X", filename.c_str(), saveMask); mLoadingStatus.reset(); mLoadingStatus.totalCoarse += mListeners.size(); broadcastOnDBSave(tgtdb, saveMask); // And write the saveMask as FILE_TYPE FilePtr fpf = tgtdb->createFile( "FILE_TYPE", 0, 1); // The version is fixed, really. Nothing to invent here fpf->writeElem(&saveMask, sizeof(uint32_t)); // And Write! tgtdb->write(fp); }
FilePtr Opener::Open(Path path) { return FilePtr(new (std::nothrow) File(*this, path)); }
bool Log::setLogFile(const std::string& filename) { logFile = FilePtr(fopen(filename.data(), "w")); return logFile != nullptr; }
FileLogger::FilePtr FileLogger::getLog(const std::string &path) { auto logFile = new std::ofstream(); logFile->open(path); return FilePtr(logFile); }