1
0
Fork 0

Change default Windows download-dir to

$HOME/FlightGear/Downloads

Add a launcher warning about this, to request users to relocate existing
files, they already downloaded.
This commit is contained in:
Automatic Release Builder 2020-12-02 11:54:04 +00:00 committed by James Turner
parent 7279b51785
commit 8f9f0cbb19
7 changed files with 93 additions and 16 deletions

View file

@ -4,16 +4,16 @@
// Qt headers
#include <QDebug>
#include <QSettings>
#include <QDesktopServices>
#include <QFileDialog>
#include <QJSEngine>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>
#include <QDesktopServices>
#include <QMessageBox>
#include <QSettings>
#include <QQuickWindow>
#include <QQmlComponent>
#include <QPushButton>
#include <QFileDialog>
#include <QQmlComponent>
#include <QQuickWindow>
#include <QSettings>
// simgear headers
#include <simgear/package/Install.hxx>
@ -38,6 +38,7 @@
#include "HoverArea.hxx"
#include "LaunchConfig.hxx"
#include "LauncherArgumentTokenizer.hxx"
#include "LauncherNotificationsController.hxx"
#include "LocationController.hxx"
#include "MPServersModel.h"
#include "ModelDataExtractor.hxx"
@ -148,6 +149,8 @@ LauncherController::LauncherController(QObject *parent, QWindow* window) :
m_versionLaunchCount = settings.value(versionedCountKey, 0).toInt();
settings.setValue(versionedCountKey, m_versionLaunchCount + 1);
}
QTimer::singleShot(2000, this, &LauncherController::checkForOldDownloadDir);
}
void LauncherController::initQML()
@ -896,3 +899,44 @@ QUrl LauncherController::urlToDataPath(QString relPath) const
}
return QUrl::fromLocalFile(absFilePath + relPath);
}
void LauncherController::checkForOldDownloadDir()
{
#if defined(Q_OS_WIN)
auto options = flightgear::Options::sharedInstance();
if (options->valueForOption("download-dir") != std::string{}) {
return; // if we're using a custom value, nothing to do
}
if (haveOldWindowsDownloadDir()) {
// the notifications logic handles 'don't show again' lgoic internally,
// so we can always trigger this check
auto nc = LauncherNotificationsController::instance();
QJSValue args = nc->jsEngine()->newObject();
const auto oldPath = SGPath::documents() / "FlightGear";
const auto newPath = flightgear::defaultDownloadDir();
const QUrl oldLocURI = QUrl::fromLocalFile(QString::fromStdString(oldPath.utf8Str()));
const QUrl newLocURI = QUrl::fromLocalFile(QString::fromStdString(newPath.utf8Str()));
args.setProperty("oldLocation", oldLocURI.toString());
args.setProperty("newLocation", newLocURI.toString());
args.setProperty("persistent-dismiss", true);
nc->postNotification("have-old-downloads-location", QUrl{"qrc:///qml/DownloadsInDocumentsWarning.qml"}, args);
}
#endif
}
bool LauncherController::haveOldWindowsDownloadDir() const
{
const SGPath p = SGPath::documents() / "FlightGear";
if ((p / "TerraSync").exists() || (p / "Aircraft").exists()) {
return true;
}
// tex-cache dir is created by default, so check if it's populated
simgear::Dir texCacheDir(p / "TextureCache");
return (texCacheDir.exists() && !texCacheDir.isEmpty());
}

View file

@ -268,6 +268,9 @@ private slots:
void saveAircraft();
void restoreAircraft();
void checkForOldDownloadDir();
private:
/**
* Check if the passed index is the selected aircraft, and if so, refresh
@ -286,6 +289,7 @@ private:
void collectAircraftArgs();
QString selectAircraftStateAutomatically();
bool haveOldWindowsDownloadDir() const;
private:
QWindow* m_window = nullptr;

View file

@ -0,0 +1,27 @@
import QtQuick 2.4
import "."
Text {
signal dismiss();
readonly property string oldLocationURI: "\"" + _notifications.argsForIndex(model.index).oldLocation + "\""
readonly property string newLocationURI: "\"" + _notifications.argsForIndex(model.index).newLocation + "\""
text: qsTr("<p>FlightGear previously downloaded aircraft and scenery to a folder within your 'Documents' folder. " +
"This can cause problems with some security features of Windows, so a new location is now recommended.</p><br/>" +
"<p>To keep your existing aircraft and scenery downloads, please move the files from " +
"<u><a href=%1>the old location</a></u> to <u><a href=%2>the new location</a></u></p>").arg(oldLocationURI).arg(newLocationURI)
wrapMode: Text.WordWrap
font.pixelSize: Style.subHeadingFontPixelSize
color: Style.themeContrastTextColor
linkColor: Style.themeContrastLinkColor
textFormat: Text.StyledText
onLinkActivated: {
console.log("Activated:" + link);
Qt.openUrlExternally(link); // will open Windows Explorer since it's a file:/// URI
// don't dismiss, user needs to click both links :)
}
}

View file

@ -35,6 +35,12 @@ Item {
color: "white"
}
// capture mouse events
MouseArea {
anchors.fill: parent
hoverEnabled: true
}
Loader {
// height is not anchored, can float
anchors {

View file

@ -23,6 +23,8 @@ QtObject
readonly property string disabledMinorFrameColor: "#afafaf"
readonly property string baseTextColor: "#2f2f2f"
readonly property string themeContrastTextColor: "#efefef"
readonly property string themeContrastLinkColor: baseTextColor
readonly property int baseFontPixelSize: 12
readonly property int subHeadingFontPixelSize: 14

View file

@ -143,6 +143,7 @@
<file>qml/NewVersionNotification.qml</file>
<file>qml/DidMigrateOfficialCatalogNotification.qml</file>
<file>qml/DidMigrateOtherCatalogNotification.qml</file>
<file>qml/DownloadsInDocumentsWarning.qml</file>
<file>qml/BackButton.qml</file>
<file>qml/ScrollToBottomHint.qml</file>
</qresource>

View file

@ -2529,16 +2529,9 @@ string_list Options::valuesForOption(const std::string& key) const
SGPath defaultDownloadDir()
{
#if defined(SG_WINDOWS)
SGPath p(SGPath::documents());
if (p.isNull()) {
SG_LOG(SG_IO, SG_ALERT, "Failed to locate user's Documents directory, will default to FG_HOME");
// fall through to standard get_fg_home codepath
}
else {
return p / "FlightGear";
}
const SGPath p = SGPath::home() / "FlightGear" / "Downloads";
return p;
#endif
return globals->get_fg_home();
}