Skip to content

Commit

Permalink
Rename currentVersion setting to installedVersion
Browse files Browse the repository at this point in the history
Fixes #59.

Also clean up the Settings class a bit.
  • Loading branch information
slipher committed May 6, 2024
1 parent 3736546 commit f9e1405
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions downloadworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool DownloadWorker::extractUpdate()
{
qDebug() << "Clearing installed version prior to extraction";
Settings settings;
settings.setCurrentVersion("");
settings.setInstalledVersion("");
QString filename = Sys::archiveName();
auto out = JlCompress::extractDir(downloadDir_ + "/" + filename, downloadDir_);
if (out.size() < 1) {
Expand All @@ -216,7 +216,7 @@ bool DownloadWorker::extractUpdate()
qDebug() << "Failed to determine version of downloaded game!";
} else {
qDebug() << "Setting installed version to" << unvanquishedVersion_;
settings.setCurrentVersion(unvanquishedVersion_);
settings.setInstalledVersion(unvanquishedVersion_);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion gamelauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void GameLauncher::startGame(bool useConnectUrl, bool failIfWindowsAdmin)
useConnectUrl = useConnectUrl && !connectUrl_.isEmpty();
QString gameCommand = Sys::getGameCommand(settings_.installPath());
QString commandLine;
if (useConnectUrl && !haveConnectTrusted(settings_.currentVersion())) {
if (useConnectUrl && !haveConnectTrusted(settings_.installedVersion())) {
// Behave for now as the old protocol handler which ignores the custom command
commandLine = gameCommand + " -connect " + connectUrl_;
} else {
Expand Down
2 changes: 1 addition & 1 deletion qmldownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void QmlDownloader::startUpdate(const QString& selectedInstallPath)
emit statusMessage("Installing to " + dir.canonicalPath());
if (settings_.installPath() != selectedInstallPath) {
qDebug() << "Clearing installed version because path was changed";
settings_.setCurrentVersion("");
settings_.setInstalledVersion("");
}
settings_.setInstallPath(selectedInstallPath);

Expand Down
28 changes: 17 additions & 11 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,46 @@

const char kDefaultCommand[] = "%command%";

// Registry/configuration file keys
const QString INSTALL_PATH = "settings/installPath";
const QString COMMAND_LINE = "settings/commandLineParameters";
const QString INSTALLED_VERSION = "settings/currentVersion";
// const QString INSTALL_FINISHED = "settings/installFinished"; // No longer used
const QString WRITE_PROBE = "writeProbe";

Settings::Settings() : QObject(nullptr), settings_(Sys::makePersistentSettings(this)) {
if (!settings_->contains(Settings::INSTALL_PATH)) {
if (!settings_->contains(INSTALL_PATH)) {
setInstallPath(Sys::defaultInstallPath());
}
if (!settings_->contains(Settings::COMMAND_LINE)) {
if (!settings_->contains(COMMAND_LINE)) {
setCommandLine(kDefaultCommand);
}
}

QString Settings::installPath() const {
return settings_->value(Settings::INSTALL_PATH).toString();
return settings_->value(INSTALL_PATH).toString();
}

QString Settings::commandLine() const {
return settings_->value(Settings::COMMAND_LINE).toString();
return settings_->value(COMMAND_LINE).toString();
}

QString Settings::currentVersion() const {
return settings_->value(Settings::CURRENT_VERSION).toString();
QString Settings::installedVersion() const {
return settings_->value(INSTALLED_VERSION).toString();
}

void Settings::setInstallPath(const QString& installPath) {
settings_->setValue(Settings::INSTALL_PATH, installPath);
settings_->setValue(INSTALL_PATH, installPath);
emit installPathChanged(installPath);
}

void Settings::setCommandLine(const QString& commandLine) {
settings_->setValue(Settings::COMMAND_LINE, commandLine);
settings_->setValue(COMMAND_LINE, commandLine);
emit commandLineChanged(commandLine);
}

void Settings::setCurrentVersion(const QString& currentVersion) {
settings_->setValue(Settings::CURRENT_VERSION, currentVersion);
emit currentVersionChanged(currentVersion);
void Settings::setInstalledVersion(const QString& installedVersion) {
settings_->setValue(INSTALLED_VERSION, installedVersion);
}

void Settings::sync()
Expand Down
16 changes: 4 additions & 12 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,24 @@ class Settings : public QObject
Q_OBJECT
Q_PROPERTY(QString installPath READ installPath WRITE setInstallPath NOTIFY installPathChanged)
Q_PROPERTY(QString commandLine READ commandLine WRITE setCommandLine NOTIFY commandLineChanged)
Q_PROPERTY(QString currentVersion READ currentVersion WRITE setCurrentVersion NOTIFY currentVersionChanged)
public:
const QString INSTALL_PATH = "settings/installPath";
const QString COMMAND_LINE = "settings/commandLineParameters";
const QString CURRENT_VERSION = "settings/currentVersion";
// const QString INSTALL_FINISHED = "settings/installFinished"; // No longer used
const QString WRITE_PROBE = "writeProbe";

Settings();

QString installPath() const;
QString commandLine() const;
// currentVersion should be a non-empty iff there is a usable installation at installPath
QString currentVersion() const;
// installedVersion should be a non-empty iff there is a usable installation at installPath
QString installedVersion() const;

void setInstallPath(const QString& installPath);
void setCommandLine(const QString& commandLine);
void setCurrentVersion(const QString& currentVersion);
void setInstalledVersion(const QString& installedVersion);
void sync();
QSettings::Status testWrite();

signals:
// QML property binding signals (configured with NOTIFY)
void installPathChanged(QString installPath);
void commandLineChanged(QString commandLine);
void currentVersionChanged(QString currentVersion);
void onMessage(QString message);

private:
QSettings* settings_;
Expand Down
8 changes: 4 additions & 4 deletions splashcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool SplashController::relaunchForSettings()

void SplashController::launchGameIfInstalled()
{
if (settings_.currentVersion().isEmpty()) {
if (settings_.installedVersion().isEmpty()) {
qDebug() << "No game installed, exiting";
QCoreApplication::quit();
} else {
Expand All @@ -72,7 +72,7 @@ void SplashController::launchGameIfInstalled()
// proceed as if the request for versions.json failed.
void SplashController::autoLaunchOrUpdate()
{
qDebug() << "Previously-installed game version:" << settings_.currentVersion();
qDebug() << "Previously-installed game version:" << settings_.installedVersion();

switch (relaunchCommand_) {
case RelaunchCommand::UPDATE_GAME:
Expand Down Expand Up @@ -113,8 +113,8 @@ void SplashController::autoLaunchOrUpdate()
launchGameIfInstalled();
return;
}
} else if (settings_.currentVersion().isEmpty() ||
(!latestGameVersion_.isEmpty() && settings_.currentVersion() != latestGameVersion_)) {
} else if (settings_.installedVersion().isEmpty() ||
(!latestGameVersion_.isEmpty() && settings_.installedVersion() != latestGameVersion_)) {
qDebug() << "Game update required.";
switch (Sys::RelaunchElevated("--splashms 1 --internalcommand updategame")) {
case Sys::ElevationResult::UNNEEDED:
Expand Down

0 comments on commit f9e1405

Please sign in to comment.