Fixed bug with app update. Fixed bug with configs out of sync. Updated submodules. Increased version number.

This commit is contained in:
Nichole Mattera 2019-09-10 18:08:46 -04:00
parent 909e2c7ae6
commit d851b520a0
8 changed files with 85 additions and 35 deletions

View File

@ -45,14 +45,16 @@ INCLUDES := include
ROMFS := romfs
APP_TITLE := Kosmos Updater
APP_AUTHOR := Steven Mattera
APP_AUTHOR := Nichole Mattera
APP_VERSION := 3.0.7
APP_VERSION := 3.0.8
APP_VERSION_MAJOR := 3
APP_VERSION_MINOR := 0
APP_VERSION_PATCH := 7
APP_VERSION_PATCH := 8
API_VERSION := v4
CONFIG_VERSION := 1
SETTING_CONFIG_VERSION := 1
INTERNAL_CONFIG_VERSION := 2
#---------------------------------------------------------------------------------
# options for code generation
@ -65,7 +67,8 @@ DEFINES += -D__SWITCH__ \
-DVERSION_MINOR=$(APP_VERSION_MINOR) \
-DVERSION_PATCH=$(APP_VERSION_PATCH) \
-DAPI_VERSION=\"$(API_VERSION)\" \
-DCONFIG_VERSION=$(CONFIG_VERSION)
-DSETTING_CONFIG_VERSION=$(SETTING_CONFIG_VERSION) \
-DINTERNAL_CONFIG_VERSION=$(INTERNAL_CONFIG_VERSION)
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES) $(INCLUDE)

@ -1 +1 @@
Subproject commit 6a1d292a6b9ad3baa012a71c3dd28f488eecaeab
Subproject commit a7f88f6671e5f4935a550d0b6cfd5c078b51e9fc

2
Swurl

@ -1 +1 @@
Subproject commit 4de6882e79a2a1526728ff388f065ae8fec1cd41
Subproject commit dc6435ff5ac538ee0fd732c71f7b215dfd9e5f5a

View File

@ -23,6 +23,7 @@ namespace ku {
void ConfigManager::initialize() {
config_init(&_cfg);
config_init(&_internalDb);
printf("%s %d\n", __FILE__, __LINE__);
if(!config_read_file(&_internalDb, INTERNAL_FILENAME.c_str())) {
config_setting_t * root, * setting;
@ -41,6 +42,9 @@ namespace ku {
setting = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, IGNORE_CONFIG_FILES_DEF);
setting = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(setting, INTERNAL_CONFIG_VERSION);
config_write_file(&_internalDb, INTERNAL_FILENAME.c_str());
}
@ -70,15 +74,12 @@ namespace ku {
config_setting_set_string(setting, PROXY_PASSWORD_DEF.c_str());
setting = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(setting, CONFIG_VERSION);
config_setting_set_int(setting, SETTING_CONFIG_VERSION);
config_write_file(&_cfg, CONFIG_FILENAME.c_str());
} else {
int configVersion = getConfigVersion();
if (configVersion < CONFIG_VERSION) {
_migrateConfigFile(configVersion);
}
}
_migrateConfigFiles();
}
void ConfigManager::dealloc() {
@ -119,7 +120,7 @@ namespace ku {
return _readString(PROXY_PASSWORD_KEY, PROXY_PASSWORD_DEF, _cfg);
}
int ConfigManager::getConfigVersion() {
int ConfigManager::getSettingsConfigVersion() {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _cfg);
}
@ -150,6 +151,10 @@ namespace ku {
return _readBoolean(IGNORE_CONFIG_FILES_KEY, IGNORE_CONFIG_FILES_DEF, _internalDb);
}
int ConfigManager::getInternalConfigVersion() {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _internalDb);
}
bool ConfigManager::setCurrentVersion(string version) {
return _writeString(VERSION_KEY, version, _internalDb, INTERNAL_FILENAME);
@ -285,18 +290,25 @@ namespace ku {
return config_write_file(&config, filename.c_str());
}
void ConfigManager::_migrateConfigFile(int currentVersion) {
void ConfigManager::_migrateConfigFiles() {
auto settingsVersion = getSettingsConfigVersion();
auto internalVersion = getInternalConfigVersion();
if (internalVersion < INTERNAL_CONFIG_VERSION) {
_migrateInternalConfigFiles(internalVersion);
}
if (settingsVersion < SETTING_CONFIG_VERSION) {
_migrateSettingsConfigFiles(settingsVersion);
}
}
void ConfigManager::_migrateSettingsConfigFiles(int currentVersion) {
bool configChanged = false;
config_setting_t * internalRoot = config_root_setting(&_internalDb);
config_setting_t * root = config_root_setting(&_cfg);
if (currentVersion < 1) {
configChanged = true;
// Added setting in internal to keep track of if the user is ignoring config files.
config_setting_t * ignoreConfigFiles = config_setting_add(internalRoot, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(ignoreConfigFiles, IGNORE_CONFIG_FILES_DEF);
// Migrate from HTTP to HTTPS.
if (getHost() == "http://kosmos-updater.teamatlasnx.com") {
config_setting_t * host = config_setting_get_member(root, HOST_KEY.c_str());
@ -311,10 +323,7 @@ namespace ku {
auto file = string(config_setting_get_string_elem(ignoredFiles, i));
if (file == "sdmc:/config/ftpd/config.ini") {
config_setting_set_string_elem(ignoredFiles, i, "sdmc:/config/sys-ftpd/config.ini");
// If this is present then the user is ignoring config files.
config_setting_set_bool(ignoreConfigFiles, true);
setIgnoreConfigFiles(true);
break;
}
}
@ -326,8 +335,38 @@ namespace ku {
}
if (configChanged) {
config_write_file(&_internalDb, INTERNAL_FILENAME.c_str());
config_write_file(&_cfg, CONFIG_FILENAME.c_str());
}
}
void ConfigManager::_migrateInternalConfigFiles(int currentVersion) {
bool configChanged = false;
config_setting_t * root = config_root_setting(&_internalDb);
if (currentVersion < 1 && config_lookup(&_internalDb, IGNORE_CONFIG_FILES_KEY.c_str()) == NULL) {
configChanged = true;
// Added setting in internal to keep track of if the user is ignoring config files.
config_setting_t * ignoreConfigFiles = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(ignoreConfigFiles, IGNORE_CONFIG_FILES_DEF);
}
if (currentVersion < 2) {
configChanged = true;
if (config_lookup(&_internalDb, CONFIG_VERSION_KEY.c_str()) == NULL) {
// Added separate config version to internal db.
config_setting_t * configVersion = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(configVersion, 2);
} else {
// How???
config_setting_t * configVersion = config_lookup(&_internalDb, CONFIG_VERSION_KEY.c_str());
config_setting_set_int(configVersion, 2);
}
}
if (configChanged) {
config_write_file(&_internalDb, INTERNAL_FILENAME.c_str());
}
}
}

View File

@ -34,7 +34,7 @@ namespace ku {
static std::string getProxy();
static std::string getProxyUsername();
static std::string getProxyPassword();
static int getConfigVersion();
static int getSettingsConfigVersion();
static bool setFilesToIgnore(std::vector<std::string> files);
@ -43,6 +43,7 @@ namespace ku {
static bool getReceivedExFATWarning();
static bool getReceivedIgnoreConfigWarning();
static bool getIgnoreConfigFiles();
static int getInternalConfigVersion();
static bool setCurrentVersion(std::string version);
static bool setInstalledFiles(std::vector<std::string> files);
@ -66,7 +67,9 @@ namespace ku {
static bool _removeSetting(std::string key, config_t config, std::string filename);
static void _migrateConfigFile(int currentVersion);
static void _migrateConfigFiles();
static void _migrateSettingsConfigFiles(int currentVersion);
static void _migrateInternalConfigFiles(int currentVersion);
static inline const std::string CONFIG_FILENAME = "settings.cfg";
static inline const std::string INTERNAL_FILENAME = "internal.db";
@ -91,9 +94,6 @@ namespace ku {
static inline const std::string PROXY_PASSWORD_KEY = "proxy_password";
static inline const std::string PROXY_PASSWORD_DEF = "";
static inline const std::string CONFIG_VERSION_KEY = "config_version";
static inline const int CONFIG_VERSION_DEF = 0;
static inline const std::string VERSION_KEY = "version";
static inline const std::string VERSION_DEF = "";
@ -108,5 +108,9 @@ namespace ku {
static inline const std::string IGNORE_CONFIG_FILES_KEY = "ignore_config_files";
static inline const bool IGNORE_CONFIG_FILES_DEF = false;
static inline const std::string CONFIG_VERSION_KEY = "config_version";
static inline const int CONFIG_VERSION_DEF = 0;
};
}

View File

@ -42,6 +42,7 @@ namespace ku {
size_t result = fwrite(data.c_str(), sizeof(char), data.size(), file);
fflush(file);
fsync(fileno(file));
fclose(file);
return (result == data.size());
@ -60,6 +61,7 @@ namespace ku {
if (file) {
fflush(file);
fsync(fileno(file));
fclose(file);
return true;
}
@ -173,7 +175,7 @@ namespace ku {
void FileManager::applyNoGC() {
Ini * ini = Ini::parseFile(HEKATE_FILE);
for (auto const& section : ini->sections) {
if (section->type == HEKATE_CAPTION || section->type == HASHTAG_COMMENT || section->type == SEMICOLON_COMMENT)
if (section->type != IniSectionType::Section)
continue;
if (section->value == "config") {
@ -187,7 +189,7 @@ namespace ku {
}
if (!patchApplied) {
section->options.push_back(new IniOption("autonogc", "1"));
section->options.push_back(new IniOption(IniOptionType::Option, "autonogc", "1"));
}
break;

View File

@ -165,6 +165,7 @@ namespace ku::scenes {
SessionManager::makeRequest(_appRequest);
}
} else if (request == _appRequest) {
romfsExit();
FileManager::writeFile("KosmosUpdater.nro", request->response.rawResponseBody);
_showStatus("Kosmos Updater has been updated to version " + _appVersionRequest->response.rawResponseBody + "!", "Please restart the app.");
}

View File

@ -15,7 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <Trim.hpp>
#include <SimpleIniParser.hpp>
#include "PackageDownloadScene.hpp"
@ -26,6 +26,7 @@
using namespace ku;
using namespace ku::models;
using namespace ku::views;
using namespace simpleIniParser;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
@ -136,7 +137,7 @@ namespace ku::scenes {
void PackageDownloadScene::_onCompleted(WebRequest * request) {
FileManager::writeFile("temp.zip", request->response.rawResponseBody);
auto versionNumber = request->response.headers.find("X-Version-Number")->second;
rtrim(versionNumber);
IniStringHelper::rtrim(versionNumber);
_updateView->setText("Removing old package...");
_updateView->setProgressBarHidden(true);