Always download to a local directory outside of the binary directory otherwise

models will be deleted when updates occur. Update version.
pull/520/head
Adam Treat 1 year ago
parent 241e1f6773
commit e6a8681dbe

@ -14,7 +14,7 @@ endif()
set(APP_VERSION_MAJOR 2) set(APP_VERSION_MAJOR 2)
set(APP_VERSION_MINOR 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}") set(APP_VERSION "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}")
# Generate a header file with the version number # Generate a header file with the version number

@ -46,45 +46,29 @@ QList<ModelInfo> Download::modelList() const
QString Download::downloadLocalModelsPath() const QString Download::downloadLocalModelsPath() const
{ {
{ QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
QString exePath = QCoreApplication::applicationDirPath() + QDir::separator(); + QDir::separator();
QString testWritePath = exePath + QString("test_write.txt"); QString testWritePath = localPath + QString("test_write.txt");
QString canonicalExePath = QFileInfo(exePath).canonicalFilePath() + QDir::separator(); QString canonicalLocalPath = QFileInfo(localPath).canonicalFilePath() + QDir::separator();
if (QFileInfo::exists(testWritePath)) QDir localDir(localPath);
return canonicalExePath; if (!localDir.exists()) {
if (!localDir.mkpath(localPath)) {
QFile testWriteFile(testWritePath); qWarning() << "ERROR: Local download directory can't be created:" << canonicalLocalPath;
if (testWriteFile.open(QIODeviceBase::ReadWrite)) { return canonicalLocalPath;
testWriteFile.close();
return canonicalExePath;
} }
} }
{ if (QFileInfo::exists(testWritePath))
QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) return canonicalLocalPath;
+ 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;
}
qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath; QFile testWriteFile(testWritePath);
if (testWriteFile.open(QIODeviceBase::ReadWrite)) {
testWriteFile.close();
return canonicalLocalPath; return canonicalLocalPath;
} }
qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath;
return canonicalLocalPath;
} }
void Download::updateModelList() void Download::updateModelList()

Loading…
Cancel
Save