Browse Source

My attempt to remove SDL from Kosmos Updater.

sdl-less
Nichole Mattera 10 months ago
parent
commit
2e52dd3f04
78 changed files with 1008 additions and 4142 deletions
  1. +1
    -2
      .gitignore
  2. +0
    -6
      .gitmodules
  3. +14
    -49
      Makefile
  4. +2
    -19
      README.md
  5. +0
    -0
      RomFS/0_icon.png
  6. +0
    -0
      RomFS/1_icon.png
  7. +0
    -1
      SimpleIniParser
  8. +110
    -0
      Source/Application.cpp
  9. +53
    -0
      Source/Application.hpp
  10. +57
    -0
      Source/Draw.cpp
  11. +54
    -0
      Source/Draw.hpp
  12. +72
    -0
      Source/Image.cpp
  13. +41
    -0
      Source/Image.hpp
  14. +71
    -0
      Source/Main.cpp
  15. +55
    -0
      Source/Managers/Theme.cpp
  16. +50
    -0
      Source/Managers/Theme.hpp
  17. +48
    -0
      Source/Scene.cpp
  18. +49
    -0
      Source/Scene.hpp
  19. +42
    -0
      Source/Scenes/Root.cpp
  20. +40
    -0
      Source/Scenes/Root.hpp
  21. +86
    -0
      Source/View.cpp
  22. +61
    -0
      Source/View.hpp
  23. +20
    -0
      Source/Views/Footer.cpp
  24. +31
    -0
      Source/Views/Footer.hpp
  25. +20
    -0
      Source/Views/Header.cpp
  26. +31
    -0
      Source/Views/Header.hpp
  27. +0
    -1
      Swurl
  28. BIN
      romfs/dark/downloading.png
  29. BIN
      romfs/light/downloading.png
  30. +0
    -140
      source/AssetManager.cpp
  31. +0
    -71
      source/AssetManager.hpp
  32. +0
    -372
      source/ConfigManager.cpp
  33. +0
    -116
      source/ConfigManager.hpp
  34. +0
    -303
      source/FileManager.cpp
  35. +0
    -43
      source/FileManager.hpp
  36. +0
    -32
      source/ModalView.cpp
  37. +0
    -37
      source/ModalView.hpp
  38. +0
    -65
      source/Scene.cpp
  39. +0
    -48
      source/Scene.hpp
  40. +0
    -206
      source/SceneDirector.cpp
  41. +0
    -65
      source/SceneDirector.hpp
  42. +0
    -49
      source/View.cpp
  43. +0
    -50
      source/View.hpp
  44. +0
    -77
      source/main.cpp
  45. +0
    -37
      source/models/Action.cpp
  46. +0
    -43
      source/models/Action.hpp
  47. +0
    -21
      source/models/Touch.cpp
  48. +0
    -23
      source/models/Touch.hpp
  49. +0
    -177
      source/scenes/AppUpdateScene.cpp
  50. +0
    -56
      source/scenes/AppUpdateScene.hpp
  51. +0
    -83
      source/scenes/ExFatWarningScene.cpp
  52. +0
    -42
      source/scenes/ExFatWarningScene.hpp
  53. +0
    -171
      source/scenes/PackageDownloadScene.cpp
  54. +0
    -57
      source/scenes/PackageDownloadScene.hpp
  55. +0
    -212
      source/scenes/PackageSelectScene.cpp
  56. +0
    -60
      source/scenes/PackageSelectScene.hpp
  57. +0
    -56
      source/views/AlertButtonView.cpp
  58. +0
    -40
      source/views/AlertButtonView.hpp
  59. +0
    -125
      source/views/AlertView.cpp
  60. +0
    -49
      source/views/AlertView.hpp
  61. +0
    -84
      source/views/ControlView.cpp
  62. +0
    -32
      source/views/ControlView.hpp
  63. +0
    -125
      source/views/FooterView.cpp
  64. +0
    -37
      source/views/FooterView.hpp
  65. +0
    -73
      source/views/HeaderView.cpp
  66. +0
    -36
      source/views/HeaderView.hpp
  67. +0
    -33
      source/views/ImageView.cpp
  68. +0
    -35
      source/views/ImageView.hpp
  69. +0
    -129
      source/views/ListRowView.cpp
  70. +0
    -58
      source/views/ListRowView.hpp
  71. +0
    -64
      source/views/ProgressBarView.cpp
  72. +0
    -32
      source/views/ProgressBarView.hpp
  73. +0
    -61
      source/views/StatusView.cpp
  74. +0
    -41
      source/views/StatusView.hpp
  75. +0
    -118
      source/views/TextView.cpp
  76. +0
    -63
      source/views/TextView.hpp
  77. +0
    -74
      source/views/UpdateView.cpp
  78. +0
    -43
      source/views/UpdateView.hpp

+ 1
- 2
.gitignore View File

@ -1,5 +1,4 @@
build
.vscode
*.elf
*.nacp
*.nro
*.nro

+ 0
- 6
.gitmodules View File

@ -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

+ 14
- 49
Makefile View File

@ -37,64 +37,37 @@ include $(DEVKITPRO)/libnx/switch_rules
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
TARGET := KosmosUpdater
BUILD := build
SOURCES := source source/models source/scenes source/views
DATA := data
INCLUDES := include
ROMFS := romfs
SOURCES := Source Source/Managers Source/Scenes Source/Views
ROMFS := RomFS
APP_TITLE := Kosmos Updater
APP_AUTHOR := Nichole Mattera
APP_VERSION := 3.0.9
APP_VERSION_MAJOR := 3
APP_VERSION_MINOR := 0
APP_VERSION_PATCH := 9
API_VERSION := v4
SETTING_CONFIG_VERSION := 1
INTERNAL_CONFIG_VERSION := 2
APP_VERSION := 4.0.0
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
DEFINES += -D__SWITCH__ \
-DVERSION=\"$(APP_VERSION)\" \
-DVERSION_MAJOR=$(APP_VERSION_MAJOR) \
-DVERSION_MINOR=$(APP_VERSION_MINOR) \
-DVERSION_PATCH=$(APP_VERSION_PATCH) \
-DAPI_VERSION=\"$(API_VERSION)\" \
-DSETTING_CONFIG_VERSION=$(SETTING_CONFIG_VERSION) \
-DINTERNAL_CONFIG_VERSION=$(INTERNAL_CONFIG_VERSION)
DEFINES += -D__SWITCH__ -DDEBUG -DVERSION=\"$(APP_VERSION)\"
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES) $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
-Wl,-Map,$(notdir $*.map)
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx \
-lfreetype \
-lwebp -lpng -ljpeg \
-lSwurl -lcurl -lz -lmbedtls -lmbedcrypto -lmbedx509 \
-lSimpleIniParser -lminizip -lconfig -lnx `sdl2-config --libs` `freetype-config --libs`
ifneq ($(shell which ccache),)
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lpng -lcurl -lz -lmbedtls -lmbedx509 -lmbedcrypto -ljansson -lnx
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/SimpleIniParser $(CURDIR)/Swurl
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
@ -108,7 +81,7 @@ export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
@ -137,8 +110,8 @@ export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
@ -190,15 +163,7 @@ endif
all: $(BUILD)
$(BUILD):
ifeq ($(wildcard $(CURDIR)/SimpleIniParser/LICENSE),)
@$(error "Please run 'git submodule update --init' before running 'make'")
endif
ifeq ($(wildcard $(CURDIR)/Swurl/LICENSE),)
@$(error "Please run 'git submodule update --init' before running 'make'")
endif
@[ -d $@ ] || mkdir -p $@
@$(MAKE) -C $(CURDIR)/SimpleIniParser -f $(CURDIR)/SimpleIniParser/Makefile
@$(MAKE) -C $(CURDIR)/Swurl -f $(CURDIR)/Swurl/Makefile
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------


+ 2
- 19
README.md View File

@ -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.

romfs/light/icon.png → RomFS/0_icon.png View File


romfs/dark/icon.png → RomFS/1_icon.png View File


+ 0
- 1
SimpleIniParser

@ -1 +0,0 @@
Subproject commit a7f88f6671e5f4935a550d0b6cfd5c078b51e9fc

+ 110
- 0
Source/Application.cpp View File

@ -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);
}
}

+ 53
- 0
Source/Application.hpp View File

@ -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);
};
}

+ 57
- 0
Source/Draw.cpp View File

@ -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;
}
}

+ 54
- 0
Source/Draw.hpp View File

@ -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);
};
}

+ 72
- 0
Source/Image.cpp View File

@ -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;
}
}

+ 41
- 0
Source/Image.hpp View File

@ -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);
};
}

+ 71
- 0
Source/Main.cpp View 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);
}

+ 55
- 0
Source/Managers/Theme.cpp View File

@ -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);
}
}
}

+ 50
- 0
Source/Managers/Theme.hpp View File

@ -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&){};
};
}

+ 48
- 0
Source/Scene.cpp View File

@ -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);
}
}

+ 49
- 0
Source/Scene.hpp View File

@ -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:
};
}

+ 42
- 0
Source/Scenes/Root.cpp View File

@ -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);
}
}

+ 40
- 0
Source/Scenes/Root.hpp View File

@ -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;
};
}

+ 86
- 0
Source/View.cpp View File

@ -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);
}
}

+ 61
- 0
Source/View.hpp View File

@ -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:
};
}

+ 20
- 0
Source/Views/Footer.cpp View File

@ -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"

+ 31
- 0
Source/Views/Footer.hpp View File

@ -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:
};
}

+ 20
- 0
Source/Views/Header.cpp View File

@ -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"

+ 31
- 0
Source/Views/Header.hpp View File

@ -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:
};
}

+ 0
- 1
Swurl

@ -1 +0,0 @@
Subproject commit dc6435ff5ac538ee0fd732c71f7b215dfd9e5f5a

BIN
romfs/dark/downloading.png View File

Before After
Width: 479  |  Height: 197  |  Size: 5.8 KiB

BIN
romfs/light/downloading.png View File

Before After
Width: 479  |  Height: 197  |  Size: 5.8 KiB

+ 0
- 140
source/AssetManager.cpp View File

@ -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;
}
}

+ 0
- 71
source/AssetManager.hpp View File

@ -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);
};
}

+ 0
- 372
source/ConfigManager.cpp View 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) {