/*! \reimp */ bool QFSContentEngine::rename(const QString &name) { if (fileName().isEmpty()) { setError("Empty source path"); return false; } QString extension = determineExtension(name, mimeType()); QString baseName = determineBaseName(name, extension); QString newPath = newFilePath(baseName, extension, QFileInfo(fileName()).absoluteDir()); QFile file(fileName()); if (file.rename(newPath)) { setFileName(newPath); setName(baseName); return true; } else { setError(file.errorString()); return false; } }
//this default implementation rename all file in the same directory //that have the same file title ERMsg CDirectoryManager::RenameFile(const std::string& oldFileName, const std::string& newFileName)const { ASSERT(oldFileName != newFileName); ERMsg msg; bool bHaveExt = !GetFileExtension(oldFileName).empty(); string oldFilePath = GetFilePath(oldFileName); string newFilePath(oldFilePath); if (bHaveExt) SetFileName(newFilePath, newFileName); else SetFileTitle(newFilePath, newFileName); msg = CDirectoryManagerBase::RenameFile(GetFileTitle(oldFilePath), GetFileExtension(oldFilePath), GetFileTitle(newFilePath), GetFileExtension(newFilePath)); // // bool bChangeExt = GetFileExtension(fileName).empty(); // // // std::string filePath = GetFilePath(fileName); // ASSERT( !filePath.empty() ); //// while( !filePath.empty() ) //// { // try // { // std::string strSrh = filePath; // if( bChangeExt ) // SetFileExtension(strSrh, ".*"); // // StringVector filePathList; // UtilWin::GetFilesList(filePathList, strSrh, true); // for(int i=0; i<filePathListsize(); i++) // { // std::string newFilePath = filePathList[i]; // if( bChangeExt ) // UtilWin::SetFileTitle(newFilePath, newFileName); // else UtilWin::SetFileName(newFilePath, newFileName); // // CFile::Rename(filePathList[i], newFilePath); // } // } // catch(CFileException, e) // { // msg = SYGetMessage(*e); //// break; // } // // // filePath = GetFilePath(fileName); // } return msg; }
ERMsg CDirectoryManager::CopyFile(const std::string& oldFileName, const std::string& newFileName)const { ASSERT(oldFileName != newFileName); ERMsg msg; bool bHaveExt = !GetFileExtension(oldFileName).empty(); string oldFilePath = GetFilePath(oldFileName); string newFilePath(oldFilePath); if (bHaveExt) SetFileName(newFilePath, newFileName); else SetFileTitle(newFilePath, newFileName); msg = CopyOneFile(oldFilePath, newFilePath); /* bool bChangeExt = GetFileExtension(fileName).empty(); std::string filePath = GetFilePath(fileName); ASSERT( !filePath.empty() ); TRY { std::string strSrh = filePath; if( bChangeExt ) UtilWin::SetFileExtension(strSrh, ".*"); StringVector filePathList; UtilWin::GetFilesList(filePathList, strSrh, true); for(int i=0; i<filePathListsize(); i++) { std::string newFilePath = filePathList[i]; if( bChangeExt ) UtilWin::SetFileTitle(newFilePath, newFileName); else UtilWin::SetFileName(newFilePath, newFileName); if( !::CopyFile(filePathList[i], newFilePath, true) ) { msg = SYGetMessage( GetLastError() ); std::string erreur; erreur.FormatMsg(IDS_CMN_UNABLE_COPY_FILE, (LPCTSTR)filePathList[i]); msg.ajoute(erreur); } } } CATCH(CFileException, e) { msg = SYGetMessage(*e); } END_CATCH */ return msg; }
/*! \reimp */ QIODevice *QFSContentEngine::open( QIODevice::OpenMode mode ) { if( name().isEmpty() ) return 0; if( fileName().isEmpty() ) { if( mode & QIODevice::WriteOnly ) { if( mimeType().isNull() ) setMimeType( QMimeType::fromFileName( name() ) ); QString media = this->media(); QFileSystem fs = !media.isNull() ? QFileSystem::fromFileName( media ) : QFileSystem::documentsFileSystem(); QDir dir = determineDirectory(mimeType(), fs.documentsPath()); QString extension = determineExtension(name(), mimeType()); QString baseName = determineBaseName(name(), extension); setName(baseName); setFileName(newFilePath(baseName, extension, dir)); } else return 0; } QFile *file = new QFile( fileName() ); if( !file->open( mode ) ) { setError( file->errorString() ); delete file; file = 0; } return file; }
bool ModelBackendOneFile::booksToLoad( const QString& path, QStringList& booksPaths ) { QDir dir(path); if(!dir.exists()) return false; dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files | QDir::Readable); dir.setSorting(QDir::DirsFirst | QDir::Name); QStringList sub_list; QStringList list = dir.entryList(); QStringList::const_iterator i = list.begin(); QStringList::const_iterator itEnd = list.end(); QFileInfo fi; while(i != itEnd) { QString file_path = dir.filePath(*i); fi.setFile(file_path); if(!fi.exists()) return false; const QString& name = fi.fileName(); if (!name.startsWith(".") && fi.isDir()) { sub_list += file_path; ++i; continue; } if (name.startsWith(".") || !BookInfo::isBook(file_path)) { ++i; continue; } // Handle problematic characters if(name.contains("+")) { // Rename the file QFile renaming(file_path); if(renaming.exists()) { QString newFilePath(file_path); newFilePath.replace("+", ""); qDebug() << Q_FUNC_INFO << "Renaming: " << file_path << " to " << newFilePath; if(renaming.rename(newFilePath)) { fi.setFile(renaming); file_path = fi.absoluteFilePath(); } else return false; } else return false; } booksPaths.append(file_path); ++i; } QStringList::const_iterator j = sub_list.begin(); while(j != sub_list.end()) { if(!booksToLoad(*j, booksPaths)) return false; ++j; } return true; }