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

models will be deleted when updates occur. Update version.
This commit is contained in:
Adam Treat 2023-04-24 11:14:23 -04:00
parent 241e1f6773
commit e6a8681dbe
2 changed files with 18 additions and 34 deletions

View File

@ -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

View File

@ -46,45 +46,29 @@ QList<ModelInfo> 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;
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;
}
qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath;
return canonicalLocalPath;
}
void Download::updateModelList()