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. 10
      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)) {
QString newFileName = readDir.fileName();
if (QFileInfo(destination + "/" + readDir.fileName()).exists()) {
if (QFileInfo(destination + "/" + newFileName).exists())
{
//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;
if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath)) {
if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath, true)) {
result.append(newFilePath);
}
}

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

@ -2786,6 +2786,8 @@ void UBDocumentController::importFile()
if (fileInfo.suffix().toLower() == "ubx") {
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 {
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)
{
if (QFileInfo(source).isDir()) {
return copyDir(source, destination);
return copyDir(source, destination, overwrite);
} else {
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 == "..")
return false;
@ -304,8 +304,7 @@ bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pT
}
else
{
QFile f(pSourceDirPath + "/" + dirContent.fileName());
successSoFar = f.copy(pTargetDirPath + "/" + dirContent.fileName());
successSoFar = copyFile(pSourceDirPath + "/" + dirContent.fileName(), pTargetDirPath + "/" + dirContent.fileName(), overwite);
}
}
else

@ -62,7 +62,7 @@ class UBFileSystemUtils : public QObject
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);

Loading…
Cancel
Save