Trying to get it to work

This commit is contained in:
Anthony Wang 2020-06-16 17:35:49 -05:00
parent 6082bf80a3
commit 04bbebf459
50 changed files with 438 additions and 668 deletions

View file

@ -45,12 +45,12 @@ INCLUDES := include
ROMFS := romfs
APP_TITLE := Isotope Updater
APP_AUTHOR := FennecTECH,Nichole Mattera
APP_AUTHOR := Nichole Mattera, Ta180m
APP_VERSION := 4.2.1
APP_VERSION_MAJOR := 4
APP_VERSION := 1.2
APP_VERSION_MAJOR := 1
APP_VERSION_MINOR := 2
APP_VERSION_PATCH := 1
# APP_VERSION_PATCH := 0
SETTING_CONFIG_VERSION := 2
INTERNAL_CONFIG_VERSION := 2
@ -64,7 +64,6 @@ DEFINES += -D__SWITCH__ \
-DVERSION=\"$(APP_VERSION)\" \
-DVERSION_MAJOR=$(APP_VERSION_MAJOR) \
-DVERSION_MINOR=$(APP_VERSION_MINOR) \
-DVERSION_PATCH=$(APP_VERSION_PATCH) \
-DSETTING_CONFIG_VERSION=$(SETTING_CONFIG_VERSION) \
-DINTERNAL_CONFIG_VERSION=$(INTERNAL_CONFIG_VERSION)
@ -78,8 +77,9 @@ LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
-Wl,-Map,$(notdir $*.map)
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx -lfreetype -lwebp -lpng -ljpeg \
-ljansson -lSwurl -lcurl -lz -lSimpleIniParser -lminizip -lconfig \
-lnx `sdl2-config --libs` `freetype-config --libs`
-ljansson -lSwurl -lcurl -lz -lmbedtls -lmbedcrypto -lmbedx509 \
-lSimpleIniParser -lminizip -lconfig -lnx `sdl2-config --libs` \
`freetype-config --libs`
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
@ -178,7 +178,6 @@ endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@ -201,6 +200,8 @@ ifeq ($(strip $(APP_JSON)),)
else
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
endif
#---------------------------------------------------------------------------------
else
.PHONY: all

View file

@ -20,7 +20,7 @@
using namespace std;
namespace dsu {
namespace ku {
void AssetManager::dealloc() {
if (AssetManager::large_button_font != NULL)
TTF_CloseFont(AssetManager::large_button_font);

View file

@ -23,7 +23,7 @@
#include <string>
#include <switch.h>
namespace dsu {
namespace ku {
class AssetManager {
public:
/* Textures */

View file

@ -19,7 +19,7 @@
using namespace std;
namespace dsu {
namespace ku {
void ConfigManager::initialize() {
config_init(&_cfg);
config_init(&_internalDb);
@ -36,8 +36,8 @@ namespace dsu {
setting = config_setting_add(root, RECEIVED_EXFAT_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, RECEIVED_EXFAT_WARNING_DEF);
// setting = config_setting_add(root, RECEIVED_IGNORE_CONFIG_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
// config_setting_set_bool(setting, RECEIVED_IGNORE_CONFIG_WARNING_DEF);
setting = config_setting_add(root, RECEIVED_IGNORE_CONFIG_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, RECEIVED_IGNORE_CONFIG_WARNING_DEF);
setting = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, IGNORE_CONFIG_FILES_DEF);
@ -116,10 +116,12 @@ namespace dsu {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _cfg);
}
bool ConfigManager::setFilesToIgnore(vector<string> files) {
return _appendArrayOfStrings(IGNORE_KEY, files, _cfg, CONFIG_FILENAME);
}
string ConfigManager::getCurrentVersion() {
return _readString(VERSION_KEY, VERSION_DEF, _internalDb);
}
@ -133,9 +135,9 @@ namespace dsu {
return _readBoolean(RECEIVED_EXFAT_WARNING_KEY, RECEIVED_EXFAT_WARNING_DEF, _internalDb);
}
// bool ConfigManager::getReceivedIgnoreConfigWarning() {
// return _readBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, RECEIVED_IGNORE_CONFIG_WARNING_DEF, _internalDb);
// }
bool ConfigManager::getReceivedIgnoreConfigWarning() {
return _readBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, RECEIVED_IGNORE_CONFIG_WARNING_DEF, _internalDb);
}
bool ConfigManager::getIgnoreConfigFiles() {
return _readBoolean(IGNORE_CONFIG_FILES_KEY, IGNORE_CONFIG_FILES_DEF, _internalDb);
@ -145,6 +147,7 @@ namespace dsu {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _internalDb);
}
bool ConfigManager::setCurrentVersion(string version) {
return _writeString(VERSION_KEY, version, _internalDb, INTERNAL_FILENAME);
}
@ -157,9 +160,9 @@ namespace dsu {
return _writeBoolean(RECEIVED_EXFAT_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
}
// bool ConfigManager::setReceivedIgnoreConfigWarning(bool received) {
// return _writeBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
// }
bool ConfigManager::setReceivedIgnoreConfigWarning(bool received) {
return _writeBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
}
bool ConfigManager::setIgnoreConfigFiles(bool ignore) {
return _writeBoolean(IGNORE_CONFIG_FILES_KEY, ignore, _internalDb, INTERNAL_FILENAME);

View file

@ -21,7 +21,7 @@
#include <string>
#include <vector>
namespace dsu {
namespace ku {
class ConfigManager {
public:
static void initialize();
@ -40,14 +40,14 @@ namespace dsu {
static std::string getCurrentVersion();
static std::vector<std::string> getInstalledFiles();
static bool getReceivedExFATWarning();
// static bool getReceivedIgnoreConfigWarning();
static bool getReceivedIgnoreConfigWarning();
static bool getIgnoreConfigFiles();
static int getInternalConfigVersion();
static bool setCurrentVersion(std::string version);
static bool setInstalledFiles(std::vector<std::string> files);
static bool setReceivedExFATWarning(bool received);
// static bool setReceivedIgnoreConfigWarning(bool received);
static bool setReceivedIgnoreConfigWarning(bool received);
static bool setIgnoreConfigFiles(bool ignore);
private:
@ -99,8 +99,8 @@ namespace dsu {
static inline const std::string RECEIVED_EXFAT_WARNING_KEY = "received_exfat_warning";
static inline const bool RECEIVED_EXFAT_WARNING_DEF = false;
// static inline const std::string RECEIVED_IGNORE_CONFIG_WARNING_KEY = "received_ignore_config_warning";
// static inline const bool RECEIVED_IGNORE_CONFIG_WARNING_DEF = false;
static inline const std::string RECEIVED_IGNORE_CONFIG_WARNING_KEY = "received_ignore_config_warning";
static inline const bool RECEIVED_IGNORE_CONFIG_WARNING_DEF = false;
static inline const std::string IGNORE_CONFIG_FILES_KEY = "ignore_config_files";
static inline const bool IGNORE_CONFIG_FILES_DEF = false;

View file

@ -17,13 +17,11 @@
#include <algorithm>
#include <dirent.h>
#include <fstream>
#include <SimpleIniParser.hpp>
#include <string.h>
#include <switch.h>
#include <sys/stat.h>
#include <unistd.h>
#include <filesystem>
#include "FileManager.hpp"
@ -31,33 +29,13 @@
using namespace simpleIniParser;
using namespace std;
namespace fs = std::filesystem;
namespace dsu
{
vector<char> FileManager::readFile(string path)
{
ifstream file;
file.open(path, ios::in | ios::binary | ios::ate);
auto size = file.tellg();
file.seekg(0, ios::beg);
vector<char> buffer(size);
file.read(buffer.data(), size);
file.close();
return buffer;
}
// Overwrites a file if it already exists!
bool FileManager::writeFile(string filename, string data)
{
namespace ku {
bool FileManager::writeFile(string filename, string data) {
deleteFile(filename);
FILE *file = fopen(filename.c_str(), "wb");
if (!file)
{
FILE * file = fopen(filename.c_str(), "wb");
if (!file) {
return false;
}
@ -70,155 +48,107 @@ namespace dsu
return (result == data.size());
}
bool FileManager::appendFile(string filename, string data)
{
ofstream file;
// Make sure we are only adding, not overwriting.
file.open(filename, ios_base::app);
if(!file.is_open()) return false;
file << data;
file.close();
return true;
}
bool FileManager::deleteFile(string filename)
{
if (fs::exists(filename))
{
bool FileManager::deleteFile(string filename) {
if (fileExists(filename)) {
return remove(filename.c_str()) == 0;
}
return false;
}
bool FileManager::fileExists(string filename)
{
if(fs::exists(filename)) return true;
bool FileManager::fileExists(string filename) {
FILE * file = fopen(filename.c_str(), "r");
if (file) {
fflush(file);
fsync(fileno(file));
fclose(file);
return true;
}
return false;
}
// This scans all FILES in the given directory and it's respective subdirs.
vector<string> FileManager::scanDirectoryRecursive(string path)
{
vector<string> files;
// First check if the dir even exists.
if(fs::exists(path))
{
// Then make sure it's actually a directory, and not a file. All before
// iterating all of the files in the directory.
if(fs::is_directory(path))
{
for (auto ft : fs::recursive_directory_iterator(path))
{
if(ft.is_directory()) continue;
string path = ft.path().string();
files.push_back(path);
}
}
}
return files;
}
// http://stackoverflow.com/a/11366985
bool FileManager::createSubfolder(string path)
{
bool FileManager::createSubfolder(string path) {
bool bSuccess = false;
int nRC = ::mkdir(path.c_str(), 0775);
if (nRC == -1)
if(nRC == -1)
{
switch (errno)
switch(errno)
{
case ENOENT:
//parent didn't exist, try to create it
if (createSubfolder(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
case ENOENT:
//parent didn't exist, try to create it
if(createSubfolder(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
break;
}
}
else
bSuccess = true;
return bSuccess;
}
bool FileManager::extract(string zipFilename, string destination)
{
bool FileManager::extract(string zipFilename, string destination) {
unzFile unz = unzOpen(zipFilename.c_str());
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
vector<string> filesInstalled = ConfigManager::getInstalledFiles();
int i = 0;
for (;;)
{
for (;;) {
int code;
if (i == 0)
{
if (i == 0) {
code = unzGoToFirstFile(unz);
}
else
{
} else {
code = unzGoToNextFile(unz);
}
i++;
if (code == UNZ_END_OF_LIST_OF_FILE)
{
if (code == UNZ_END_OF_LIST_OF_FILE) {
break;
}
else
{
} else {
unz_file_pos pos;
unzGetFilePos(unz, &pos);
}
unz_file_info_s *fileInfo = _getFileInfo(unz);
unz_file_info_s * fileInfo = _getFileInfo(unz);
string filename = destination;
filename += _getFullFileName(unz, fileInfo);
if (find(begin(filesToIgnore), end(filesToIgnore), filename) != end(filesToIgnore))
{
if (find(begin(filesToIgnore), end(filesToIgnore), filename) != end(filesToIgnore)) {
free(fileInfo);
continue;
}
// No need to extract Hekate's payload.
if (filename.compare(0, 12, "sdmc:/hekate") == 0 && filename.compare(filename.length() - 4, 4, ".bin") == 0)
{
if (filename.compare(0, 12, "sdmc:/hekate") == 0 && filename.compare(filename.length() - 4, 4, ".bin") == 0) {
free(fileInfo);
continue;
}
// No need to extract Isotope Updater.
if (filename.compare(0, 29, "sdmc:/switch/Isotope-Updater/") == 0)
{
if (filename.compare(0, 27, "sdmc:/switch/IsotopeUpdater/") == 0) {
free(fileInfo);
continue;
}
if (filename.back() != '/')
{
if (filename.back() != '/') {
filesInstalled.push_back(filename);
int result = _extractFile(filename.c_str(), unz, fileInfo);
if (result < 0)
{
if (result < 0) {
free(fileInfo);
unzClose(unz);
return false;
@ -228,8 +158,7 @@ namespace dsu
free(fileInfo);
}
if (i <= 0)
{
if (i <= 0) {
unzClose(unz);
return false;
}
@ -239,15 +168,12 @@ namespace dsu
return true;
}
void FileManager::cleanUpFiles()
{
void FileManager::cleanUpFiles() {
vector<string> installedFiles = ConfigManager::getInstalledFiles();
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
for (auto const &fileName : installedFiles)
{
if (find(begin(filesToIgnore), end(filesToIgnore), fileName) != end(filesToIgnore))
{
for (auto const& fileName : installedFiles) {
if (find(begin(filesToIgnore), end(filesToIgnore), fileName) != end(filesToIgnore)) {
continue;
}
@ -258,29 +184,23 @@ namespace dsu
ConfigManager::setInstalledFiles(blankVector);
}
void FileManager::applyNoGC()
{
Ini *ini = Ini::parseFile(HEKATE_FILE);
for (auto const &section : ini->sections)
{
void FileManager::applyNoGC() {
Ini * ini = Ini::parseFile(HEKATE_FILE);
for (auto const& section : ini->sections) {
if (section->type != IniSectionType::Section)
continue;
if (section->value == "config")
{
if (section->value == "config") {
bool patchApplied = false;
for (auto const &option : section->options)
{
if (option->key == "autonogc")
{
for (auto const& option : section->options) {
if (option->key == "autonogc") {
option->value = "1";
patchApplied = true;
break;
}
}
if (!patchApplied)
{
if (!patchApplied) {
section->options.push_back(new IniOption(IniOptionType::Option, "autonogc", "1"));
}
@ -292,20 +212,18 @@ namespace dsu
delete ini;
}
unz_file_info_s *FileManager::_getFileInfo(unzFile unz)
{
unz_file_info_s *fileInfo = (unz_file_info_s *)malloc(sizeof(unz_file_info_s));
unz_file_info_s * FileManager::_getFileInfo(unzFile unz) {
unz_file_info_s * fileInfo = (unz_file_info_s*) malloc(sizeof(unz_file_info_s));
unzGetCurrentFileInfo(unz, fileInfo, NULL, 0, NULL, 0, NULL, 0);
return fileInfo;
}
string FileManager::_getFullFileName(unzFile unz, unz_file_info_s *fileInfo)
{
string FileManager::_getFullFileName(unzFile unz, unz_file_info_s * fileInfo) {
char filePath[fileInfo->size_filename + 1];
unzGetCurrentFileInfo(unz, fileInfo, filePath, fileInfo->size_filename, NULL, 0, NULL, 0);
filePath[fileInfo->size_filename] = '\0';
string path(filePath);
path.resize(fileInfo->size_filename);
@ -316,88 +234,82 @@ namespace dsu
{
bool bSuccess = false;
int nRC = ::mkdir(path.c_str(), 0775);
if (nRC == -1)
if(nRC == -1)
{
switch (errno)
switch(errno)
{
case ENOENT:
//parent didn't exist, try to create it
if (_makeDirectoryParents(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
case ENOENT:
//parent didn't exist, try to create it
if( _makeDirectoryParents(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
break;
}
}
else
bSuccess = true;
return bSuccess;
}
int FileManager::_extractFile(const char *path, unzFile unz, unz_file_info_s *fileInfo)
{
int FileManager::_extractFile(const char * path, unzFile unz, unz_file_info_s * fileInfo) {
//check to make sure filepath or fileInfo isnt null
if (path == NULL || fileInfo == NULL)
return -1;
if (unzOpenCurrentFile(unz) != UNZ_OK)
return -2;
char folderPath[strlen(path) + 1];
strcpy(folderPath, path);
char *pos = strrchr(folderPath, '/');
if (pos != NULL)
{
char * pos = strrchr(folderPath, '/');
if (pos != NULL) {
*pos = '\0';
_makeDirectoryParents(string(folderPath));
}
u32 blocksize = 0x8000;
u8 *buffer = (u8 *)malloc(blocksize);
u8 * buffer = (u8*) malloc(blocksize);
if (buffer == NULL)
return -3;
u32 done = 0;
int writeBytes = 0;
FILE *fp = fopen(path, "w");
if (fp == NULL)
{
FILE * fp = fopen(path, "w");
if (fp == NULL) {
free(buffer);
return -4;
return -4;
}
while (done < fileInfo->uncompressed_size)
{
if (done + blocksize > fileInfo->uncompressed_size)
{
while (done < fileInfo->uncompressed_size) {
if (done + blocksize > fileInfo->uncompressed_size) {
blocksize = fileInfo->uncompressed_size - done;
}
unzReadCurrentFile(unz, buffer, blocksize);
writeBytes = write(fileno(fp), buffer, blocksize);
if (writeBytes <= 0)
{
if (writeBytes <= 0) {
break;
}
done += writeBytes;
}
fflush(fp);
fsync(fileno(fp));
fclose(fp);
free(buffer);
if (done != fileInfo->uncompressed_size)
return -4;
return -4;
unzCloseCurrentFile(unz);
return 0;
}
} // namespace dsu
}

View file

@ -21,15 +21,12 @@
#include <string>
#include <vector>
namespace dsu {
namespace ku {
class FileManager {
public:
static std::vector<char> readFile(std::string path);
static bool writeFile(std::string filename, std::string data);
static bool deleteFile(std::string filename);
static bool appendFile(std::string filename, std::string data);
static bool fileExists(std::string filename);
static std::vector<std::string> scanDirectoryRecursive(std::string path);
static bool createSubfolder(std::string path);
static bool extract(std::string filename, std::string destination);
static void cleanUpFiles();

View file

@ -18,7 +18,7 @@
#include "ModalView.hpp"
#include "SceneDirector.hpp"
namespace dsu {
namespace ku {
void ModalView::show() {
SceneDirector::modal = this;
}

View file

@ -24,8 +24,8 @@
#include "View.hpp"
namespace dsu {
class ModalView : public dsu::View {
namespace ku {
class ModalView : public ku::View {
public:
std::function<void(ModalView *, bool)> onDismiss;

View file

@ -17,7 +17,7 @@
#include "Scene.hpp"
namespace dsu {
namespace ku {
Scene::Scene() {
_touchedView = NULL;
}

View file

@ -23,7 +23,7 @@
#include "View.hpp"
namespace dsu {
namespace ku {
class Scene {
public:
Scene();

View file

@ -21,12 +21,10 @@
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"
using namespace dsu::scenes;
using namespace ku::scenes;
namespace dsu
{
SceneDirector::SceneDirector()
{
namespace ku {
SceneDirector::SceneDirector() {
currentSceneDirector = this;
romfsInit();
@ -56,18 +54,15 @@ namespace dsu
_packageDownloadScene = NULL;
_currentScene = NULL;
if (!ConfigManager::getReceivedExFATWarning())
{
if (!ConfigManager::getReceivedExFATWarning()) {
currentScene = SCENE_EXFAT_WARNING;
}
else if (!ConfigManager::shouldAutoUpdate())
{
else if (!ConfigManager::shouldAutoUpdate()) {
currentScene = SCENE_PACKAGE_SELECT;
}
}
SceneDirector::~SceneDirector()
{
SceneDirector::~SceneDirector() {
if (_exFatWarningScene != NULL)
delete _exFatWarningScene;
@ -96,8 +91,7 @@ namespace dsu
romfsExit();
}
bool SceneDirector::direct()
{
bool SceneDirector::direct() {
double dTime = _getDeltaTime();
hidScanInput();
@ -106,120 +100,107 @@ namespace dsu
// TODO: Handle touch controls
// Unload previous scenes
switch (SceneDirector::currentScene)
{
case SCENE_APP_UPDATE:
if (_exFatWarningScene != NULL)
{
delete _exFatWarningScene;
_exFatWarningScene = NULL;
}
break;
switch(SceneDirector::currentScene) {
case SCENE_APP_UPDATE:
if (_exFatWarningScene != NULL) {
delete _exFatWarningScene;
_exFatWarningScene = NULL;
}
break;
case SCENE_PACKAGE_SELECT:
if (_appUpdateScene != NULL)
{
delete _appUpdateScene;
_appUpdateScene = NULL;
}
break;
case SCENE_PACKAGE_SELECT:
if (_appUpdateScene != NULL) {
delete _appUpdateScene;
_appUpdateScene = NULL;
}
break;
case SCENE_PACKAGE_DOWNLOAD:
if (_appUpdateScene != NULL)
{
delete _appUpdateScene;
_appUpdateScene = NULL;
}
case SCENE_PACKAGE_DOWNLOAD:
if (_appUpdateScene != NULL) {
delete _appUpdateScene;
_appUpdateScene = NULL;
}
if (_packageSelectScene != NULL)
{
delete _packageSelectScene;
_packageSelectScene = NULL;
}
break;
if (_packageSelectScene != NULL) {
delete _packageSelectScene;
_packageSelectScene = NULL;
}
break;
default:
/* Do Nothing */
break;
default:
/* Do Nothing */
break;
}
// Load new scenes
switch (SceneDirector::currentScene)
{
case SCENE_EXFAT_WARNING:
if (_exFatWarningScene == NULL)
_exFatWarningScene = new ExFatWarningScene();
switch(SceneDirector::currentScene) {
case SCENE_EXFAT_WARNING:
if (_exFatWarningScene == NULL)
_exFatWarningScene = new ExFatWarningScene();
_currentScene = _exFatWarningScene;
break;
_currentScene = _exFatWarningScene;
break;
case SCENE_APP_UPDATE:
if (_appUpdateScene == NULL)
_appUpdateScene = new AppUpdateScene();
case SCENE_APP_UPDATE:
if (_appUpdateScene == NULL)
_appUpdateScene = new AppUpdateScene();
_currentScene = _appUpdateScene;
break;
_currentScene = _appUpdateScene;
break;
case SCENE_PACKAGE_SELECT:
if (_packageSelectScene == NULL)
_packageSelectScene = new PackageSelectScene();
_currentScene = _packageSelectScene;
break;
case SCENE_PACKAGE_SELECT:
if (_packageSelectScene == NULL)
_packageSelectScene = new PackageSelectScene();
_currentScene = _packageSelectScene;
break;
case SCENE_PACKAGE_DOWNLOAD:
if (_packageDownloadScene == NULL)
_packageDownloadScene = new PackageDownloadScene();
_currentScene = _packageDownloadScene;
break;
case SCENE_PACKAGE_DOWNLOAD:
if (_packageDownloadScene == NULL)
_packageDownloadScene = new PackageDownloadScene();
_currentScene = _packageDownloadScene;
break;
}
if (modal != NULL)
{
if (modal != NULL) {
modal->handleButton(kDown, dTime);
}
else
{
} else {
_currentScene->handleButton(kDown, dTime);
}
_render(dTime);
return !SceneDirector::exitApp;
}
void SceneDirector::render()
{
void SceneDirector::render() {
double dTime = _getDeltaTime();
_render(dTime);
}
double SceneDirector::_getDeltaTime()
{
double SceneDirector::_getDeltaTime() {
_last = _now;
_now = SDL_GetPerformanceCounter();
return (double)((_now - _last) * 1000 / SDL_GetPerformanceFrequency());
return (double) ((_now - _last) * 1000 / SDL_GetPerformanceFrequency());
}
void SceneDirector::_render(double dTime)
{
void SceneDirector::_render(double dTime) {
AssetManager::setRenderColor(AssetManager::background);
SDL_RenderClear(SceneDirector::renderer);
_currentScene->render({0, 0, 1280, 720}, dTime);
_currentScene->render({ 0, 0, 1280, 720 }, dTime);
if (modal != NULL)
{
if (modal != NULL) {
// Draw Faded background.
AssetManager::setRenderColor(AssetManager::modal_faded_background);
SDL_Rect fadedBGFrame = {0, 0, 1280, 720};
SDL_Rect fadedBGFrame = { 0, 0, 1280, 720 };
SDL_SetRenderDrawBlendMode(SceneDirector::renderer, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(SceneDirector::renderer, &fadedBGFrame);
modal->render({0, 0, 1280, 720}, dTime);
modal->render({ 0, 0, 1280, 720 }, dTime);
}
SDL_RenderPresent(SceneDirector::renderer);
}
} // namespace dsu
}

View file

@ -26,7 +26,7 @@
#include "scenes/PackageDownloadScene.hpp"
#include "scenes/PackageSelectScene.hpp"
namespace dsu {
namespace ku {
typedef enum {
SCENE_EXFAT_WARNING,
SCENE_APP_UPDATE,

View file

@ -17,7 +17,7 @@
#include "View.hpp"
namespace dsu {
namespace ku {
View::View() {
frame = { 0, 0, 0, 0 };
hidden = false;

View file

@ -20,7 +20,7 @@
#include <list>
#include <SDL2/SDL.h>
namespace dsu {
namespace ku {
class View {
public:
SDL_Rect frame;

View file

@ -20,21 +20,22 @@
#include <switch.h>
#include <Swurl.hpp>
#include "FileManager.hpp"
#include "AssetManager.hpp"
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
using namespace swurl;
int main(int argc, char **argv)
{
SessionManager::initialize();
SessionManager::userAgent = string("Isotope-updater/") + VERSION;
SessionManager::userAgent = string("isotope-updater/") + VERSION;
nxlinkStdio();
#ifdef DEBUG
nxlinkStdio();
#endif
ConfigManager::initialize();

View file

@ -19,7 +19,7 @@
using namespace std;
namespace dsu::models {
namespace ku::models {
Action::Action(ActionButton actionButton, string actionText) {
button = actionButton;
text = actionText;

View file

@ -20,7 +20,7 @@
#include <SDL2/SDL.h>
#include <string>
namespace dsu::models {
namespace ku::models {
typedef enum {
A_BUTTON,
B_BUTTON,

View file

@ -17,5 +17,5 @@
#include "Touch.hpp"
namespace dsu::models {
namespace ku::models {
}

View file

@ -17,7 +17,7 @@
#pragma once
namespace dsu::models {
namespace ku::models {
class Touch {
};
}

View file

@ -23,23 +23,21 @@
#include "../FileManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
using namespace ku;
using namespace ku::models;
using namespace ku::views;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes
{
AppUpdateScene::AppUpdateScene()
{
namespace ku::scenes {
AppUpdateScene::AppUpdateScene() {
SessionManager::onProgressChanged = bind(&AppUpdateScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&AppUpdateScene::_onCompleted, this, _1);
SessionManager::onError = bind(&AppUpdateScene::_onError, this, _1, _2);
_headerView = new HeaderView("Isotope Updater", true);
_headerView->frame = {0, 0, 1280, 88};
_headerView->frame = { 0, 0, 1280, 88 };
_updateView = new UpdateView("Checking for updates to Isotope Updater...");
_updateView->frame.x = 0;
@ -51,7 +49,7 @@ namespace dsu::scenes
_statusView->hidden = true;
_footerView = new FooterView();
_footerView->frame = {0, 647, 1280, 73};
_footerView->frame = { 0, 647, 1280, 73 };
addSubView(_headerView);
addSubView(_updateView);
@ -59,8 +57,7 @@ namespace dsu::scenes
addSubView(_footerView);
}
AppUpdateScene::~AppUpdateScene()
{
AppUpdateScene::~AppUpdateScene() {
if (_headerView != NULL)
delete _headerView;
@ -80,19 +77,15 @@ namespace dsu::scenes
delete _appRequest;
}
void AppUpdateScene::handleButton(u32 buttons, double dTime)
{
if (!_statusView->hidden && buttons & KEY_A)
{
void AppUpdateScene::handleButton(u32 buttons, double dTime) {
if (!_statusView->hidden && buttons & KEY_A) {
SceneDirector::exitApp = true;
}
}
void AppUpdateScene::render(SDL_Rect rect, double dTime)
{
if (_appVersionRequest == NULL)
{
_appVersionRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope-Updater/releases");
void AppUpdateScene::render(SDL_Rect rect, double dTime) {
if (_appVersionRequest == NULL) {
_appVersionRequest = new WebRequest("http://api.github.com/repos/Ta180m/Isotope-Updater/releases");
SessionManager::makeRequest(_appVersionRequest);
}
@ -100,8 +93,7 @@ namespace dsu::scenes
Scene::render(rect, dTime);
}
void AppUpdateScene::_showStatus(string text, string subtext)
{
void AppUpdateScene::_showStatus(string text, string subtext) {
_statusView->setText(text);
_statusView->setSubtext(subtext);
@ -111,14 +103,11 @@ namespace dsu::scenes
_footerView->actions.push_back(new Action(A_BUTTON, "Quit"));
}
std::string AppUpdateScene::_sanitizeVersion(std::string version)
{
std::string AppUpdateScene::_sanitizeVersion(std::string version) {
std::string result = "";
for (char &c : version)
{
if ((c >= '0' && c <= '9') || c == '.')
{
for (char& c : version) {
if ((c >= '0' && c <= '9') || c == '.') {
result += c;
}
}
@ -126,37 +115,27 @@ namespace dsu::scenes
return result;
}
tuple<int, int, int> AppUpdateScene::_parseVersion(string version)
{
tuple<int, int, int> AppUpdateScene::_parseVersion(string version) {
size_t pos = 0;
int index = 0, major = 0, minor = 0, patch = 0;
while (pos != string::npos)
{
while (pos != string::npos) {
size_t end_pos = version.find(".", pos);
int versionNumber = 0;
if (end_pos == string::npos)
{
if (end_pos == string::npos) {
versionNumber = stoi(version.substr(pos, string::npos));
pos = string::npos;
}
else
{
} else {
versionNumber = stoi(version.substr(pos, end_pos - pos));
pos = end_pos + 1;
}
if (index == 0)
{
if (index == 0) {
major = versionNumber;
}
else if (index == 1)
{
} else if (index == 1) {
minor = versionNumber;
}
else if (index == 2)
{
} else if (index == 2) {
patch = versionNumber;
break;
}
@ -169,34 +148,28 @@ namespace dsu::scenes
// Swurl Callback Methods
void AppUpdateScene::_onProgressUpdate(WebRequest *request, double progress)
{
void AppUpdateScene::_onProgressUpdate(WebRequest * request, double progress) {
_downloadProgess = progress;
SceneDirector::currentSceneDirector->render();
}
void AppUpdateScene::_onCompleted(WebRequest *request)
{
if (request == _appVersionRequest)
{
json_t *root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1)
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[4]");
void AppUpdateScene::_onCompleted(WebRequest * request) {
if (request == _appVersionRequest) {
json_t * root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1) {
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
json_t *release = json_array_get(root, 0);
if (!release || !json_is_object(release))
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[5]");
json_t * release = json_array_get(root, 0);
if (!release || !json_is_object(release)) {
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
json_t *tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName))
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[6]");
json_t * tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName)) {
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
@ -206,9 +179,8 @@ namespace dsu::scenes
if (
VERSION_MAJOR > get<0>(latestVersion) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR > get<1>(latestVersion)) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR == get<1>(latestVersion) && VERSION_PATCH > get<2>(latestVersion)) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR == get<1>(latestVersion) && VERSION_PATCH == get<2>(latestVersion)))
{
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR == get<1>(latestVersion))
) {
json_decref(root);
SessionManager::onProgressChanged = NULL;
@ -218,39 +190,32 @@ namespace dsu::scenes
SceneDirector::currentScene = SCENE_PACKAGE_SELECT;
}
// Update
else
{
json_t *assets = json_object_get(release, "assets");
if (!assets || !json_is_array(assets) || json_array_size(assets) < 1)
{
else {
json_t * assets = json_object_get(release, "assets");
if (!assets || !json_is_array(assets) || json_array_size(assets) < 1) {
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
std::string downloadUrl = "";
for (size_t i = 0; i < json_array_size(assets); i++)
{
json_t *asset = json_array_get(assets, i);
if (!asset || !json_is_object(asset))
{
for(size_t i = 0; i < json_array_size(assets); i++) {
json_t * asset = json_array_get(assets, i);
if (!asset || !json_is_object(asset)) {
continue;
}
json_t *name = json_object_get(asset, "name");
if (!name || !json_is_string(name))
{
json_t * name = json_object_get(asset, "name");
if (!name || !json_is_string(name)) {
continue;
}
std::string assetName(json_string_value(name));
if (assetName.compare(assetName.length() - 4, 4, ".nro") != 0)
{
if (assetName.compare(assetName.length() - 4, 4, ".nro") != 0) {
continue;
}
json_t *browserDownloadUrl = json_object_get(asset, "browser_download_url");
if (!browserDownloadUrl || !json_is_string(browserDownloadUrl))
{
json_t * browserDownloadUrl = json_object_get(asset, "browser_download_url");
if (!browserDownloadUrl || !json_is_string(browserDownloadUrl)) {
continue;
}
@ -260,8 +225,7 @@ namespace dsu::scenes
json_decref(root);
if (downloadUrl.length() == 0)
{
if (downloadUrl.length() == 0) {
_showStatus("Unable to find the latest release assets.", "Please restart the app to try again.");
return;
}
@ -272,17 +236,14 @@ namespace dsu::scenes
_appRequest = new WebRequest(downloadUrl);
SessionManager::makeRequest(_appRequest);
}
}
else if (request == _appRequest)
{
} else if (request == _appRequest) {
romfsExit();
FileManager::writeFile("Isotope-Updater.nro", request->response.rawResponseBody);
FileManager::writeFile("IsotopeUpdater.nro", request->response.rawResponseBody);
_showStatus("Isotope Updater has been updated to version " + _appVersionRequest->response.rawResponseBody + "!", "Please restart the app.");
}
}
void AppUpdateScene::_onError(WebRequest *request, string error)
{
void AppUpdateScene::_onError(WebRequest * request, string error) {
_showStatus(error, "Please restart the app to try again.");
}
} // namespace dsu::scenes
}

View file

@ -27,8 +27,8 @@
#include "../views/StatusView.hpp"
#include "../views/UpdateView.hpp"
namespace dsu::scenes {
class AppUpdateScene : public dsu::Scene {
namespace ku::scenes {
class AppUpdateScene : public ku::Scene {
public:
AppUpdateScene();
~AppUpdateScene();
@ -37,10 +37,10 @@ namespace dsu::scenes {
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::FooterView * _footerView = NULL;
ku::views::HeaderView * _headerView = NULL;
ku::views::UpdateView * _updateView = NULL;
ku::views::StatusView * _statusView = NULL;
ku::views::FooterView * _footerView = NULL;
swurl::WebRequest * _appVersionRequest = NULL;
swurl::WebRequest * _appRequest = NULL;

View file

@ -21,10 +21,10 @@
#include "../ConfigManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::views;
using namespace ku;
using namespace ku::views;
namespace dsu::scenes {
namespace ku::scenes {
ExFatWarningScene::ExFatWarningScene() {
_timeSpent = -10000;
_footerVisible = false;

View file

@ -22,8 +22,8 @@
#include "../Scene.hpp"
#include "../views/TextView.hpp"
namespace dsu::scenes {
class ExFatWarningScene : public dsu::Scene {
namespace ku::scenes {
class ExFatWarningScene : public ku::Scene {
public:
ExFatWarningScene();
~ExFatWarningScene();
@ -35,8 +35,8 @@ namespace dsu::scenes {
double _timeSpent;
bool _footerVisible;
dsu::views::TextView * _headerTextView;
dsu::views::TextView * _bodyTextView;
dsu::views::TextView * _footerTextView;
ku::views::TextView * _headerTextView;
ku::views::TextView * _bodyTextView;
ku::views::TextView * _footerTextView;
};
}

View file

@ -15,7 +15,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <cstring>
#include <jansson.h>
#include <SimpleIniParser.hpp>
@ -25,21 +24,15 @@
#include "../FileManager.hpp"
#include "../SceneDirector.hpp"
#define IRAM_PAYLOAD_MAX_SIZE 0x2F000
#define IRAM_PAYLOAD_BASE 0x40010000
static __attribute__((aligned(0x1000))) u8 g_ff_page[0x1000];
static __attribute__((aligned(0x1000))) u8 g_work_page[0x1000];
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
using namespace ku;
using namespace ku::models;
using namespace ku::views;
using namespace simpleIniParser;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes {
namespace ku::scenes {
PackageDownloadScene::PackageDownloadScene() {
SessionManager::onProgressChanged = bind(&PackageDownloadScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&PackageDownloadScene::_onCompleted, this, _1);
@ -87,11 +80,11 @@ namespace dsu::scenes {
if (_footerView != NULL)
delete _footerView;
if (_IsotopeUrlRequest != NULL)
delete _IsotopeUrlRequest;
if (_isotopeUrlRequest != NULL)
delete _isotopeUrlRequest;
if (_IsotopeRequest != NULL)
delete _IsotopeRequest;
if (_isotopeRequest != NULL)
delete _isotopeRequest;
bpcExit();
}
@ -108,35 +101,14 @@ namespace dsu::scenes {
}
void PackageDownloadScene::render(SDL_Rect rect, double dTime) {
if (_IsotopeUrlRequest == NULL) {
_IsotopeUrlRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope/releases");
SessionManager::makeRequest(_IsotopeUrlRequest);
if (_isotopeUrlRequest == NULL) {
_isotopeUrlRequest = new WebRequest("http://api.github.com/repos/Ta180m/Isotope/releases");
SessionManager::makeRequest(_isotopeUrlRequest);
}
Scene::render(rect, dTime);
}
void PackageDownloadScene::_copyToIram(uintptr_t iram_addr, void *buf, size_t size) {
memcpy(g_work_page, buf, size);
SecmonArgs args = {0};
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
args.X[2] = iram_addr; /* IRAM Address */
args.X[3] = size; /* Copy size */
args.X[4] = 1;
svcCallSecureMonitor(&args);
memcpy(buf, g_work_page, size);
}
void PackageDownloadScene::_clearIram() {
memset(g_ff_page, 0xFF, sizeof(g_ff_page));
for(size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += sizeof(g_ff_page)) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, g_ff_page, sizeof(g_ff_page));
}
}
void PackageDownloadScene::_showStatus(string text, string subtext, bool wasSuccessful) {
_statusView->setText(text);
_statusView->setSubtext(subtext);
@ -153,26 +125,7 @@ namespace dsu::scenes {
void PackageDownloadScene::_onAlertViewDismiss(ModalView * view, bool success) {
if (success) {
if (_restartAlertView->getSelectedOption() == 0) {
auto payload = FileManager::readFile("sdmc:/bootloader/update.bin");
if (payload.size() == 0) {
SceneDirector::exitApp = true;
return;
}
Result rc = splInitialize();
if (R_FAILED(rc)) {
SceneDirector::exitApp = true;
return;
}
this->_clearIram();
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, &payload[i], 0x1000);
}
splSetConfig((SplConfigItem) 65001, 2);
splExit();
bpcRebootSystem();
}
else {
SceneDirector::exitApp = true;
@ -186,37 +139,37 @@ namespace dsu::scenes {
}
void PackageDownloadScene::_onCompleted(WebRequest * request) {
if (request == _IsotopeUrlRequest) {
if (request == _isotopeUrlRequest) {
json_t * root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1) {
if (root) {
json_decref(root);
}
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[7]", false);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.", false);
return;
}
json_t * release = json_array_get(root, 0);
if (!release || !json_is_object(release)) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[8]", false);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.", false);
return;
}
json_t * tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName)) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[9]", false);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.", false);
return;
}
_IsotopeVersion = json_string_value(tagName);
_isotopeVersion = json_string_value(tagName);
json_t * assets = json_object_get(release, "assets");
if (!assets || !json_is_array(assets) || json_array_size(assets) < 1) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[10]", false);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.", false);
return;
}
@ -233,7 +186,7 @@ namespace dsu::scenes {
}
std::string assetName(json_string_value(name));
if (assetName.compare(0, 8, "isotope_") != 0 || assetName.compare(assetName.length() - 4, 4, ".zip") != 0) {
if (assetName.compare(0, 6, "Isotope") != 0 || assetName.compare(assetName.length() - 4, 4, ".zip") != 0) {
continue;
}
@ -253,8 +206,8 @@ namespace dsu::scenes {
return;
}
_IsotopeRequest = new WebRequest(downloadUrl);
SessionManager::makeRequest(_IsotopeRequest);
_isotopeRequest = new WebRequest(downloadUrl);
SessionManager::makeRequest(_isotopeRequest);
} else {
FileManager::writeFile("temp.zip", request->response.rawResponseBody);
@ -274,14 +227,14 @@ namespace dsu::scenes {
}
FileManager::deleteFile("temp.zip");
ConfigManager::setCurrentVersion(_IsotopeVersion);
ConfigManager::setCurrentVersion(_isotopeVersion);
_updateView->setText("Applying disabled game cart option...");
SceneDirector::currentSceneDirector->render();
FileManager::applyNoGC();
_showStatus("Isotope has been updated to version " + _IsotopeVersion + "!", "Please restart your Switch to finish the update.", true);
_showStatus("Isotope has been updated to version " + _isotopeVersion + "!", "Please restart your Switch to finish the update.", true);
}
}

View file

@ -28,8 +28,8 @@
#include "../views/StatusView.hpp"
#include "../views/UpdateView.hpp"
namespace dsu::scenes {
class PackageDownloadScene : public dsu::Scene {
namespace ku::scenes {
class PackageDownloadScene : public ku::Scene {
public:
PackageDownloadScene();
~PackageDownloadScene();
@ -38,22 +38,19 @@ namespace dsu::scenes {
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::FooterView * _footerView = NULL;
dsu::views::AlertView * _restartAlertView = NULL;
ku::views::HeaderView * _headerView = NULL;
ku::views::UpdateView * _updateView = NULL;
ku::views::StatusView * _statusView = NULL;
ku::views::FooterView * _footerView = NULL;
ku::views::AlertView * _restartAlertView = NULL;
std::string _IsotopeVersion = "";
std::string _isotopeVersion = "";
swurl::WebRequest * _IsotopeUrlRequest = NULL;
swurl::WebRequest * _IsotopeRequest = NULL;
void _copyToIram(uintptr_t iram_addr, void *buf, size_t size);
void _clearIram();
swurl::WebRequest * _isotopeUrlRequest = NULL;
swurl::WebRequest * _isotopeRequest = NULL;
void _showStatus(std::string text, std::string subtext, bool wasSuccessful);
void _onAlertViewDismiss(dsu::ModalView * view, bool success);
void _onAlertViewDismiss(ku::ModalView * view, bool success);
std::string _getVersionNumber(std::string version);
void _onProgressUpdate(swurl::WebRequest * request, double progress);

View file

@ -21,25 +21,24 @@
#include "../ConfigManager.hpp"
#include "../SceneDirector.hpp"
#include "../FileManager.hpp"
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
string elem[120] = { "","Hydrogen","Helium","Lithium","Beryllium","Boron","Carbon","Nitrogen","Oxygen","Fluorine","Neon","Sodium","Magnesium","Aluminium","Silicon","Phosphorus","Sulfur","Chlorine","Argon","Potassium","Calcium","Scandium","Titanium","Vanadium","Chromium","Manganese","Iron","Cobalt","Nickel","Copper","Zinc","Gallium","Germanium","Arsenic","Selenium","Bromine","Krypton","Rubidium","Strontium","Yttrium","Zirconium","Niobium","Molybdenum","Technetium","Ruthenium","Rhodium","Palladium","Silver","Cadmium","Indium","Tin","Antimony","Tellurium","Iodine","Xenon","Caesium","Barium","Lanthanum","Cerium","Praseodymium","Neodymium","Promethium","Samarium","Europium","Gadolinium","Terbium","Dysprosium","Holmium","Erbium","Thulium","Ytterbium","Lutetium","Hafnium","Tantalum","Tungsten","Rhenium","Osmium","Iridium","Platinum","Gold","Mercury","Thallium","Lead","Bismuth","Polonium","Astatine","Radon","Francium","Radium","Actinium","Thorium","Protactinium","Uranium","Neptunium","Plutonium","Americium","Curium","Berkelium","Californium","Einsteinium","Fermium","Mendelevium","Nobelium","Lawrencium","Rutherfordium","Dubnium","Seaborgium","Bohrium","Hassium","Meitnerium","Darmstadtium","Roentgenium","Copernicium","Nihonium","Flerovium","Moscovium","Livermorium","Tennessine","Oganesson" };
using namespace ku;
using namespace ku::models;
using namespace ku::views;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes
{
PackageSelectScene::PackageSelectScene()
{
namespace ku::scenes {
PackageSelectScene::PackageSelectScene() {
SessionManager::onProgressChanged = bind(&PackageSelectScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&PackageSelectScene::_onCompleted, this, _1);
SessionManager::onError = bind(&PackageSelectScene::_onError, this, _1, _2);
_headerView = new HeaderView("Isotope Updater", true);
_headerView->frame = {0, 0, 1280, 88};
_headerView->frame = { 0, 0, 1280, 88 };
_updateView = new UpdateView("Checking for updates to Isotope...");
_updateView->frame.x = 0;
@ -56,12 +55,12 @@ namespace dsu::scenes
_installRowView->hasFocus = true;
_footerView = new FooterView();
_footerView->frame = {0, 647, 1280, 73};
_footerView->frame = { 0, 647, 1280, 73 };
vector<string> buttons;
buttons.push_back("Yes");
buttons.push_back("No");
_ignoreConfigsAlertView = new AlertView("Ignore Config Files?", "Would you like for Isotope Updater to ignore config\nfiles? This will prevent Isotope Updater from overwriting\nall config files except for Hekate's main config file, and save the\nignored files for next time as well.", buttons);
_ignoreConfigsAlertView = new AlertView("Ignore Config Files?", "Would you like for Isotope Updater to ignore config\nfiles? This will prevent Isotope Updater from overwriting\nall config files except for Hekate's main config file.", buttons);
_ignoreConfigsAlertView->onDismiss = bind(&PackageSelectScene::_onAlertViewDismiss, this, _1, _2);
addSubView(_headerView);
@ -73,8 +72,7 @@ namespace dsu::scenes
_showUpdateView();
}
PackageSelectScene::~PackageSelectScene()
{
PackageSelectScene::~PackageSelectScene() {
if (_headerView != NULL)
delete _headerView;
@ -90,63 +88,52 @@ namespace dsu::scenes
if (_footerView != NULL)
delete _footerView;
if (_IsotopeVersionRequest != NULL)
delete _IsotopeVersionRequest;
if (_isotopeVersionRequest != NULL)
delete _isotopeVersionRequest;
}
void PackageSelectScene::handleButton(u32 buttons, double dTime)
{
if (!_statusView->hidden && buttons & KEY_A)
{
void PackageSelectScene::handleButton(u32 buttons, double dTime) {
if (!_statusView->hidden && buttons & KEY_A) {
SceneDirector::exitApp = true;
}
else if (_updateView->hidden && _statusView->hidden)
{
if (buttons & KEY_A)
{
else if (_updateView->hidden && _statusView->hidden) {
if (buttons & KEY_A) {
SceneDirector::currentScene = SCENE_PACKAGE_DOWNLOAD;
}
if (buttons & KEY_B)
{
if (buttons & KEY_B) {
SceneDirector::exitApp = true;
}
}
}
void PackageSelectScene::render(SDL_Rect rect, double dTime)
{
if (_IsotopeVersionRequest == NULL)
{
_IsotopeVersionRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope/releases");
void PackageSelectScene::render(SDL_Rect rect, double dTime) {
if (_isotopeVersionRequest == NULL) {
_isotopeVersionRequest = new WebRequest("http://api.github.com/repos/Ta180m/Isotope/releases");
SceneDirector::currentSceneDirector->render();
SessionManager::makeRequest(_IsotopeVersionRequest);
SessionManager::makeRequest(_isotopeVersionRequest);
}
Scene::render(rect, dTime);
}
void PackageSelectScene::_showUpdateView()
{
void PackageSelectScene::_showUpdateView() {
_updateView->setProgress(0);
_updateView->hidden = false;
_statusView->hidden = true;
_installRowView->hidden = true;
for (auto const &action : _footerView->actions)
{
for (auto const& action : _footerView->actions) {
delete action;
}
_footerView->actions.clear();
}
void PackageSelectScene::_showPackageSelectViews(std::string IsotopeVersion)
{
// if (!ConfigManager::getReceivedIgnoreConfigWarning())
// {
_ignoreConfigsAlertView->show();
// }
void PackageSelectScene::_showPackageSelectViews(std::string isotopeVersion) {
if (!ConfigManager::getReceivedIgnoreConfigWarning()) {
_ignoreConfigsAlertView->show();
}
_updateView->hidden = true;
_statusView->hidden = true;
@ -154,26 +141,20 @@ namespace dsu::scenes
_installRowView->hasFocus = true;
string version = ConfigManager::getCurrentVersion();
if (version.compare(IsotopeVersion) == 0)
{
if (version.compare(isotopeVersion) == 0) {
_installRowView->setPrimaryText("Reinstall Isotope");
}
else
{
} else {
_installRowView->setPrimaryText("Install Latest Isotope");
}
if (version == "" || version.compare(IsotopeVersion) == 0)
{
_installRowView->setSecondaryText("Latest Version is " + IsotopeVersion);
}
else
{
_installRowView->setSecondaryText("You currently have version " + version + " installed, and the latest version is " + IsotopeVersion + ".");
string curElem = elem[stoi(version.substr(1))];
string isoElem = elem[stoi(isotopeVersion.substr(1))];
if (version == "" || version.compare(isotopeVersion) == 0) {
_installRowView->setSecondaryText("Latest Version is " + isotopeVersion + " - " + isoElem);
} else {
_installRowView->setSecondaryText("You currently have version " + version + " - " + curElem + " installed, and the latest version is " + isotopeVersion + " - " + isoElem + ".");
}
for (auto const &action : _footerView->actions)
{
for (auto const& action : _footerView->actions) {
delete action;
}
_footerView->actions.clear();
@ -181,8 +162,7 @@ namespace dsu::scenes
_footerView->actions.push_back(new Action(B_BUTTON, "Quit"));
}
void PackageSelectScene::_showStatusView(string text, string subtext)
{
void PackageSelectScene::_showStatusView(string text, string subtext) {
_statusView->setText(text);
_statusView->setSubtext(subtext);
@ -190,8 +170,7 @@ namespace dsu::scenes
_statusView->hidden = false;
_installRowView->hidden = true;
for (auto const &action : _footerView->actions)
{
for (auto const& action : _footerView->actions) {
delete action;
}
_footerView->actions.clear();
@ -200,64 +179,50 @@ namespace dsu::scenes
// Alert View Callback Method
void PackageSelectScene::_onAlertViewDismiss(ModalView *view, bool success)
{
if (success && _ignoreConfigsAlertView->getSelectedOption() == 0)
{
vector<string> files = FileManager::scanDirectoryRecursive("sdmc:/config");
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
files.push_back("sdmc:/atmosphere/config/BCT.ini");
files.push_back("sdmc:/atmosphere/config/override_config.ini");
files.push_back("sdmc:/atmosphere/config/system_settings.ini");
void PackageSelectScene::_onAlertViewDismiss(ModalView * view, bool success) {
if (success && _ignoreConfigsAlertView->getSelectedOption() == 0) {
vector<string> files;
files.push_back("sdmc:/atmosphere/BCT.ini");
files.push_back("sdmc:/atmosphere/loader.ini");
files.push_back("sdmc:/atmosphere/system_settings.ini");
files.push_back("sdmc:/bootloader/patches.ini");
files.push_back("sdmc:/bootloader/hekate_ipl.ini");
files.push_back("sdmc:/config/hid_mitm/config.ini");
files.push_back("sdmc:/config/sys-clk/config.ini");
files.push_back("sdmc:/config/sys-ftpd/config.ini");
files.push_back("sdmc:/ftpd/config.ini");
files.push_back("sdmc:/switch/Isotope-Toolbox/config.json");
files.push_back("sdmc:/switch/Isotope-Updater/internal.db");
files.push_back("sdmc:/switch/Isotope-Updater/settings.cfg");
if(filesToIgnore.empty())
{
ConfigManager::setFilesToIgnore(files);
} else {
for (auto i : filesToIgnore)
{
files.erase(remove(files.begin(), files.end(), i), files.end());
}
}
ConfigManager::setFilesToIgnore(files);
ConfigManager::setIgnoreConfigFiles(true);
} else {
ConfigManager::setIgnoreConfigFiles(false);
}
ConfigManager::setReceivedIgnoreConfigWarning(true);
}
// Swurl Callback Methods
void PackageSelectScene::_onProgressUpdate(WebRequest *request, double progress)
{
void PackageSelectScene::_onProgressUpdate(WebRequest * request, double progress) {
_updateView->setProgress(progress);
SceneDirector::currentSceneDirector->render();
}
void PackageSelectScene::_onCompleted(WebRequest *request)
{
json_t *root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1)
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[1]");
void PackageSelectScene::_onCompleted(WebRequest * request) {
json_t * root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1) {
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
json_t *release = json_array_get(root, 0);
if (!release || !json_is_object(release))
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[2]");
json_t * release = json_array_get(root, 0);
if (!release || !json_is_object(release)) {
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
json_t *tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName))
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[3]");
json_t * tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName)) {
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
@ -270,8 +235,7 @@ namespace dsu::scenes
SessionManager::onError = NULL;
}
void PackageSelectScene::_onError(WebRequest *request, string error)
{
void PackageSelectScene::_onError(WebRequest * request, string error) {
_showStatusView(error, "Please restart the app to try again.");
}
} // namespace dsu::scenes
}

View file

@ -28,8 +28,8 @@
#include "../views/UpdateView.hpp"
#include "../views/AlertView.hpp"
namespace dsu::scenes {
class PackageSelectScene : public dsu::Scene {
namespace ku::scenes {
class PackageSelectScene : public ku::Scene {
public:
PackageSelectScene();
~PackageSelectScene();
@ -38,20 +38,20 @@ namespace dsu::scenes {
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::ListRowView * _installRowView = NULL;
dsu::views::FooterView * _footerView = NULL;
dsu::views::AlertView * _ignoreConfigsAlertView = NULL;
ku::views::HeaderView * _headerView = NULL;
ku::views::UpdateView * _updateView = NULL;
ku::views::StatusView * _statusView = NULL;
ku::views::ListRowView * _installRowView = NULL;
ku::views::FooterView * _footerView = NULL;
ku::views::AlertView * _ignoreConfigsAlertView = NULL;
swurl::WebRequest * _IsotopeVersionRequest = NULL;
swurl::WebRequest * _isotopeVersionRequest = NULL;
void _showUpdateView();
void _showPackageSelectViews(std::string IsotopeVersion);
void _showPackageSelectViews(std::string isotopeVersion);
void _showStatusView(std::string text, std::string subtext);
void _onAlertViewDismiss(dsu::ModalView * view, bool success);
void _onAlertViewDismiss(ku::ModalView * view, bool success);
void _onProgressUpdate(swurl::WebRequest * request, double progress);
void _onCompleted(swurl::WebRequest * request);

View file

@ -20,10 +20,10 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
AlertButtonView::AlertButtonView(string title, bool hasFocus, SDL_Rect rect) {
frame = rect;

View file

@ -22,7 +22,7 @@
#include "ControlView.hpp"
#include "TextView.hpp"
namespace dsu::views {
namespace ku::views {
class AlertButtonView : public ControlView {
public:
bool isLast;

View file

@ -22,10 +22,10 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
AlertView::AlertView(string title, string message, vector<string> buttons) {
_focusSelection = 0;
_alertHeight = 203;

View file

@ -26,8 +26,8 @@
#include "../ModalView.hpp"
#include "TextView.hpp"
namespace dsu::views {
class AlertView : public dsu::ModalView {
namespace ku::views {
class AlertView : public ku::ModalView {
public:
AlertView(std::string title, std::string message, std::vector<std::string> buttons);
~AlertView();

View file

@ -22,9 +22,9 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
namespace dsu::views {
namespace ku::views {
SDL_Color ControlView::_generateSelectionColor() {
SDL_Color color1 = AssetManager::selected_border_1;
SDL_Color color2 = AssetManager::selected_border_2;

View file

@ -21,8 +21,8 @@
#include "../View.hpp"
namespace dsu::views {
class ControlView : public dsu::View {
namespace ku::views {
class ControlView : public ku::View {
protected:
double _timeElapsed;

View file

@ -20,10 +20,10 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::models;
using namespace ku;
using namespace ku::models;
namespace dsu::views {
namespace ku::views {
FooterView::FooterView() : View() {
isFocusable = false;
isTouchable = false;

View file

@ -22,16 +22,16 @@
#include "../models/Action.hpp"
#include "../View.hpp"
namespace dsu::views {
class FooterView : public dsu::View {
namespace ku::views {
class FooterView : public ku::View {
public:
std::list<dsu::models::Action *> actions;
std::list<ku::models::Action *> actions;
FooterView();
~FooterView();
void render(SDL_Rect rect, double dTime);
private:
void _renderButton(dsu::models::ActionButton button, SDL_Texture * texture, SDL_Rect frame);
void _renderButton(ku::models::ActionButton button, SDL_Texture * texture, SDL_Rect frame);
};
}

View file

@ -20,9 +20,9 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
namespace dsu::views {
namespace ku::views {
HeaderView::HeaderView(string title, bool showIcon) : View() {
isFocusable = false;
isTouchable = false;

View file

@ -20,8 +20,8 @@
#include "TextView.hpp"
#include "../View.hpp"
namespace dsu::views {
class HeaderView : public dsu::View {
namespace ku::views {
class HeaderView : public ku::View {
public:
HeaderView(std::string title, bool showIcon);
~HeaderView();

View file

@ -19,9 +19,9 @@
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
namespace dsu::views {
namespace ku::views {
ImageView::ImageView(SDL_Texture * image) : View() {
_image = image;
}

View file

@ -21,8 +21,8 @@
using namespace std;
namespace dsu::views {
class ImageView : public dsu::View {
namespace ku::views {
class ImageView : public ku::View {
public:
ImageView(SDL_Texture * image);
~ImageView(){};

View file

@ -22,10 +22,10 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
ListRowView::ListRowView(string primaryText, string secondaryText, ListRowStyle style) : ControlView() {
isLast = false;
hasCheckmark = false;

View file

@ -22,7 +22,7 @@
#include "ControlView.hpp"
#include "TextView.hpp"
namespace dsu::views {
namespace ku::views {
typedef enum {
DEFAULT,
SUBTITLE,

View file

@ -22,9 +22,9 @@
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
namespace dsu::views {
namespace ku::views {
ProgressBarView::ProgressBarView() : View() {
progress = 0;
}

View file

@ -19,8 +19,8 @@
#include "../View.hpp"
namespace dsu::views {
class ProgressBarView : public dsu::View {
namespace ku::views {
class ProgressBarView : public ku::View {
public:
double progress;

View file

@ -19,10 +19,10 @@
#include "../AssetManager.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
StatusView::StatusView(string text, string subtext) : View() {
frame = { 0, 0, 1280, 100 };

View file

@ -24,8 +24,8 @@
using namespace std;
namespace dsu::views {
class StatusView : public dsu::View {
namespace ku::views {
class StatusView : public ku::View {
public:
StatusView(std::string text, std::string subtext);
~StatusView();

View file

@ -21,10 +21,10 @@
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
TextView::TextView(TTF_Font * theFont, string theText, SDL_Color theTextColor) : View() {
isFocusable = false;
isTouchable = false;

View file

@ -23,7 +23,7 @@
#include "../View.hpp"
namespace dsu::views {
namespace ku::views {
typedef enum {
LEFT_ALIGN,
CENTER_ALIGN,
@ -37,7 +37,7 @@ namespace dsu::views {
int textHeight;
};
class TextView : public dsu::View {
class TextView : public ku::View {
public:
TTF_Font * font;
std::string text;

View file

@ -19,10 +19,10 @@
#include "../AssetManager.hpp"
using namespace dsu;
using namespace ku;
using namespace std;
namespace dsu::views {
namespace ku::views {
UpdateView::UpdateView(string text) : View() {
frame = { 0, 0, 1280, 325 };

View file

@ -24,8 +24,8 @@
#include "TextView.hpp"
#include "../View.hpp"
namespace dsu::views {
class UpdateView : public dsu::View {
namespace ku::views {
class UpdateView : public ku::View {
public:
UpdateView(std::string text);
~UpdateView();