@ -1,5 +1,4 @@ | |||
build | |||
.vscode | |||
*.elf | |||
*.nacp | |||
*.nro | |||
*.nro |
@ -1,6 +0,0 @@ | |||
[submodule "SimpleIniParser"] | |||
path = SimpleIniParser | |||
url = https://github.com/AtlasNX/SimpleIniParser.git | |||
[submodule "Swurl"] | |||
path = Swurl | |||
url = https://github.com/AtlasNX/Swurl.git |
@ -1,20 +1,3 @@ | |||
# Kosmos Updater | |||
# Kosmos Updater - SDL-less | |||
A homebrew application for the Nintendo Switch that will automatically update your CFW with the latest from Kosmos. | |||
## settings.cfg | |||
| Config option | Description | |||
| --------------------------------------------------------------------------- | --- | |||
| `host = "http://kosmos-updater.teamatlasnx.com";` | Which server to connect to. You can host your own server using the files in the [server repository](https://github.com/AtlasNX/Kosmos-Updater-Server). | |||
| `ignore = [ "sdmc://fileToIgnore.nro", "sdmc://anotherFileToIgnore.nro" ];` | Array of files to ignore when extracting. | |||
| `autoupdate = true;` | Whether or not to auto update Kosmos Updater. | |||
| `proxy_enabled = false;` | Whether or not to use a proxy for network calls. | |||
| `proxy_url = "http://example.com:8080";` | The URL of the proxy server. | |||
| `proxy_username = "username";` | The username to use for the proxy server, if blank it will not be used. | |||
| `proxy_password = "password";` | The password to use for the proxy server, if blank it will not be used. | |||
## Credits | |||
* Thanks to vgmoose for examples on using minizip in appstorenx. | |||
* Thanks to y4my4m and natinusala in the ReSwitched discord for their discussions around libcurl. | |||
This was an attempt to rewrite Kosmos Updater without using SDL. This would have dramatically reduced the size of the binary. |
@ -0,0 +1,110 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* 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 "Application.hpp" | |||
#include "Managers/Theme.hpp" | |||
namespace KosmosUpdater { | |||
Application::Application() { | |||
this->_window = nwindowGetDefault(); | |||
framebufferCreate( | |||
&this->_framebuffer, | |||
this->_window, | |||
1280, | |||
720, | |||
PIXEL_FORMAT_RGBA_8888, | |||
2); | |||
framebufferMakeLinear(&this->_framebuffer); | |||
Managers::Theme::Instance()->updateTheme(); | |||
} | |||
Application::~Application() { | |||
framebufferClose(&this->_framebuffer); | |||
} | |||
int Application::start(std::shared_ptr<Scene> scene) { | |||
Application::_CurrentScene = scene; | |||
// Main Game Loop | |||
while (appletMainLoop()) | |||
{ | |||
auto dTime = _getDeltaTime(); | |||
// Handle controller inputs | |||
hidScanInput(); | |||
this->_processControllerForScene(CONTROLLER_P1_AUTO, dTime); | |||
Application::CurrentFramebuffer = (u8 *) framebufferBegin(&this->_framebuffer, &Application::Stride); | |||
memset(Application::CurrentFramebuffer, 0, Application::Stride * 720); | |||
if (Application::_CurrentScene) { | |||
this->_render(dTime); | |||
Application::_CurrentScene->tick(Rect(0, 0, 1280, 720), dTime); | |||
} else { | |||
break; | |||
} | |||
// Present our frame. | |||
framebufferEnd(&this->_framebuffer); | |||
} | |||
return 0; | |||
} | |||
void Application::render() { | |||
if (Application::_CurrentScene) { | |||
auto dTime = _getDeltaTime(); | |||
_render(dTime); | |||
// Present our frame. | |||
framebufferEnd(&this->_framebuffer); | |||
} | |||
} | |||
void Application::SwitchScene(std::shared_ptr<Scene> scene) { | |||
Application::_CurrentScene = scene; | |||
} | |||
double Application::_getDeltaTime() { | |||
_lastTime = _nowTime; | |||
_nowTime = svcGetSystemTick(); | |||
return _nowTime - _lastTime / 19200; | |||
} | |||
void Application::_processControllerForScene(HidControllerID id, double dTime) { | |||
if (Application::_CurrentScene) | |||
Application::_CurrentScene->buttonsHeld(hidKeysHeld(id), dTime); | |||
if (Application::_CurrentScene) | |||
Application::_CurrentScene->buttonsDown(hidKeysDown(id), dTime); | |||
if (Application::_CurrentScene) | |||
Application::_CurrentScene->buttonsUp(hidKeysUp(id), dTime); | |||
} | |||
void Application::_render(double dTime) { | |||
Draw::fill(Rect(0, 0, 1280, 720), Application::_CurrentScene->background); | |||
// Call rendering routines. | |||
Application::_CurrentScene->render(Rect(0, 0, 1280, 720), dTime); | |||
} | |||
} |
@ -0,0 +1,53 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <memory> | |||
#include <switch.h> | |||
#include "Scene.hpp" | |||
#pragma once | |||
namespace KosmosUpdater { | |||
class Application { | |||
public: | |||
static inline u8 * CurrentFramebuffer = nullptr; | |||
static inline u32 Stride = 0; | |||
Application(); | |||
~Application(); | |||
int start(std::shared_ptr<Scene> scene); | |||
void render(); | |||
static void SwitchScene(std::shared_ptr<Scene> scene); | |||
private: | |||
NWindow * _window; | |||
Framebuffer _framebuffer; | |||
u64 _nowTime; | |||
u64 _lastTime; | |||
static inline std::shared_ptr<Scene> _CurrentScene = nullptr; | |||
double _getDeltaTime(); | |||
void _processControllerForScene(HidControllerID id, double dTime); | |||
void _render(double dTime); | |||
}; | |||
} |
@ -0,0 +1,57 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "Application.hpp" | |||
#include "Draw.hpp" | |||
namespace KosmosUpdater { | |||
void Draw::pixel(u16 x, u16 y, Color color) { | |||
u32 position = y * Application::Stride + x * sizeof(u32); | |||
u8 * framebuffer = Application::CurrentFramebuffer; | |||
framebuffer[position] = Draw::_blend(framebuffer[position], color.red, color.alpha); | |||
framebuffer[position + 1] = Draw::_blend(framebuffer[position + 1], color.green, color.alpha); | |||
framebuffer[position + 2] = Draw::_blend(framebuffer[position + 2], color.blue, color.alpha); | |||
framebuffer[position + 3] = 255; | |||
} | |||
void Draw::fill(Rect rect, Color color) { | |||
for (u16 x = rect.x; x < rect.x + rect.width; x++) { | |||
for (u16 y = rect.y; y < rect.y + rect.height; y++) { | |||
Draw::pixel(x, y, color); | |||
} | |||
} | |||
} | |||
void Draw::image(u16 x, u16 y, std::shared_ptr<Image> image) { | |||
if (!image->imageLoaded || image->rawImage == nullptr) | |||
return; | |||
for (u16 x2 = x; x2 < x + image->width; x2++) { | |||
for (u16 y2 = y; y2 < y + image->height; y2++) { | |||
int pos = ((y2 * image->width) + x2) * 3; | |||
Draw::pixel(x2, y2, Color(image->rawImage[pos], image->rawImage[pos + 1], image->rawImage[pos + 2], 255)); | |||
} | |||
} | |||
} | |||
u8 Draw::_blend(u32 source, u32 destination, u8 alpha) { | |||
return (destination * alpha + source * (255 - alpha)) / 255; | |||
} | |||
} |
@ -0,0 +1,54 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <memory> | |||
#include <switch.h> | |||
#include "Image.hpp" | |||
#define Rect(x, y, w, h) { x, y, w, h } | |||
#define Color(r, g, b, a) { r, g, b, a } | |||
#pragma once | |||
namespace KosmosUpdater { | |||
struct Rect { | |||
u16 x; | |||
u16 y; | |||
u16 width; | |||
u16 height; | |||
}; | |||
struct Color { | |||
u8 red; | |||
u8 green; | |||
u8 blue; | |||
u8 alpha; | |||
}; | |||
class Draw { | |||
public: | |||
static void pixel(u16 x, u16 y, Color color); | |||
static void fill(Rect rect, Color color); | |||
static void image(u16 x, u16 y, std::shared_ptr<Image> image); | |||
private: | |||
static u8 _blend(u32 source, u32 destination, u8 alpha); | |||
}; | |||
} |
@ -0,0 +1,72 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* 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 <fstream> | |||
#include <png.h> | |||
#include <sstream> | |||
#include <vector> | |||
#include "Image.hpp" | |||
namespace KosmosUpdater { | |||
Image::Image(std::string filePath) { | |||
std::string file = this->_readFile(filePath); | |||
this->imageLoaded = this->_readPNG(file); | |||
} | |||
Image::~Image() { | |||
if (this->rawImage != NULL) { | |||
free(this->rawImage); | |||
} | |||
} | |||
std::string Image::_readFile(std::string filePath) { | |||
std::ifstream file(filePath); | |||
std::ostringstream ss; | |||
ss << file.rdbuf(); | |||
return ss.str(); | |||
} | |||
bool Image::_readPNG(std::string file) { | |||
png_image image; | |||
memset(&image, 0, sizeof(image)); | |||
image.version = PNG_IMAGE_VERSION; | |||
if (png_image_begin_read_from_memory(&image, file.c_str(), file.length()) == 0) { | |||
return false; | |||
} | |||
this->width = image.width; | |||
this->height = image.height; | |||
image.format = PNG_FORMAT_RGB; | |||
this->rawImage = (u8*) malloc(image.width * image.height * 3); | |||
memset(this->rawImage, 0, image.width * image.height * 3); | |||
if (png_image_finish_read(&image, NULL, this->rawImage, 0, NULL) == 0) { | |||
return false; | |||
} | |||
png_image_free(&image); | |||
return true; | |||
} | |||
} |
@ -0,0 +1,41 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <string> | |||
#include <switch.h> | |||
#pragma once | |||
namespace KosmosUpdater { | |||
class Image { | |||
public: | |||
bool imageLoaded = false; | |||
u8 * rawImage = NULL; | |||
u16 width = 0; | |||
u16 height = 0; | |||
Image(std::string filePath); | |||
~Image(); | |||
private: | |||
std::string _readFile(std::string filePath); | |||
bool _readPNG(std::string file); | |||
}; | |||
} | |||
@ -0,0 +1,71 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <curl/curl.h> | |||
#include <memory> | |||
#include <switch.h> | |||
#include "Application.hpp" | |||
#include "Scenes/Root.hpp" | |||
extern "C" { | |||
void userAppInit(void); | |||
void userAppExit(void); | |||
} | |||
void userAppInit(void) { | |||
if (R_FAILED(setsysInitialize())) | |||
fatalThrow(0x9001); | |||
if (R_FAILED(socketInitializeDefault())) | |||
fatalThrow(0x9002); | |||
#ifdef DEBUG | |||
nxlinkStdio(); | |||
#endif | |||
// res = nifmInitialize(NifmServiceType_User); | |||
// if (R_FAILED(res)) | |||
// fatalThrow(res); | |||
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) | |||
fatalThrow(0x9004); | |||
if (R_FAILED(romfsInit())) | |||
fatalThrow(0x9005); | |||
// rc = plInitialize(); | |||
// if (R_FAILED(res)) | |||
// fatalThrow(res); | |||
} | |||
void userAppExit(void) { | |||
// plExit(); | |||
romfsExit(); | |||
curl_global_cleanup(); | |||
// nifmExit(); | |||
socketExit(); | |||
setsysExit(); | |||
} | |||
int main(int argc, char * argv[]) { | |||
std::unique_ptr<KosmosUpdater::Application> app = std::make_unique<KosmosUpdater::Application>(); | |||
std::shared_ptr<KosmosUpdater::Scenes::Root> root = std::make_shared<KosmosUpdater::Scenes::Root>(); | |||
return app->start(root); | |||
} |
@ -0,0 +1,55 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <switch.h> | |||
#include "Theme.hpp" | |||
namespace KosmosUpdater::Managers { | |||
Theme * Theme::Instance() { | |||
if (_instance == nullptr) { | |||
_instance = new Theme; | |||
} | |||
return _instance; | |||
} | |||
void Theme::updateTheme() { | |||
ColorSetId theme; | |||
setsysGetColorSetId(&theme); | |||
this->modalOverlay = Color(18, 27, 36, 229); | |||
this->focusedBorderOne = Color(0, 255, 196, 255); | |||
this->focusedBorderTwo = Color(22, 146, 197, 255); | |||
if (theme == ColorSetId_Light) { | |||
this->isLight = true; | |||
this->background = Color(235, 235, 235, 255); | |||
this->text = Color(45, 45, 45, 255); | |||
this->focusedBackground = Color(253, 253, 253, 255); | |||
this->focusedText = Color(50, 80, 240, 255); | |||
} else { | |||
this->isLight = false; | |||
this->background = Color(45, 45, 45, 255); | |||
this->text = Color(255, 255, 255, 255); | |||
this->focusedBackground = Color(31, 34, 39, 255); | |||
this->focusedText = Color(0, 255, 196, 255); | |||
} | |||
} | |||
} |
@ -0,0 +1,50 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <memory> | |||
#include "../Draw.hpp" | |||
#pragma once | |||
namespace KosmosUpdater::Managers { | |||
class Theme { | |||
public: | |||
bool isLight = false; | |||
Color background; | |||
Color text; | |||
Color modalOverlay; | |||
Color focusedBackground; | |||
Color focusedText; | |||
Color focusedBorderOne; | |||
Color focusedBorderTwo; | |||
void updateTheme(); | |||
static Theme * Instance(); | |||
private: | |||
static inline Theme * _instance = nullptr; | |||
Theme(){}; | |||
Theme(Theme const&){}; | |||
}; | |||
} |
@ -0,0 +1,48 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "Scene.hpp" | |||
namespace KosmosUpdater { | |||
void Scene::render(Rect rect, double dTime) { | |||
for (auto const& view : subviews) { | |||
if (auto viewTemp = view.lock()) { | |||
if (viewTemp->isHidden) | |||
continue; | |||
Rect subviewFrame = viewTemp->frame; | |||
// Models::ViewRender subViewRender = view->render({ rect.x + subviewFrame.x, rect.y + subviewFrame.y, subviewFrame.w, subviewFrame.h }, dTime); | |||
viewTemp->render( | |||
Rect( | |||
(u16) (rect.x + subviewFrame.x), | |||
(u16) (rect.y + subviewFrame.y), | |||
subviewFrame.width, | |||
subviewFrame.height | |||
), | |||
dTime | |||
); | |||
// SDL_RenderCopy(Application::renderer, subViewRender.texture, NULL, &subViewRender.bounds); | |||
} | |||
} | |||
} | |||
void Scene::addSubView(std::shared_ptr<View> view) { | |||
subviews.push_back(view); | |||
} | |||
} |
@ -0,0 +1,49 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <vector> | |||
#include <memory> | |||
#include <switch.h> | |||
#include "Draw.hpp" | |||
#include "View.hpp" | |||
#pragma once | |||
namespace KosmosUpdater { | |||
class Scene { | |||
public: | |||
Color background = { 0, 0, 0, 255 }; | |||
std::vector<std::weak_ptr<View>> subviews; | |||
Scene(){}; | |||
virtual void buttonsHeld(u32 buttons, double dTime){}; | |||
virtual void buttonsDown(u32 buttons, double dTime){}; | |||
virtual void buttonsUp(u32 buttons, double dTime){}; | |||
virtual void tick(Rect rect, double dTime){}; | |||
virtual void render(Rect rect, double dTime); | |||
void addSubView(std::shared_ptr<View> view); | |||
private: | |||
}; | |||
} |
@ -0,0 +1,42 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "../Application.hpp" | |||
#include "../Draw.hpp" | |||
#include "../Managers/Theme.hpp" | |||
#include "Root.hpp" | |||
namespace KosmosUpdater::Scenes { | |||
Root::Root() { | |||
auto theme = Managers::Theme::Instance(); | |||
this->background = theme->background; | |||
this->icon = std::make_unique<Image>("romfs:/icon.png"); | |||
} | |||
void Root::buttonsDown(u32 buttons, double dTime) { | |||
if (buttons != 0) { | |||
Application::SwitchScene(nullptr); | |||
} | |||
} | |||
void Root::render(Rect rect, double dTime) { | |||
Draw::image(0, 0, this->icon); | |||
} | |||
} |
@ -0,0 +1,40 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <memory> | |||
#include "../Scene.hpp" | |||
#include "../Image.hpp" | |||
#pragma once | |||
namespace KosmosUpdater::Scenes { | |||
class Root : public Scene { | |||
public: | |||
std::shared_ptr<Image> icon; | |||
Root(); | |||
void buttonsDown(u32 buttons, double dTime); | |||
void render(Rect rect, double dTime); | |||
private: | |||
double _test; | |||
}; | |||
} |
@ -0,0 +1,86 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "View.hpp" | |||
namespace KosmosUpdater { | |||
void View::render(Rect rect, double dTime) { | |||
// if (background.a != 0) { | |||
// SDL_SetRenderDrawColor(Application::renderer, background.r, background.g, background.b, background.a); | |||
// SDL_RenderFillRect(Application::renderer, &rect); | |||
// } | |||
// Models::ViewRender subViewRenders[subviews.size()]; | |||
// int i = 0; | |||
// for (auto const& view : subviews) { | |||
// if (!view->isHidden) { | |||
// auto subviewFrame = view->frame; | |||
// subViewRenders[i] = view->render({ rect.x + subviewFrame.x, rect.y + subviewFrame.y, subviewFrame.w, subviewFrame.h }, dTime); | |||
// if (!requiresRendering && subViewRenders[i].requiredRendering) { | |||
// requiresRendering = true; | |||
// } | |||
// } | |||
// i++; | |||
// } | |||
// SDL_Rect bounds = { 0, 0, 0, 0 }; | |||
// if (clipsToBounds) { | |||
// bounds = rect; | |||
// } else { | |||
// SDL_GetWindowSize(Application::window, &bounds.w, &bounds.h); | |||
// } | |||
// onTick(rect, dTime); | |||
// bool requiredRendering = requiresRendering; | |||
// if (requiresRendering) { | |||
// requiresRendering = false; | |||
// if (_texture == NULL) { | |||
// _texture = SDL_CreateTexture(Application::renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, bounds.w, bounds.h); | |||
// SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND); | |||
// } | |||
// SDL_SetRenderTarget(Application::renderer, _texture); | |||
// SDL_SetRenderDrawColor(Application::renderer, 0, 0, 0, 0); | |||
// SDL_RenderClear(Application::renderer); | |||
// if (clipsToBounds) { | |||
// onRender({ 0, 0, rect.w, rect.h }, dTime); | |||
// } else { | |||
// onRender(rect, dTime); | |||
// } | |||
// for (i = 0; i < (int) subviews.size(); i++) { | |||
// if (subViewRenders[i].texture != NULL) { | |||
// SDL_RenderCopy(Application::renderer, subViewRenders[i].texture, NULL, &subViewRenders[i].bounds); | |||
// } | |||
// } | |||
// SDL_SetRenderTarget(Application::renderer, NULL); | |||
// } | |||
// SDL_SetTextureAlphaMod(_texture, alpha); | |||
// return { _texture, (clipsToBounds) ? frame : bounds, requiredRendering }; | |||
} | |||
void View::addSubView(std::shared_ptr<View> view) { | |||
this->subviews.push_back(view); | |||
} | |||
} |
@ -0,0 +1,61 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include <vector> | |||
#include <memory> | |||
#include <switch.h> | |||
#include "Draw.hpp" | |||
#pragma once | |||
namespace KosmosUpdater { | |||
class View { | |||
public: | |||
Rect frame = Rect(0, 0, 0, 0); | |||
Color background = Color(0, 0, 0, 0); | |||
u8 alpha = 255; | |||
bool isHidden = false; | |||
bool clipsToBounds = true; | |||
bool requiresRendering = true; | |||
View(){}; | |||
virtual void onTick(Rect rect, double dTime){}; | |||
virtual void onRender(Rect rect, double dTime){}; | |||
void render(Rect rect, double dTime); | |||
/* Controls */ | |||
bool isFocusable = false; | |||
bool hasFocus = false; | |||
std::weak_ptr<View> focusedSubview = std::weak_ptr<View>(); | |||
/* Touch Controls */ | |||
bool isTouchable = false; | |||
virtual void touchStarted(){}; | |||
virtual void touchMoved(){}; | |||
virtual void touchEnded(){}; | |||
/* View Hierarchy */ | |||
std::vector<std::weak_ptr<View>> subviews; | |||
void addSubView(std::shared_ptr<View> view); | |||
private: | |||
}; | |||
} |
@ -0,0 +1,20 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "Footer.hpp" |
@ -0,0 +1,31 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "../View.hpp" | |||
#pragma once | |||
namespace KosmosUpdater::Views { | |||
class Footer : public View { | |||
public: | |||
private: | |||
}; | |||
} |
@ -0,0 +1,20 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "Header.hpp" |
@ -0,0 +1,31 @@ | |||
/* | |||
* Kosmos Updater | |||
* Copyright (c) 2020 Nichole Mattera | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License | |||
* as published by the Free Software Foundation; either version 2 | |||
* of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
#include "../View.hpp" | |||
#pragma once | |||
namespace KosmosUpdater::Views { | |||
class Header : public View { | |||
public: | |||
private: | |||
}; | |||
} |
@ -1,140 +0,0 @@ | |||
// Kosmos Updater | |||
// Copyright (C) 2019 Nichole Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include "AssetManager.hpp" | |||
#include "SceneDirector.hpp" | |||
using namespace std; | |||
namespace ku { | |||
void AssetManager::dealloc() { | |||
if (AssetManager::large_button_font != NULL) | |||
TTF_CloseFont(AssetManager::large_button_font); | |||
if (AssetManager::button_font != NULL) | |||
TTF_CloseFont(AssetManager::button_font); | |||
if (AssetManager::subbody_font != NULL) | |||
TTF_CloseFont(AssetManager::subbody_font); | |||
if (AssetManager::body_font != NULL) | |||
TTF_CloseFont(AssetManager::body_font); | |||
if (AssetManager::header_font != NULL) | |||
TTF_CloseFont(AssetManager::header_font); | |||
if (AssetManager::icon != NULL) | |||
SDL_DestroyTexture(AssetManager::icon); | |||
if (AssetManager::downloading != NULL) | |||
SDL_DestroyTexture(AssetManager::downloading); | |||
if (AssetManager::checkmark != NULL) | |||
SDL_DestroyTexture(AssetManager::checkmark); | |||
if (AssetManager::handheld != NULL) | |||
SDL_DestroyTexture(AssetManager::handheld); | |||
if (AssetManager::y_button != NULL) | |||
SDL_DestroyTexture(AssetManager::y_button); | |||
if (AssetManager::x_button != NULL) | |||
SDL_DestroyTexture(AssetManager::x_button); | |||
if (AssetManager::b_button != NULL) | |||
SDL_DestroyTexture(AssetManager::b_button); | |||
if (AssetManager::a_button != NULL) | |||
SDL_DestroyTexture(AssetManager::a_button); | |||
} | |||
bool AssetManager::initialize() { | |||
Result rc; | |||
setsysGetColorSetId(&AssetManager::theme); | |||
if (AssetManager::theme == ColorSetId_Light) { | |||
AssetManager::background = { 235, 235, 235, 255 }; | |||
AssetManager::sidebard_background = { 240, 240, 240, 255 }; | |||
AssetManager::header_footer_divider = { 45, 45, 45, 255 }; | |||
AssetManager::header_bullet = { 121, 121, 121, 255 }; | |||
AssetManager::list_divider = { 205, 205, 205, 255 }; | |||
AssetManager::active_player_indicator = { 158, 228, 0, 255 }; | |||
AssetManager::player_indicator = { 125, 125, 125, 255 }; | |||
AssetManager::selected_background = { 253, 253, 253, 255 }; | |||
AssetManager::selected_border_1 = { 0, 255, 196, 255 }; | |||
AssetManager::selected_border_2 = { 22, 146, 197, 255 }; | |||
AssetManager::modal_faded_background = { 18, 27, 36, 229 }; | |||
AssetManager::modal_background = { 240, 240, 240, 255 }; | |||
AssetManager::text = { 45, 45, 45, 255 }; | |||
AssetManager::active_text = { 50, 80, 240, 255 }; | |||
AssetManager::disabled_text = { 165, 165, 165, 255 }; | |||
} else { | |||
AssetManager::background = { 45, 45, 45, 255 }; | |||
AssetManager::sidebard_background = { 51, 51, 51, 255 }; | |||
AssetManager::header_footer_divider = { 255, 255, 255, 255 }; | |||
AssetManager::header_bullet = { 160, 160, 160, 255 }; | |||
AssetManager::list_divider = { 77, 77, 77, 255 }; | |||
AssetManager::active_player_indicator = { 158, 228, 0, 255 }; | |||
AssetManager::player_indicator = { 125, 125, 125, 255 }; | |||
AssetManager::selected_background = { 31, 34, 39, 255 }; | |||
AssetManager::selected_border_1 = { 0, 255, 196, 255 }; | |||
AssetManager::selected_border_2 = { 22, 146, 197, 255 }; | |||
AssetManager::modal_faded_background = { 18, 27, 36, 229 }; | |||
AssetManager::modal_background = { 70, 70, 70, 255 }; | |||
AssetManager::text = { 255, 255, 255, 255 }; | |||
AssetManager::active_text = { 0, 255, 196, 255 }; | |||
AssetManager::disabled_text = { 125, 125, 125, 255 }; | |||
} | |||
rc = plGetSharedFontByType(&AssetManager::standardFontData, PlSharedFontType_Standard); | |||
if (R_FAILED(rc)) | |||
return false; | |||
AssetManager::header_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 28); | |||
AssetManager::body_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 23); | |||
AssetManager::subbody_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 18); | |||
if (!AssetManager::header_font || !AssetManager::body_font) | |||
return false; | |||
rc = plGetSharedFontByType(&AssetManager::extendedFontData, PlSharedFontType_NintendoExt); | |||
if (R_FAILED(rc)) | |||
return false; | |||
AssetManager::button_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::extendedFontData.address, AssetManager::extendedFontData.size), 1, 25); | |||
if (!AssetManager::button_font) | |||
return false; | |||
AssetManager::large_button_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::extendedFontData.address, AssetManager::extendedFontData.size), 1, 70); | |||
if (!AssetManager::large_button_font) | |||
return false; | |||
return true; | |||
} | |||
void AssetManager::setRenderColor(SDL_Color color) { | |||
SDL_SetRenderDrawColor(SceneDirector::renderer, color.r, color.g, color.b, color.a); | |||
} | |||
SDL_Texture * AssetManager::loadAsset(string file) { | |||
string themeDirectory = (AssetManager::theme == ColorSetId_Light) ? "light" : "dark"; | |||
string path = "romfs:/" + themeDirectory + "/" + file; | |||
SDL_Surface * image = IMG_Load(path.c_str()); | |||
SDL_Texture * texture = SDL_CreateTextureFromSurface(SceneDirector::renderer, image); | |||
SDL_FreeSurface(image); | |||
return texture; | |||
} | |||
} |
@ -1,71 +0,0 @@ | |||
// Kosmos Updater | |||
// Copyright (C) 2019 Nichole Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#pragma once | |||
#include <SDL2/SDL.h> | |||
#include <SDL2/SDL_image.h> | |||
#include <SDL2/SDL_ttf.h> | |||
#include <string> | |||
#include <switch.h> | |||
namespace ku { | |||
class AssetManager { | |||
public: | |||
/* Textures */ | |||
static inline SDL_Texture * a_button = NULL; | |||
static inline SDL_Texture * b_button = NULL; | |||
static inline SDL_Texture * x_button = NULL; | |||
static inline SDL_Texture * y_button = NULL; | |||
static inline SDL_Texture * handheld = NULL; | |||
static inline SDL_Texture * checkmark = NULL; | |||
static inline SDL_Texture * downloading = NULL; | |||
static inline SDL_Texture * icon = NULL; | |||
/* Colors */ | |||
static inline ColorSetId theme; | |||
static inline SDL_Color background; | |||
static inline SDL_Color sidebard_background; | |||
static inline SDL_Color header_footer_divider; | |||
static inline SDL_Color header_bullet; | |||
static inline SDL_Color list_divider; | |||
static inline SDL_Color active_player_indicator; | |||
static inline SDL_Color player_indicator; | |||
static inline SDL_Color selected_background; | |||
static inline SDL_Color selected_border_1; | |||
static inline SDL_Color selected_border_2; | |||
static inline SDL_Color modal_faded_background; | |||
static inline SDL_Color modal_background; | |||
static inline SDL_Color text; | |||
static inline SDL_Color active_text; | |||
static inline SDL_Color disabled_text; | |||
/* Fonts */ | |||
static inline PlFontData standardFontData; | |||
static inline TTF_Font * header_font = NULL; | |||
static inline TTF_Font * body_font = NULL; | |||
static inline TTF_Font * subbody_font = NULL; | |||
static inline PlFontData extendedFontData; | |||
static inline TTF_Font * button_font = NULL; | |||
static inline TTF_Font * large_button_font = NULL; | |||
static bool initialize(); | |||
static void dealloc(); | |||
static void setRenderColor(SDL_Color color); | |||
static SDL_Texture * loadAsset(std::string file); | |||
}; | |||
} |
@ -1,372 +0,0 @@ | |||
// Kosmos Updater | |||
// Copyright (C) 2019 Nichole Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include "ConfigManager.hpp" | |||
using namespace std; | |||
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; | |||
root = config_root_setting(&_internalDb); | |||
setting = config_setting_add(root, VERSION_KEY.c_str(), CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, VERSION_DEF.c_str()); | |||
setting = config_setting_add(root, INSTALLED_FILES_KEY.c_str(), CONFIG_TYPE_ARRAY); | |||
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, 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()); | |||
} | |||
if(!config_read_file(&_cfg, CONFIG_FILENAME.c_str())) { | |||
config_setting_t * root, * setting; | |||
root = config_root_setting(&_cfg); | |||
setting = config_setting_add(root, HOST_KEY.c_str(), CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, HOST_DEF.c_str()); | |||
setting = config_setting_add(root, IGNORE_KEY.c_str(), CONFIG_TYPE_ARRAY); | |||
setting = config_setting_add(root, AUTOUPDATE_KEY.c_str(), CONFIG_TYPE_BOOL); | |||
config_setting_set_bool(setting, AUTOUPDATE_DEF); | |||
setting = config_setting_add(root, PROXY_ENABLED_KEY.c_str(), CONFIG_TYPE_BOOL); | |||
config_setting_set_bool(setting, PROXY_ENABLED_DEF); | |||
setting = config_setting_add(root, PROXY_URL_KEY.c_str(), CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, PROXY_URL_DEF.c_str()); | |||
setting = config_setting_add(root, PROXY_USERNAME_KEY.c_str(), CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, PROXY_USERNAME_DEF.c_str()); | |||
setting = config_setting_add(root, PROXY_PASSWORD_KEY.c_str(), CONFIG_TYPE_STRING); | |||
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, SETTING_CONFIG_VERSION); | |||
config_write_file(&_cfg, CONFIG_FILENAME.c_str()); | |||
} | |||
_migrateConfigFiles(); | |||
} | |||
void ConfigManager::dealloc() { | |||
config_destroy(&_cfg); | |||
config_destroy(&_internalDb); | |||
} | |||
string ConfigManager::getHost() { | |||
return _readString(HOST_KEY, HOST_DEF, _cfg); | |||
} | |||
vector<string> ConfigManager::getFilesToIgnore() { | |||
vector<string> defaultValue; | |||
return _readArrayOfStrings(IGNORE_KEY, defaultValue, _cfg); | |||
} | |||
bool ConfigManager::shouldAutoUpdate() { | |||
#ifdef DEBUG | |||
return false; | |||
#endif | |||
return _readBoolean(AUTOUPDATE_KEY, AUTOUPDATE_DEF, _cfg); | |||
} | |||
bool ConfigManager::shouldUseProxy() { | |||
return _readBoolean(PROXY_ENABLED_KEY, PROXY_ENABLED_DEF, _cfg); | |||
} | |||
string ConfigManager::getProxy() { | |||
return _readString(PROXY_URL_KEY, PROXY_URL_DEF, _cfg); | |||
} | |||
string ConfigManager::getProxyUsername() { | |||
return _readString(PROXY_USERNAME_KEY, PROXY_USERNAME_DEF, _cfg); | |||
} | |||
string ConfigManager::getProxyPassword() { | |||
return _readString(PROXY_PASSWORD_KEY, PROXY_PASSWORD_DEF, _cfg); | |||
} | |||
int ConfigManager::getSettingsConfigVersion() { | |||
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _cfg); | |||
} | |||
bool ConfigManager::setFilesToIgnore(vector<string> files) { | |||