improved import/export behaviors as some documents could be overwritten when they should not

preferencesAboutTextFull
Clément Fauconnier 4 years ago
parent ab705d282e
commit 1dbdd90f68
  1. 12
      src/adaptors/UBImportDocumentSetAdaptor.cpp
  2. 1
      src/board/UBBoardController.cpp
  3. 2
      src/document/UBDocumentController.cpp
  4. 7
      src/frameworks/UBFileSystemUtils.cpp
  5. 2
      src/frameworks/UBFileSystemUtils.h

@ -94,11 +94,17 @@ QFileInfoList UBImportDocumentSetAdaptor::importData(const QString &zipFile, con
foreach(QFileInfo readDir, tDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden , QDir::Name)) { foreach(QFileInfo readDir, tDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden , QDir::Name)) {
QString newFileName = readDir.fileName(); QString newFileName = readDir.fileName();
if (QFileInfo(destination + "/" + readDir.fileName()).exists()) { if (QFileInfo(destination + "/" + newFileName).exists())
newFileName = QFileInfo(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(tmpDir)).fileName(); {
//if the generateUniqueDocumentPath is called twice in the same millisecond, the destination files are overwritten
do
{
newFileName = QFileInfo(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(tmpDir)).fileName();
} while (QFileInfo(destination + "/" + newFileName).exists());
} }
QString newFilePath = destination + "/" + newFileName; QString newFilePath = destination + "/" + newFileName;
if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath)) { if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath, true)) {
result.append(newFilePath); result.append(newFilePath);
} }
} }

@ -780,6 +780,7 @@ void UBBoardController::deleteScene(int nIndex)
scIndexes << nIndex; scIndexes << nIndex;
deletePages(scIndexes); deletePages(scIndexes);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
selectedDocument()->setMetaData(UBSettings::documentPageCount, QString::number(pageCount()-1));
if (nIndex >= pageCount()) if (nIndex >= pageCount())
nIndex = pageCount()-1; nIndex = pageCount()-1;

@ -2786,6 +2786,8 @@ void UBDocumentController::importFile()
if (fileInfo.suffix().toLower() == "ubx") { if (fileInfo.suffix().toLower() == "ubx") {
UBPersistenceManager::persistenceManager()->createDocumentProxiesStructure(docManager->importUbx(filePath, UBSettings::userDocumentDirectory()), true); UBPersistenceManager::persistenceManager()->createDocumentProxiesStructure(docManager->importUbx(filePath, UBSettings::userDocumentDirectory()), true);
emit documentThumbnailsUpdated(this); // some documents might have been overwritten while not having the same page count
} else { } else {
UBSettings::settings()->lastImportFilePath->set(QVariant(fileInfo.absolutePath())); UBSettings::settings()->lastImportFilePath->set(QVariant(fileInfo.absolutePath()));

@ -121,7 +121,7 @@ bool UBFileSystemUtils::copyFile(const QString &source, const QString &destinati
bool UBFileSystemUtils::copy(const QString &source, const QString &destination, bool overwrite) bool UBFileSystemUtils::copy(const QString &source, const QString &destination, bool overwrite)
{ {
if (QFileInfo(source).isDir()) { if (QFileInfo(source).isDir()) {
return copyDir(source, destination); return copyDir(source, destination, overwrite);
} else { } else {
return copyFile(source, destination, overwrite); return copyFile(source, destination, overwrite);
} }
@ -280,7 +280,7 @@ bool UBFileSystemUtils::deleteDir(const QString& pDirPath)
} }
bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath) bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath, bool overwite)
{ {
if (pSourceDirPath == "" || pSourceDirPath == "." || pSourceDirPath == "..") if (pSourceDirPath == "" || pSourceDirPath == "." || pSourceDirPath == "..")
return false; return false;
@ -304,8 +304,7 @@ bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pT
} }
else else
{ {
QFile f(pSourceDirPath + "/" + dirContent.fileName()); successSoFar = copyFile(pSourceDirPath + "/" + dirContent.fileName(), pTargetDirPath + "/" + dirContent.fileName(), overwite);
successSoFar = f.copy(pTargetDirPath + "/" + dirContent.fileName());
} }
} }
else else

@ -62,7 +62,7 @@ class UBFileSystemUtils : public QObject
static bool deleteDir(const QString& pDirPath); static bool deleteDir(const QString& pDirPath);
static bool copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath); static bool copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath, bool overwrite = false);
static bool moveDir(const QString& pSourceDirPath, const QString& pTargetDirPath); static bool moveDir(const QString& pSourceDirPath, const QString& pTargetDirPath);

Loading…
Cancel
Save