void DirectoryListingClient::receive(void* object, Message* msg) { ServiceStub::receive(object, msg); if (msg->getMeta().find("operation") != msg->getMeta().end()) { ScopeLock lock(_mutex); string op = msg->getMeta("operation"); DirectoryEntry* dirEntry = new DirectoryEntry(*(DirectoryEntry*)object); string key = dirEntry->path() + ":" + dirEntry->name(); if (op.compare("added") == 0) { if (_knownEntries.find(key) == _knownEntries.end()) _knownEntries[key] = shared_ptr<DirectoryEntry>(dirEntry); if (_listener != NULL) _listener->added(_knownEntries[key]); } else if (op.compare("modified") == 0) { if (_knownEntries.find(key) != _knownEntries.end()) { if (_listener != NULL) _listener->changed(_knownEntries[key]); } else { UM_LOG_ERR("Unknown directory entry reported as modified"); } } else if (op.compare("removed") == 0) { if (_knownEntries.find(key) != _knownEntries.end()) { if (_listener != NULL) _listener->removed(_knownEntries[key]); } else { UM_LOG_ERR("Unknown directory entry reported as removed"); } } } }
EncodedJSValue JSC_HOST_CALL jsDirectoryEntryPrototypeFunctionRemoveRecursively(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSDirectoryEntry::s_info)) return throwVMTypeError(exec); JSDirectoryEntry* castedThis = static_cast<JSDirectoryEntry*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDirectoryEntry::s_info); DirectoryEntry* imp = static_cast<DirectoryEntry*>(castedThis->impl()); RefPtr<VoidCallback> successCallback; if (exec->argumentCount() > 0 && !exec->argument(0).isNull() && !exec->argument(0).isUndefined()) { if (!exec->argument(0).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); return JSValue::encode(jsUndefined()); } successCallback = JSCustomVoidCallback::create(asObject(exec->argument(0)), castedThis->globalObject()); } RefPtr<ErrorCallback> errorCallback; if (exec->argumentCount() > 1 && !exec->argument(1).isNull() && !exec->argument(1).isUndefined()) { if (!exec->argument(1).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); return JSValue::encode(jsUndefined()); } errorCallback = JSErrorCallback::create(asObject(exec->argument(1)), castedThis->globalObject()); } imp->removeRecursively(successCallback, errorCallback); return JSValue::encode(jsUndefined()); }
FileEntry* FileStorage::FindOrCreateFileEntry(const StringRef& path, DirectoryEntry* parent /*= nullptr*/) { if (parent == nullptr) { parent = &mRootDir; } FileEntry* fileEntry = nullptr; if (Path::IsPath(path)) { List<HeapString> paths; RETURN_NULL_IF_FALSE(Path::Split(path, paths)); DirectoryEntry* dir = parent; for (uint i = 0; i < paths.Count() - 1; ++i) { dir = dir->FindOrCreateDirectoryEntry(paths[i]); RETURN_NULL_IF_NULL(dir); } fileEntry = dir->FindOrCreateFileEntry(paths.Last()); } else { fileEntry = parent->FindOrCreateFileEntry(path); } return fileEntry; }
void StreamDialog::parseAvailableServices(QStringList directory) { DirectoryEntry de; QString servicePath; QString streamName; QString streamSource; for (int i = 0; i < directory.count(); i++) { de.setLine(directory.at(i)); if (!de.isValid()) continue; QStringList services = de.multicastServices(); for (int i = 0; i < services.count(); i++) { servicePath = de.appName() + SYNTRO_SERVICEPATH_SEP + services.at(i); SyntroUtils::removeStreamNameFromPath(servicePath, streamSource, streamName); if (m_currentStreams.contains(streamSource)) continue; if (streamName == SYNTRO_STREAMNAME_AVMUX) m_availableStreams.append(streamSource); } } }
ErrorOr<Entry *> VFSFromYAML::lookupPath(sys::path::const_iterator Start, sys::path::const_iterator End, Entry *From) { if (Start->equals(".")) ++Start; // FIXME: handle .. if (CaseSensitive ? !Start->equals(From->getName()) : !Start->equals_lower(From->getName())) // failure to match return error_code(errc::no_such_file_or_directory, system_category()); ++Start; if (Start == End) { // Match! return From; } DirectoryEntry *DE = dyn_cast<DirectoryEntry>(From); if (!DE) return error_code(errc::not_a_directory, system_category()); for (DirectoryEntry::iterator I = DE->contents_begin(), E = DE->contents_end(); I != E; ++I) { ErrorOr<Entry *> Result = lookupPath(Start, End, *I); if (Result || Result.getError() != errc::no_such_file_or_directory) return Result; } return error_code(errc::no_such_file_or_directory, system_category()); }
int BrepHandler::extractLine(const Pointer& ptr) { DirectoryEntry* de = _iges->getDirectoryEntry(ptr); ParameterData params; _iges->getParameter(de->paramData(), params); return extractLine(de, params); }
WORD RsfsFormatter::getFileIndexSize(const DirectoryEntry& rootDir) { const std::vector<DirectoryEntry>& dirs = rootDir.getDirectories(); WORD wDataRegionOffset = rootDir.getFiles().size() * RSFS_FILEENTRY_SIZE + dirs.size() * RSFS_DIRECTORYENTRY_SIZE; for(std::vector<DirectoryEntry>::const_iterator it = dirs.begin(); it != dirs.end(); it++) wDataRegionOffset += getFileIndexSize(*it); return wDataRegionOffset; }
int LafsFlat::getDirectoryEntryCount(const DirectoryEntry& dir) { int iEntryCount = 2; //2 for root entry 1 (root directory) + 1 (jump directory) std::vector<DirectoryEntry> it = dir.getDirectories(); for(std::vector<DirectoryEntry>::const_iterator it = dir.getDirectories().begin(); it != dir.getDirectories().end(); it++) iEntryCount += getDirectoryEntryCount(*it); return iEntryCount; }
EncodedJSValue JSC_HOST_CALL jsDirectoryEntryPrototypeFunctionCreateReader(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSDirectoryEntry::s_info)) return throwVMTypeError(exec); JSDirectoryEntry* castedThis = static_cast<JSDirectoryEntry*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDirectoryEntry::s_info); DirectoryEntry* imp = static_cast<DirectoryEntry*>(castedThis->impl()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->createReader())); return JSValue::encode(result); }
/*! * \brief Enqueue a work descriptor in the readyQueue of the passed thread * \param thread pointer to the thread to which readyQueue the task must be appended * \param wd a reference to the work descriptor to be enqueued * \sa ThreadData, WD and BaseThread */ virtual void queue ( BaseThread *thread, WD &wd ) { ThreadData &data = ( ThreadData & ) *thread->getTeamData()->getScheduleData(); if ( !data._init ) { data._cacheId = thread->runningOn()->getMemorySpaceId(); data._init = true; } TeamData &tdata = (TeamData &) *thread->getTeam()->getScheduleData(); if ( wd.isTied() ) { unsigned int index = wd.isTiedTo()->runningOn()->getMemorySpaceId(); tdata._readyQueues[index].push_front ( &wd ); return; } if ( wd.getNumCopies() > 0 ){ unsigned int numCaches = sys.getCacheMap().getSize(); unsigned int ranks[numCaches]; for (unsigned int i = 0; i < numCaches; i++ ) { ranks[i] = 0; } CopyData * copies = wd.getCopies(); for ( unsigned int i = 0; i < wd.getNumCopies(); i++ ) { if ( !copies[i].isPrivate() ) { WorkDescriptor* parent = wd.getParent(); if ( parent != NULL ) { Directory *dir = parent->getDirectory(); if ( dir != NULL ) { DirectoryEntry *de = dir->findEntry(copies[i].getAddress()); if ( de != NULL ) { for ( unsigned int j = 0; j < numCaches; j++ ) { ranks[j]+=((unsigned int)(de->getAccess( j+1 ) > 0))*copies[i].getSize(); } } } } } } unsigned int winner = 0; unsigned int maxRank = 0; for ( unsigned int i = 0; i < numCaches; i++ ) { if ( ranks[i] > maxRank ) { winner = i+1; maxRank = ranks[i]; } } tdata._readyQueues[winner].push_front( &wd ); } else { tdata._readyQueues[0].push_front ( &wd ); } }
bool FileStorage::RemoveAllFiles(DirectoryEntry& parent) { #ifdef MEDUSA_SAFE_CHECK if (parent.Storage() != this) { Log::AssertFailed("Invalid operate on different storage."); return false; } #endif auto filesCopy = parent.Files(); for (auto file : filesCopy) { RETURN_FALSE_IF_FALSE(RemoveFile(file)); } return true; }
int DirectoryEntryManager::findEntryByNameAndNumber(const QString &name, const QString &number) const { for (int i = 0; i < m_directory_entries.size(); i++) { DirectoryEntry *entry = m_directory_entries[i]; if (! entry) { continue; } if (entry->name().isEmpty()) { continue; } if (entry->name() == name && entry->number() == number) { return i; } } return -1; }
bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure) { if (m_GamePlugin->loadOrderMechanism() != IPluginGame::LoadOrderMechanism::FileTime) { // nothing to do return true; } qDebug("setting file times on esps"); for (ESPInfo &esp : m_ESPs) { std::wstring espName = ToWString(esp.m_Name); const FileEntry::Ptr fileEntry = directoryStructure.findFile(espName); if (fileEntry.get() != nullptr) { QString fileName; bool archive = false; int originid = fileEntry->getOrigin(archive); fileName = QString("%1\\%2").arg(QDir::toNativeSeparators(ToQString(directoryStructure.getOriginByID(originid).getPath()))).arg(esp.m_Name); HANDLE file = ::CreateFile(ToWString(fileName).c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (file == INVALID_HANDLE_VALUE) { if (::GetLastError() == ERROR_SHARING_VIOLATION) { // file is locked, probably the game is running return false; } else { throw windows_error(QObject::tr("failed to access %1").arg(fileName).toUtf8().constData()); } } ULONGLONG temp = 0; temp = (145731ULL + esp.m_Priority) * 24 * 60 * 60 * 10000000ULL; FILETIME newWriteTime; newWriteTime.dwLowDateTime = (DWORD)(temp & 0xFFFFFFFF); newWriteTime.dwHighDateTime = (DWORD)(temp >> 32); esp.m_Time = newWriteTime; fileEntry->setFileTime(newWriteTime); if (!::SetFileTime(file, nullptr, nullptr, &newWriteTime)) { throw windows_error(QObject::tr("failed to set file time %1").arg(fileName).toUtf8().constData()); } CloseHandle(file); } }
JSValue JSDirectoryEntry::getDirectory(ExecState* exec) { DirectoryEntry* imp = static_cast<DirectoryEntry*>(impl()); const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); if (exec->hadException()) return jsUndefined(); int argsCount = exec->argumentCount(); if (argsCount <= 1) { imp->getDirectory(path); return jsUndefined(); } RefPtr<Flags> flags; if (!exec->argument(1).isNull() && !exec->argument(1).isUndefined() && exec->argument(1).isObject() && !exec->argument(1).inherits(&JSFlags::s_info)) { JSObject* object = exec->argument(1).getObject(); flags = Flags::create(); JSValue jsCreate = object->get(exec, Identifier(exec, "create")); flags->setCreate(jsCreate.toBoolean(exec)); JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive")); flags->setExclusive(jsExclusive.toBoolean(exec)); } else flags = toFlags(exec->argument(1)); if (exec->hadException()) return jsUndefined(); RefPtr<EntryCallback> successCallback; if (exec->argumentCount() > 2 && !exec->argument(2).isNull() && !exec->argument(2).isUndefined()) { if (!exec->argument(2).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } successCallback = JSEntryCallback::create(asObject(exec->argument(2)), globalObject()); } RefPtr<ErrorCallback> errorCallback; if (exec->argumentCount() > 3 && !exec->argument(3).isNull() && !exec->argument(3).isUndefined()) { if (!exec->argument(3).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } errorCallback = JSErrorCallback::create(asObject(exec->argument(3)), globalObject()); } imp->getDirectory(path, flags, successCallback, errorCallback); return jsUndefined(); }
void stk500SaveFiles::run() { if (this->sourceFile.endsWith('/')) { // Saving a full directory // First navigate to this directory QString dirPath = this->sourceFile; dirPath.remove(dirPath.length() - 1, 1); QString destDirPath = this->destFile; if (destDirPath.endsWith('/')) { destDirPath.remove(destDirPath.length() - 1, 1); } DirectoryEntryPtr dirStartPtr; if (dirPath.isEmpty()) { dirStartPtr = protocol->sd().getRootPtr(); } else { DirectoryEntryPtr dirEntryPtr = sd_findEntry(dirPath, true, false); if (isCancelled()) { return; } if (!dirEntryPtr.isValid()) { // Should not happen, but just in case... throw ProtocolException("Folder not found"); } DirectoryEntry folderEntry = protocol->sd().readDirectory(dirEntryPtr); if (folderEntry.firstCluster()) { dirStartPtr = protocol->sd().getDirPtrFromCluster(folderEntry.firstCluster()); } else { dirStartPtr = DirectoryEntryPtr(0, 0); } } saveFolder(dirStartPtr, dirPath, destDirPath, 0.0, 1.0); } else { // Saving a single file DirectoryEntryPtr filePtr = sd_findEntry(this->sourceFile, false, false); if (isCancelled()) { return; } if (!filePtr.isValid()) { throw ProtocolException("File not found"); } DirectoryEntry fileEntry = protocol->sd().readDirectory(filePtr); saveFile(fileEntry, this->sourceFile, this->destFile, 0.0, 1.0); } }
ErrorOr<Status> VFSFromYAML::status(const Twine &Path) { ErrorOr<Entry *> Result = lookupPath(Path); if (!Result) return Result.getError(); std::string PathStr(Path.str()); if (FileEntry *F = dyn_cast<FileEntry>(*Result)) { ErrorOr<Status> S = ExternalFS->status(F->getExternalContentsPath()); assert(!S || S->getName() == F->getExternalContentsPath()); if (S && !F->useExternalName(UseExternalNames)) S->setName(PathStr); return S; } else { // directory DirectoryEntry *DE = cast<DirectoryEntry>(*Result); Status S = DE->getStatus(); S.setName(PathStr); return S; } }
DirectoryListingReply* DirectoryListingService::list(DirectoryListingRequest* req) { updateEntries(); DirectoryListingReply* reply = new DirectoryListingReply(); map<string, struct stat>::iterator statIter = _knownEntries.begin(); Regex regex(req->pattern()); if (regex.hasError()) return reply; while(statIter != _knownEntries.end()) { DirectoryEntry* dOrig = statToEntry(statIter->first, statIter->second); if (regex.matches(statIter->first)) { DirectoryEntry* dEntry = reply->add_entries(); dEntry->CopyFrom(*dOrig); delete dOrig; } statIter++; } return reply; }
bool LafsFlat::startDirectory(const DirectoryEntry& dir) { WORD wEntryBuffer = 0x8000; //First bit is set for a directory //Two entries per directory start of directory if(2 + dir.getSize() >= getFreeEntries()) return false; m_lafsEntries.push_back(LafsEntry(wEntryBuffer, dir)); m_lafsEntries.push_back(LafsEntry(wEntryBuffer, dir, true)); return true; }
void RsfsFormatter::create(std::ostream& out, const DirectoryEntry& rootDir) { std::stringstream ssFileIndexBuffer; std::stringstream ssFileRawBuffer; WORD wDataRegionOffset = getFileIndexSize(rootDir) + RSFS_HEADER_SIZE; writeDirectory(rootDir, wDataRegionOffset, ssFileIndexBuffer, ssFileRawBuffer); //Write out header out.put(1); out.put(0); WORD numRootEntries = rootDir.getDirectories().size() + rootDir.getFiles().size(); out.write(reinterpret_cast<char*>(&numRootEntries), sizeof(WORD)); //write file directories for(unsigned char b = ssFileIndexBuffer.get(); !ssFileIndexBuffer.eof(); b = ssFileIndexBuffer.get()) out.put(b); for(unsigned char b = ssFileRawBuffer.get(); !ssFileRawBuffer.eof(); b = ssFileRawBuffer.get()) out.put(b); }
bool LafsFlat::addJumpDirectory(const DirectoryEntry& dir, const int iNextFlat) { WORD wEntryBuffer = 0x8000; //First bit is set for a directory //Two entries per directory start of directory if(m_lafsEntries.size() + 2 + dir.getSize() > LAFS_ENTRIES_PER_FLAT) return false; m_lafsEntries.push_back(LafsEntry(wEntryBuffer, dir)); m_lafsEntries.push_back(LafsEntry(wEntryBuffer, dir, iNextFlat, true)); return true; }
inline void CachePolicy::registerCacheAccess( Directory& dir, uint64_t tag, size_t size, bool input, bool output ) { bool didCopyIn = false; CacheEntry *ce; ce = _cache.getEntry( tag ); unsigned int version=0; if ( ce != NULL ) version = ce->getVersion()+1; DirectoryEntry *de = dir.getEntry( tag, version ); if ( de == NULL ) { // Memory access not registered in the directory bool inserted; DirectoryEntry d = DirectoryEntry( tag, 0, ( output ? &_cache : NULL ), dir.getCacheMapSize() ); de = &(dir.insert( tag, d, inserted )); if (!inserted) { if ( output ) { de->setOwner(&_cache); de->setInvalidated(false); ce->setFlushTo( &dir ); } } CacheEntry c = CacheEntry( NULL, size, tag, 0, output, input ); ce = &(_cache.insert( tag, c, inserted )); if (inserted) { // allocate it ce->setAddress( _cache.allocate( dir, size , tag) ); ce->setAllocSize( size ); if (input) { CopyDescriptor cd = CopyDescriptor(tag); if ( _cache.copyDataToCache( cd, size ) ) { ce->setCopying(false); } } } else { // wait for address NANOS_INSTRUMENT( sys.getInstrumentation()->raiseOpenBurstEvent ( sys.getInstrumentation()->getInstrumentationDictionary()->getEventKey( "cache-wait" ), NANOS_CACHE_EVENT_REGISTER_CACHE_ACCESS_94 ); ) while ( ce->getAddress() == NULL ) {} NANOS_INSTRUMENT( sys.getInstrumentation()->raiseCloseBurstEvent ( sys.getInstrumentation()->getInstrumentationDictionary()->getEventKey( "cache-wait" ), 0 ); ) }
char *SyntroPythonClient::lookupSources(const char *sourceName, int serviceType) { DirectoryEntry de; QString servicePath; QString streamName; QString streamSource; static char availableSources[SYNTRO_MAX_DELENGTH]; QStringList services; QMutexLocker lock(&m_lock); availableSources[0] = 0; for (int i = 0; i < m_directory.count(); i++) { de.setLine(m_directory.at(i)); if (!de.isValid()) continue; if (serviceType == SERVICETYPE_MULTICAST) services = de.multicastServices(); else services = de.e2eServices(); for (int i = 0; i < services.count(); i++) { servicePath = de.appName() + SYNTRO_SERVICEPATH_SEP + services.at(i); SyntroUtils::removeStreamNameFromPath(servicePath, streamSource, streamName); if (streamName == sourceName) { strcat(availableSources, qPrintable(streamSource)); strcat(availableSources, "\n"); } } } return availableSources; }
void RsfsFormatter::writeDirectory(const DirectoryEntry& dir, const WORD wDataRegionOffset, std::ostream& fileIndexBuffer, std::ostream& fileRawDataBuffer) { char fileReadBuffer[100]; const std::vector<DirectoryEntry>& dirs = dir.getDirectories(); const std::vector<FileEntry>& files = dir.getFiles(); WORD wBuffer = 0; if(dir.getName().length() > 0) { wBuffer = RSFS_ENTRYTYPE_DIRECTORY; fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD)); fileIndexBuffer.write(dir.getName().c_str(), dir.getName().length()); for(unsigned int i = RSFS_NAME_SIZE - dir.getName().length(); i > 0; i--) fileIndexBuffer.put(0); if(dir.getDirectories().size() > 0xFFFF) throw FormattingException("The number of sub-directories exceeds the max permittable number of sub-directories."); wBuffer = static_cast<WORD>(dir.getDirectories().size() + dir.getFiles().size()); fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD)); fileIndexBuffer.put(0); fileIndexBuffer.put(0); } for(std::vector<FileEntry>::const_iterator it = files.begin(); it != files.end(); it++) { if(it->getName().length() >= RSFS_NAME_SIZE) { throw new FormattingException(std::string("Skipped due to file name exceeding max length: ") + it->getName()); continue; } wBuffer = RSFS_ENTRYTYPE_FILE; fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD)); fileIndexBuffer.write(it->getName().c_str(), it->getName().length()); //Padd the file name with nulls. for(unsigned int i = RSFS_NAME_SIZE - it->getName().length(); i > 0; i--) fileIndexBuffer.put(0); if(it->getSize() > 0xFFFF) throw FormattingException("Size of file exceeded permitable size."); wBuffer = static_cast<WORD>(it->getSize()); fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD)); //Make sure data is aligned in words std::streamoff offset = 0; for(offset = wDataRegionOffset + fileRawDataBuffer.tellp(); offset % 2; offset++) fileRawDataBuffer.put(0); if(offset + it->getSize() > 0xFFFF) throw FormattingException("Size of medium exceeded permitable size."); WORD wFileDataOffset = static_cast<WORD>(offset) / 2; //Offset in terms of words. fileIndexBuffer.write(reinterpret_cast<char*>(&wFileDataOffset), sizeof(WORD)); //Write our file's data to the fileRawBuffer. std::ifstream inFile(it->getSourceFile(), std::ifstream::binary | std::ifstream::in); if(!inFile.good()) throw FormattingException(std::string("Error reading from source file") + it->getName()); while(!inFile.eof()) { inFile.read(fileReadBuffer, sizeof(fileReadBuffer)); fileRawDataBuffer.write(fileReadBuffer, inFile.gcount()); } } for(std::vector<DirectoryEntry>::const_iterator it = dirs.begin(); it != dirs.end(); it++) writeDirectory(*it, wDataRegionOffset, fileIndexBuffer, fileRawDataBuffer); }
void stk500SaveFiles::saveFile(DirectoryEntry fileEntry, QString sourceFilePath, QString destFilePath, double progStart, double progTotal) { /* Ensure that the parent directory exists */ QString destFolderPath = destFilePath; int destFolderIdx = destFolderPath.lastIndexOf('/'); if (destFolderIdx != -1) { destFolderPath.remove(destFolderIdx, destFolderPath.length() - destFolderIdx); } QDir dir = QDir::root(); dir.mkpath(destFolderPath); /* Open the file for writing */ QFile destFile(destFilePath); if (!destFile.open(QIODevice::WriteOnly)) { throw ProtocolException("Failed to open file for writing"); } /* Proceed to read in data */ quint32 cluster = fileEntry.firstCluster(); if (cluster) { char buff[512]; quint32 remaining = fileEntry.fileSize; quint32 done = 0; qint64 startTime = QDateTime::currentMSecsSinceEpoch(); qint64 time = startTime; qint64 timeElapsed = 0; while (remaining > 0) { quint32 block = protocol->sd().getClusterBlock(cluster); for (int i = 0; i < protocol->sd().volume().blocksPerCluster; i++) { protocol->sd().read(block + i, 0, buff, 512); /* If cancelled, stop reading/writing by setting remaining to 0 */ if (isCancelled()) { remaining = 0; } time = QDateTime::currentMSecsSinceEpoch(); timeElapsed = (time - startTime) / 1000; done = (fileEntry.fileSize - remaining); int speed_ps; if (timeElapsed == 0 || done == 0) { speed_ps = 6000; } else { speed_ps = done / timeElapsed; } /* Update progress */ setProgress(progStart + progTotal * ((double) done / (double) fileEntry.fileSize)); /* Update the status info */ QString newStatus; newStatus.append("Reading ").append(sourceFilePath).append(": "); newStatus.append(stk500::getSizeText(remaining)).append(" remaining ("); newStatus.append(stk500::getSizeText(speed_ps)).append("/s)\n"); newStatus.append("Elapsed: ").append(stk500::getTimeText(timeElapsed)); newStatus.append(", estimated ").append(stk500::getTimeText(remaining / speed_ps)); newStatus.append(" remaining"); setStatus(newStatus); /* Write the 512 or less bytes of buffered data to the file */ if (remaining < 512) { destFile.write(buff, remaining); remaining = 0; break; } else { destFile.write(buff, 512); remaining -= 512; } } // Next cluster, if end of chain no more clusters follow cluster = protocol->sd().fatGet(cluster); if (protocol->sd().isEOC(cluster)) { break; } } } // If errors occur the deconstructor closes it as well... destFile.close(); // If cancelled, delete the file again (awh...) if (isCancelled()) { destFile.remove(); } }
template <class T> void DAT::AddInDirectory(std::vector<TriageFile> Triage,const unsigned int profondeur,FILE* DatFile,const char* name,T me) //ajouter dans un nouveau dossier { for (unsigned int i=0;i< profondeur;++i) cout<<'\t'; cout<<"Ajout du répertoir :"<<name<<endl; /// Triage est un vecteur contenant les chemin des fichier à inclure qui sont obligatoirement dans le repertoire qui les traite fseek(DatFile,0,SEEK_END); const long int SeekCurrentDir=ftell(DatFile);//on enregistre la position du curseur dans le fichier où est mise la structure du dossier fwrite((char*)&me,1,sizeof(T),DatFile);//on met le dossier courant dans le fichier CurrentOffset=ftell(DatFile); //adresse acctuelle dans la mémoire unsigned int _size=Triage.size(); vector<unsigned int> index; bool sous_dossier=false; for(unsigned int i=0;i<_size && !sous_dossier;++i) //pour tous les fichiers on cherche ceux à ajouter if(Triage[i].Path.size()==profondeur)//si c'est un fichier à ajouter { if (me.Nb<NOMBRE_OF_FILE) { me.Nb++; index.push_back(i); } else sous_dossier=true; } ///on a donc tous les fichiers à ajouter, et si nesésaire, dans un dossier de suite _size=0; //difference dans index for (unsigned int i=0;i<me.Nb;++i) //pour tous les fichier à ajouter { //on va chercher le fichier int id=index[i]-_size; if(EcrireFichier(DatFile,&me,i,id,&Triage)) //on ecrit le fichier ++_size; else exit(0); } ResetMe(DatFile,&me,SeekCurrentDir); //on reecrit les info sur le dossier if (sous_dossier)//si sous_dossier, envoyer le vecteur. DeleguerDossier(Triage,profondeur,DatFile,name,&me,SeekCurrentDir); else if (Triage.size()>0)//on à écrit tous les fichiers, on passe aux sous dossiers //sinon découper le vecteur par sousdossier et appeler la fonction pour chaqu'un des dossiers { //si il y à des fichiers/dossier à mettre string name_next=Triage[0].Path[profondeur]; //nom du prochain vector<TriageFile> Triage_next; //fichier du prochain sous_dossier=(me.Nb>=NOMBRE_OF_FILE); int meNb=me.Nb; while(Triage.size()>0 && !sous_dossier) //tant qu'on a pas distribué tous les fichiers/dossiers { bool ok=true; for(unsigned int i=0;i<Triage.size() && ok;++i) { if(Triage[i].Path[profondeur]==name_next) //on prend tous les fichier qui seront dans le prochain dossier { Triage_next.push_back(Triage[i]); Triage.erase(Triage.begin()+i); --i; } else ok=false; } fseek(DatFile,0,SEEK_END); CurrentOffset=ftell(DatFile); me.FilesEntry[meNb]=CurrentOffset; sous_dossier=((++meNb)>=NOMBRE_OF_FILE); DirectoryEntry NextDir;//prochain repertoir NextDir.setName((char*)name_next.c_str()); AddInDirectory(Triage_next,profondeur+1,DatFile,name_next.c_str(),NextDir); Triage_next.clear(); if (Triage.size()>0) name_next=Triage[0].Path[profondeur]; } me.Nb=meNb; ResetMe(DatFile,&me,SeekCurrentDir); //on reecrit les info sur le dossier if (sous_dossier) DeleguerDossier(Triage,profondeur,DatFile,name,&me,SeekCurrentDir); } fseek(DatFile,0,SEEK_END); };
PSpaceCurve(IGES* _iges, BrepHandler* _brep, Logical& iso, Pointer& c) { DirectoryEntry* curveDE = _iges->getDirectoryEntry(c); ParameterData param; _iges->getParameter(curveDE->paramData(), param); }
void PluginList::refresh(const QString &profileName , const DirectoryEntry &baseDirectory , const QString &pluginsFile , const QString &loadOrderFile , const QString &lockedOrderFile) { ChangeBracket<PluginList> layoutChange(this); m_ESPsByName.clear(); m_ESPsByPriority.clear(); m_ESPs.clear(); QStringList primaryPlugins = m_GamePlugin->primaryPlugins(); m_CurrentProfile = profileName; std::vector<FileEntry::Ptr> files = baseDirectory.getFiles(); for (auto iter = files.begin(); iter != files.end(); ++iter) { FileEntry::Ptr current = *iter; if (current.get() == nullptr) { continue; } QString filename = ToQString(current->getName()); QString extension = filename.right(3).toLower(); if ((extension == "esp") || (extension == "esm")) { bool forceEnabled = Settings::instance().forceEnableCoreFiles() && std::find(primaryPlugins.begin(), primaryPlugins.end(), filename.toLower()) != primaryPlugins.end(); bool archive = false; try { FilesOrigin &origin = baseDirectory.getOriginByID(current->getOrigin(archive)); QString iniPath = QFileInfo(filename).baseName() + ".ini"; bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; QString originName = ToQString(origin.getName()); unsigned int modIndex = ModInfo::getIndex(originName); if (modIndex != UINT_MAX) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); originName = modInfo->name(); } m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, ToQString(current->getFullPath()), hasIni)); } catch (const std::exception &e) { reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3").arg(filename).arg(current->getOrigin(archive)).arg(e.what())); } } } if (readLoadOrder(loadOrderFile)) { int maxPriority = 0; // assign known load orders for (std::vector<ESPInfo>::iterator espIter = m_ESPs.begin(); espIter != m_ESPs.end(); ++espIter) { std::map<QString, int>::const_iterator priorityIter = m_ESPLoadOrder.find(espIter->m_Name.toLower()); if (priorityIter != m_ESPLoadOrder.end()) { if (priorityIter->second > maxPriority) { maxPriority = priorityIter->second; } espIter->m_Priority = priorityIter->second; } else { espIter->m_Priority = -1; } } ++maxPriority; // assign maximum priorities for plugins with unknown priority for (std::vector<ESPInfo>::iterator espIter = m_ESPs.begin(); espIter != m_ESPs.end(); ++espIter) { if (espIter->m_Priority == -1) { espIter->m_Priority = maxPriority++; } } } else { // no load order stored, determine by date std::sort(m_ESPs.begin(), m_ESPs.end(), ByDate); for (size_t i = 0; i < m_ESPs.size(); ++i) { m_ESPs[i].m_Priority = i; } } std::sort(m_ESPs.begin(), m_ESPs.end(), ByPriority); // first, sort by priority // remove gaps from the priorities so we can use them as array indices without overflow for (int i = 0; i < static_cast<int>(m_ESPs.size()); ++i) { m_ESPs[i].m_Priority = i; } std::sort(m_ESPs.begin(), m_ESPs.end(), ByName); // sort by name so alphabetical sorting works updateIndices(); readEnabledFrom(pluginsFile); readLockedOrderFrom(lockedOrderFile); layoutChange.finish(); refreshLoadOrder(); emit dataChanged(this->index(0, 0), this->index(m_ESPs.size(), columnCount())); m_Refreshed(); }