From 6f8a788d804a1a941565b82fbc0a08a8ab94b7b3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 14 Jun 2018 16:28:03 +0100 Subject: [PATCH] Launcher bugfix: custom download dirs Partial fixes for: https://sourceforge.net/p/flightgear/codetickets/2019/ But further work needed on Windows I expect, will do that now. --- src/GUI/LauncherController.cxx | 26 +++++--------------------- src/GUI/qml/SettingControl.qml | 7 ++++--- src/GUI/qml/Settings.qml | 9 ++++++++- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/GUI/LauncherController.cxx b/src/GUI/LauncherController.cxx index 779ab47aa..66db8daa5 100644 --- a/src/GUI/LauncherController.cxx +++ b/src/GUI/LauncherController.cxx @@ -344,9 +344,9 @@ void LauncherController::downloadDirChanged(QString path) return; } - // if the default dir is passed in, map that back to the emptru string + // if the default dir is passed in, map that back to the empty string if (path == m_config->defaultDownloadDir()) { - path.clear();; + path.clear(); } auto options = flightgear::Options::sharedInstance(); @@ -364,25 +364,9 @@ void LauncherController::downloadDirChanged(QString path) options->clearOption("download-dir"); } - // replace existing package root - globals->get_subsystem()->shutdown(); - globals->setPackageRoot(simgear::pkg::RootRef()); - - // create new root with updated download-dir value - fgInitPackageRoot(); - - globals->get_subsystem()->init(); - - QSettings settings; - // re-scan the aircraft list - m_aircraftModel->setPackageRoot(globals->packageRoot()); - - auto aircraftCache = LocalAircraftCache::instance(); - aircraftCache->setPaths(settings.value("aircraft-paths").toStringList()); - aircraftCache->scanDirs(); - - // re-set scenery dirs - flightgear::launcherSetSceneryPaths(); + m_config->setValueForKey("", "download-dir", path); + saveSettings(); + flightgear::restartTheApp(); } QmlAircraftInfo *LauncherController::selectedAircraftInfo() const diff --git a/src/GUI/qml/SettingControl.qml b/src/GUI/qml/SettingControl.qml index 8a0a95d81..cd2b1f79b 100644 --- a/src/GUI/qml/SettingControl.qml +++ b/src/GUI/qml/SettingControl.qml @@ -62,6 +62,9 @@ Item { function saveState() { + if (root.setting === "") + return; + if (this.hasOwnProperty("value")) { _config.setValueForKey("", root.setting, this.value) } else { @@ -71,10 +74,8 @@ Item { function restoreState() { - if (root.setting == "") { - console.warn("Missing setting key on " + label) + if (root.setting === "") return; - } if (!"value" in root) { console.warn("No value property on " + root); diff --git a/src/GUI/qml/Settings.qml b/src/GUI/qml/Settings.qml index 6e9bc7c69..520c9df79 100644 --- a/src/GUI/qml/Settings.qml +++ b/src/GUI/qml/Settings.qml @@ -309,7 +309,8 @@ Item { label: qsTr("Download location") description: qsTr("FlightGear stores downloaded files (scenery and aircraft) in this location. " + "Depending on your settings, it may grow to a considerable size (many gigabytes). " - + "If you change the download location, files will need to be downloaded again.") + + "If you change the download location, files will need to be downloaded again. " + + "When changing this setting, FlightGear will restart to use the new location correctly.") advanced: true chooseDirectory: true defaultPath: _config.defaultDownloadDir @@ -327,6 +328,12 @@ Item { // value is changed. _launcher.downloadDirChanged(path); } + + function saveState() + { + // ensure this is a no-op, we write the value explicity + // in LauncherController::downloadDirChanged + } } ]