BrowseModel::BrowseModel(QObject *p) : ActionModel(p) , root(new FolderItem("/", 0)) , enabled(false) , dbVersion(0) { connect(this, SIGNAL(listFolder(QString)), MPDConnection::self(), SLOT(listFolder(QString))); folderIndex.insert(root->getPath(), root); }
void ScanFileOrFolder::run() { stopped=false; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start the listing with destination: "+destination+", mode: "+QString::number(mode)); destination=resolvDestination(destination).absoluteFilePath(); if(stopIt) { stopped=true; return; } if(fileErrorAction==FileError_Skip) { stopped=true; return; } int sourceIndex=0; while(sourceIndex<sources.size()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"size source to list: "+QString::number(sourceIndex)+text_slash+QString::number(sources.size())); if(stopIt) { stopped=true; return; } QFileInfo source=sources.at(sourceIndex); if(source.isDir() && !source.isSymLink()) { /* Bad way; when you copy c:\source\folder into d:\destination, you wait it create the folder d:\destination\folder //listFolder(source.absoluteFilePath()+QDir::separator(),destination); listFolder(source.absoluteFilePath()+text_slash,destination);//put unix separator because it's transformed into that's under windows too */ //put unix separator because it's transformed into that's under windows too QString tempString=QFileInfo(destination).absoluteFilePath(); if(!tempString.endsWith(text_slash) && !tempString.endsWith(text_antislash)) tempString+=text_slash; tempString+=TransferThread::resolvedName(source); if(moveTheWholeFolder && mode==Ultracopier::Move && !QFileInfo(tempString).exists() && driveManagement.isSameDrive(source.absoluteFilePath(),tempString)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("tempString: %1 move and not exists").arg(tempString)); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("do real move: %1 to %2").arg(source.absoluteFilePath()).arg(tempString)); emit addToRealMove(source.absoluteFilePath(),tempString); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("tempString: %1 normal listing, blacklist size: %2").arg(tempString).arg(blackList.size())); listFolder(source.absoluteFilePath(),tempString); } } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1 is file or symblink").arg(source.absoluteFilePath())); emit fileTransfer(source,destination+text_slash+source.fileName(),mode); } sourceIndex++; } stopped=true; if(stopIt) return; emit finishedTheListing(); }
void BrowseModel::load() { if (!enabled || (root && (root->getChildCount() || root->isFetching()))) { return; } root->setState(FolderItem::State_Fetching); emit listFolder(root->getPath()); }
void VListFolderUE::selectParentItem(int p_id) { Q_UNUSED(p_id); if (m_currentFolderPath.isEmpty()) { return; } if (listFolder(VUtils::basePathFromPath(m_currentFolderPath), QString())) { m_folderPath = m_currentFolderPath; } m_listWidget->updateGeometry(); emit widgetUpdated(); }
QStringList listFolder(const QString& folder,const QString& suffix=QString()) { QStringList returnList; QFileInfoList entryList=QDir(folder+suffix).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot,QDir::DirsFirst|QDir::Name);//possible wait time here int sizeEntryList=entryList.size(); for (int index=0;index<sizeEntryList;++index) { QFileInfo fileInfo=entryList.at(index); if(fileInfo.isDir()) returnList+=listFolder(folder,suffix+fileInfo.fileName()+text_slash);//put unix separator because it's transformed into that's under windows too else if(fileInfo.isFile()) returnList+=suffix+fileInfo.fileName(); } return returnList; }
void VListFolderUE::processCommand(int p_id, const QString &p_cmd) { Q_UNUSED(p_id); init(); QString folderPath = m_folderPath; if (folderPath.isEmpty()) { VDirectory *dir = g_mainWin->getDirectoryTree()->currentDirectory(); folderPath = dir->fetchPath(); } listFolder(folderPath, p_cmd); m_listWidget->updateGeometry(); emit widgetUpdated(); emit stateUpdated(State::Success); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList arguments=QCoreApplication::arguments(); if(arguments.size()!=2) { qDebug() << "pass only the file to parse and datapack path to update as arguments"; return 1; } if(!QFile(arguments.last()+"/items/items.xml").exists()) { qDebug() << "missing items/items.xml into the path given"; return 2; } if(!QFile(arguments.last()+"/monsters/skill/skill.xml").exists()) { qDebug() << "missing monsters/skill/skill.xml.xml into the path given"; return 2; } if(!QFile(arguments.last()+"/monsters/monster.xml").exists()) { qDebug() << "missing monsters/monster.xml into the path given"; return 2; } datapackPath=arguments.last()+"/"; QByteArray endOfString; endOfString[0]=0x00; { bool test=false; if(!test) { QString currentPath=QDir::currentPath(); if(!currentPath.endsWith("/") || !currentPath.endsWith("\\")) currentPath+="/"; const QStringList &fileList=listFolder(currentPath); int index=0; while(index<fileList.size()) { if(index%1000==0 && index>0) qDebug() << "Number of file done" << index << "on" << fileList.size(); //filter by generation const QString &filePath=currentPath+fileList.at(index); QFile file(filePath); if(file.open(QIODevice::ReadOnly)) { QByteArray rawData=file.readAll(); rawData.replace(endOfString,QByteArray()); QString data=QString::fromUtf8(rawData); QString fulldata=data; file.close(); data.remove(QRegularExpression("<span[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</span>"); data.remove(QRegularExpression("<a[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</a>"); data.remove(QRegularExpression("<p[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</p>"); data.replace(QRegularExpression("<br />[^>]+[ \r\t\n]*</td>"),"</td>"); loadHtmlTM(data,fulldata);//bool used= //if(!used) // qDebug() << "Not used:" << file.fileName(); } else qDebug() << "Unable to open the file" << filePath; index++; } } else { QFile file(QDir::currentPath()+"/Celebi/Generation_III_learnset.html"); if(file.open(QIODevice::ReadOnly)) { QByteArray rawData=file.readAll(); rawData.replace(endOfString,QByteArray()); QString data=QString::fromUtf8(rawData); QString fulldata=data; file.close(); data.remove(QRegularExpression("<span[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</span>"); data.remove(QRegularExpression("<a[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</a>"); data.remove(QRegularExpression("<p[^>]*>",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)); data.remove("</p>"); data.replace(QRegularExpression("<br />[^>]+[ \r\t\n]*</td>"),"</td>"); bool used=loadHtmlTM(data,fulldata); if(!used) qDebug() << "Not used:" << file.fileName(); } } } parseItemsExtra(); parseSkillsExtra(); parseMonstersExtra(); updateMonsterXml(arguments.last()+QLatin1Literal(DATAPACK_BASE_PATH_MONSTERS)+QStringLiteral("monster.xml")); return 0; }
void ScanFileOrFolder::listFolder(QFileInfo source,QFileInfo destination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1 (%2), destination: %3 (%4)").arg(source.absoluteFilePath()).arg(source.isSymLink()).arg(destination.absoluteFilePath()).arg(destination.isSymLink())); if(stopIt) return; destination=resolvDestination(destination); if(stopIt) return; if(fileErrorAction==FileError_Skip) return; //if is same if(source.absoluteFilePath()==destination.absoluteFilePath()) { emit folderAlreadyExists(source,destination,true); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"pattern: "+folder_isolation.pattern()); //resolv the new name destinationSuffixPath=destination.baseName(); int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } num++; if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+text_dot+destination.completeSuffix()); } while(destination.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } //check if destination exists if(checkDestinationExists) { if(destination.exists()) { emit folderAlreadyExists(source,destination,false); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { //resolv the new name QFileInfo destinationInfo; int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } destinationInfo.setFile(destinationInfo.absolutePath()+text_slash+destinationSuffixPath); num++; } while(destinationInfo.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+QStringLiteral(".")+destination.completeSuffix()); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } } //do source check //check of source is readable do { fileErrorAction=FileError_NotSet; if(!source.isReadable() || !source.isExecutable() || !source.exists() || !source.isDir()) { if(!source.isDir()) emit errorOnFolder(source,tr("This is not a folder")); else if(!source.exists()) emit errorOnFolder(source,tr("The folder does exists")); else emit errorOnFolder(source,tr("The folder is not readable")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); do { QDir tempDir(source.absoluteFilePath()); fileErrorAction=FileError_NotSet; if(!tempDir.isReadable() || !tempDir.exists()) { emit errorOnFolder(source,tr("Problem with name encoding")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); if(stopIt) return; /// \todo check here if the folder is not readable or not exists QFileInfoList entryList; if(copyListOrder) entryList=QDir(source.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst|QDir::Name|QDir::IgnoreCase);//possible wait time here else entryList=QDir(source.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System);//possible wait time here if(stopIt) return; int sizeEntryList=entryList.size(); emit newFolderListing(source.absoluteFilePath()); if(mode!=Ultracopier::Move) emit addToMkPath(source,destination,sizeEntryList); for (int index=0;index<sizeEntryList;++index) { QFileInfo fileInfo=entryList.at(index); if(stopIt) return; if(haveFilters) { if(reloadTheNewFilters) { QMutexLocker lock(&filtersMutex); QCoreApplication::processEvents(QEventLoop::AllEvents); reloadTheNewFilters=false; this->include=this->include_send; this->exclude=this->exclude_send; } QString fileName=fileInfo.fileName(); if(fileInfo.isDir() && !fileInfo.isSymLink()) { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_folder || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_folder || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName()); } } else { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_file || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_file || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else #ifndef ULTRACOPIER_PLUGIN_RSYNC emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); #else { bool sendToTransfer=false; if(!rsync) sendToTransfer=true; else if(!QFile::exists(destination.absoluteFilePath()+"/"+fileInfo.fileName())) sendToTransfer=true; else if(fileInfo.lastModified()!=QFileInfo(destination.absoluteFilePath()+"/"+fileInfo.fileName()).lastModified()) sendToTransfer=true; if(sendToTransfer) emit fileTransfer(fileInfo.absoluteFilePath(),destination.absoluteFilePath()+"/"+fileInfo.fileName(),mode); } #endif } } } else { if(fileInfo.isDir() && !fileInfo.isSymLink())//possible wait time here //listFolder(source,destination,suffixPath+fileInfo.fileName()+QDir::separator()); listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName());//put unix separator because it's transformed into that's under windows too else #ifndef ULTRACOPIER_PLUGIN_RSYNC emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); #else { bool sendToTransfer=false; if(!rsync) sendToTransfer=true; else if(!QFile::exists(destination.absoluteFilePath()+"/"+fileInfo.fileName())) sendToTransfer=true; else if(fileInfo.lastModified()!=QFileInfo(destination.absoluteFilePath()+"/"+fileInfo.fileName()).lastModified()) sendToTransfer=true; if(sendToTransfer) emit fileTransfer(fileInfo.absoluteFilePath(),destination.absoluteFilePath()+"/"+fileInfo.fileName(),mode); } #endif } } #ifdef ULTRACOPIER_PLUGIN_RSYNC if(rsync) { //check the reverse path here QFileInfoList entryListDestination; if(copyListOrder) entryListDestination=QDir(destination.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst|QDir::Name|QDir::IgnoreCase);//possible wait time here else entryListDestination=QDir(destination.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System);//possible wait time here int sizeEntryListDestination=entryListDestination.size(); int index=0; for (int indexDestination=0;indexDestination<sizeEntryListDestination;++indexDestination) { index=0; while(index<sizeEntryList) { if(entryListDestination.at(indexDestination).fileName()==entryList.at(index).fileName()) break; index++; } if(index==sizeEntryList) { //then not found, need be remove emit addToRmForRsync(entryListDestination.at(indexDestination)); } } return; } #endif if(mode==Ultracopier::Move) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"source: "+source.absoluteFilePath()+", sizeEntryList: "+QString::number(sizeEntryList)); emit addToMovePath(source,destination,sizeEntryList); } }