-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split UpdateChecker file access into separate class
Means we avoid using the UpdateChecker dialog code in setup which means we don't need swell at all
- Loading branch information
Showing
8 changed files
with
149 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "update_check_settings_file.h" | ||
#include <version/eps_version.h> | ||
#include <helper/resource_paths_juce-file.hpp> | ||
|
||
UpdateCheckerSettingsFile::UpdateCheckerSettingsFile() | ||
{ | ||
settingsFile = ResourcePaths::getSettingsDirectory(true).getChildFile("UpdateCheck.settings"); | ||
if (!settingsFileExists()) { | ||
// No settings file - perhaps first run? | ||
if (saveSettings() && settingsFileExists()) { | ||
// Settings file is writable so probably was just first run. | ||
// Set autocheck on initially. | ||
setAutoCheckEnabled(true); | ||
} | ||
} | ||
loadSettings(); | ||
} | ||
|
||
UpdateCheckerSettingsFile::~UpdateCheckerSettingsFile() | ||
{ | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::getAutoCheckEnabled() | ||
{ | ||
return settingAutoCheckEnabled; | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::setAutoCheckEnabled(bool enabled) | ||
{ | ||
settingAutoCheckEnabled = enabled; | ||
return saveSettings(); | ||
} | ||
|
||
Version UpdateCheckerSettingsFile::getLastReportedVersion() | ||
{ | ||
return settingLastReportedVersion; | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::setLastReportedVersion(Version version) | ||
{ | ||
settingLastReportedVersion = version; | ||
return saveSettings(); | ||
} | ||
|
||
|
||
bool UpdateCheckerSettingsFile::canReadSettingsFile() | ||
{ | ||
return loadSettings(); | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::canWriteSettingsFile() | ||
{ | ||
return saveSettings(); | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::loadSettings() | ||
{ | ||
if (!settingsFileExists()) { | ||
return false; | ||
} | ||
|
||
juce::XmlDocument xml(settingsFile); | ||
auto updateCheckElement = xml.getDocumentElementIfTagMatches("UpdateCheck"); | ||
if (!updateCheckElement) { | ||
return false; | ||
} | ||
|
||
auto lastReportedElement = updateCheckElement->getChildByName("LastReportedVersion"); | ||
if (lastReportedElement) { | ||
settingLastReportedVersion.major = lastReportedElement->getIntAttribute("VersionMajor", 0); | ||
settingLastReportedVersion.minor = lastReportedElement->getIntAttribute("VersionMinor", 0); | ||
settingLastReportedVersion.revision = lastReportedElement->getIntAttribute("VersionRevision", 0); | ||
} | ||
|
||
auto autoCheckElement = updateCheckElement->getChildByName("AutoCheck"); | ||
if (autoCheckElement) { | ||
settingAutoCheckEnabled = autoCheckElement->getBoolAttribute("OnStartUp", false); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::saveSettings() | ||
{ | ||
auto updateCheckElement = juce::XmlElement("UpdateCheck"); | ||
|
||
auto lastReportedElement = new juce::XmlElement("LastReportedVersion"); | ||
lastReportedElement->setAttribute("VersionMajor", settingLastReportedVersion.major); | ||
lastReportedElement->setAttribute("VersionMinor", settingLastReportedVersion.minor); | ||
lastReportedElement->setAttribute("VersionRevision", settingLastReportedVersion.revision); | ||
updateCheckElement.addChildElement(lastReportedElement); | ||
|
||
auto autoCheckElement = new juce::XmlElement("AutoCheck"); | ||
autoCheckElement->setAttribute("OnStartUp", settingAutoCheckEnabled); | ||
updateCheckElement.addChildElement(autoCheckElement); | ||
|
||
return updateCheckElement.writeTo(settingsFile); | ||
} | ||
|
||
bool UpdateCheckerSettingsFile::settingsFileExists() | ||
{ | ||
return settingsFile.existsAsFile(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include <AppConfig.h> | ||
#include <juce_core/juce_core.h> | ||
#include <helper/version.hpp> | ||
|
||
class UpdateCheckerSettingsFile { | ||
public: | ||
UpdateCheckerSettingsFile(); | ||
~UpdateCheckerSettingsFile(); | ||
|
||
bool getAutoCheckEnabled(); | ||
bool setAutoCheckEnabled(bool enabled); | ||
|
||
Version getLastReportedVersion(); | ||
bool setLastReportedVersion(Version version); | ||
|
||
bool canReadSettingsFile(); | ||
bool canWriteSettingsFile(); | ||
|
||
private: | ||
|
||
juce::File settingsFile; | ||
bool loadSettings(); | ||
bool saveSettings(); | ||
bool settingsFileExists(); | ||
|
||
bool settingAutoCheckEnabled{ false }; | ||
Version settingLastReportedVersion; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters