From e6a8681dbe718eb3005e3b88fd24ce968279712c Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Mon, 24 Apr 2023 11:14:23 -0400 Subject: [PATCH] Always download to a local directory outside of the binary directory otherwise models will be deleted when updates occur. Update version. --- CMakeLists.txt | 2 +- download.cpp | 50 +++++++++++++++++--------------------------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f83216a..b8711e55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() set(APP_VERSION_MAJOR 2) set(APP_VERSION_MINOR 2) -set(APP_VERSION_PATCH 0) +set(APP_VERSION_PATCH 1) set(APP_VERSION "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}") # Generate a header file with the version number diff --git a/download.cpp b/download.cpp index 3d34a6cd..4be30148 100644 --- a/download.cpp +++ b/download.cpp @@ -46,45 +46,29 @@ QList Download::modelList() const QString Download::downloadLocalModelsPath() const { - { - QString exePath = QCoreApplication::applicationDirPath() + QDir::separator(); - QString testWritePath = exePath + QString("test_write.txt"); - QString canonicalExePath = QFileInfo(exePath).canonicalFilePath() + QDir::separator(); - if (QFileInfo::exists(testWritePath)) - return canonicalExePath; - - QFile testWriteFile(testWritePath); - if (testWriteFile.open(QIODeviceBase::ReadWrite)) { - testWriteFile.close(); - return canonicalExePath; + QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + QDir::separator(); + QString testWritePath = localPath + QString("test_write.txt"); + QString canonicalLocalPath = QFileInfo(localPath).canonicalFilePath() + QDir::separator(); + QDir localDir(localPath); + if (!localDir.exists()) { + if (!localDir.mkpath(localPath)) { + qWarning() << "ERROR: Local download directory can't be created:" << canonicalLocalPath; + return canonicalLocalPath; } } - { - QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) - + QDir::separator(); - QString testWritePath = localPath + QString("test_write.txt"); - QString canonicalLocalPath = QFileInfo(localPath).canonicalFilePath() + QDir::separator(); - QDir localDir(localPath); - if (!localDir.exists()) { - if (!localDir.mkpath(localPath)) { - qWarning() << "ERROR: Local download directory can't be created:" << canonicalLocalPath; - return canonicalLocalPath; - } - } - - if (QFileInfo::exists(testWritePath)) - return canonicalLocalPath; - - QFile testWriteFile(testWritePath); - if (testWriteFile.open(QIODeviceBase::ReadWrite)) { - testWriteFile.close(); - return canonicalLocalPath; - } + if (QFileInfo::exists(testWritePath)) + return canonicalLocalPath; - qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath; + QFile testWriteFile(testWritePath); + if (testWriteFile.open(QIODeviceBase::ReadWrite)) { + testWriteFile.close(); return canonicalLocalPath; } + + qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath; + return canonicalLocalPath; } void Download::updateModelList()