Browse Source

Merging repos.

sdl-reimagine
Nichole Mattera 10 months ago
parent
commit
570a8951e7
102 changed files with 2708 additions and 4128 deletions
  1. +0
    -6
      .gitmodules
  2. +16
    -38
      Makefile
  3. +1
    -18
      README.md
  4. +10
    -0
      RomFS/config.cfg
  5. +0
    -0
      RomFS/dark/downloading.png
  6. +0
    -0
      RomFS/dark/icon.png
  7. +12
    -0
      RomFS/lang.en-us.cfg
  8. +0
    -0
      RomFS/light/downloading.png
  9. +0
    -0
      RomFS/light/icon.png
  10. +0
    -1
      SimpleIniParser
  11. +244
    -0
      Source/Application.cpp
  12. +59
    -0
      Source/Application.hpp
  13. +53
    -0
      Source/Constants.hpp
  14. +50
    -0
      Source/Modal.cpp
  15. +46
    -0
      Source/Modal.hpp
  16. +38
    -0
      Source/Models/FooterAction.hpp
  17. +32
    -0
      Source/Models/TextLine.hpp
  18. +40
    -0
      Source/Scene.cpp
  19. +50
    -0
      Source/Scene.hpp
  20. +119
    -0
      Source/Scenes/AppUpdateScene.cpp
  21. +62
    -0
      Source/Scenes/AppUpdateScene.hpp
  22. +24
    -0
      Source/Scenes/CompletionScene.cpp
  23. +31
    -0
      Source/Scenes/CompletionScene.hpp
  24. +24
    -0
      Source/Scenes/ConfirmationScene.cpp
  25. +31
    -0
      Source/Scenes/ConfirmationScene.hpp
  26. +110
    -0
      Source/Scenes/ExFatWarningScene.cpp
  27. +46
    -0
      Source/Scenes/ExFatWarningScene.hpp
  28. +24
    -0
      Source/Scenes/PackageInstallationScene.cpp
  29. +31
    -0
      Source/Scenes/PackageInstallationScene.hpp
  30. +188
    -0
      Source/Utils/ConfigManager.cpp
  31. +74
    -0
      Source/Utils/ConfigManager.hpp
  32. +92
    -0
      Source/Utils/FontManager.cpp
  33. +55
    -0
      Source/Utils/FontManager.hpp
  34. +127
    -0
      Source/Utils/StringManager.cpp
  35. +57
    -0
      Source/Utils/StringManager.hpp
  36. +72
    -0
      Source/Utils/ThemeManager.cpp
  37. +57
    -0
      Source/Utils/ThemeManager.hpp
  38. +69
    -0
      Source/Utils/VersionService.cpp
  39. +31
    -0
      Source/Utils/VersionService.hpp
  40. +86
    -0
      Source/View.cpp
  41. +61
    -0
      Source/View.hpp
  42. +56
    -0
      Source/Views/FooterView.cpp
  43. +40
    -0
      Source/Views/FooterView.hpp
  44. +76
    -0
      Source/Views/HeaderView.cpp
  45. +43
    -0
      Source/Views/HeaderView.hpp
  46. +35
    -0
      Source/Views/ImageView.cpp
  47. +37
    -0
      Source/Views/ImageView.hpp
  48. +67
    -0
      Source/Views/ProgressBarView.cpp
  49. +35
    -0
      Source/Views/ProgressBarView.hpp
  50. +111
    -0
      Source/Views/TextView.cpp
  51. +55
    -0
      Source/Views/TextView.hpp
  52. +31
    -0
      Source/main.cpp
  53. +0
    -1
      Swurl
  54. +0
    -140
      source/AssetManager.cpp
  55. +0
    -71
      source/AssetManager.hpp
  56. +0
    -372
      source/ConfigManager.cpp
  57. +0
    -116
      source/ConfigManager.hpp
  58. +0
    -303
      source/FileManager.cpp
  59. +0
    -43
      source/FileManager.hpp
  60. +0
    -32
      source/ModalView.cpp
  61. +0
    -37
      source/ModalView.hpp
  62. +0
    -65
      source/Scene.cpp
  63. +0
    -48
      source/Scene.hpp
  64. +0
    -206
      source/SceneDirector.cpp
  65. +0
    -65
      source/SceneDirector.hpp
  66. +0
    -49
      source/View.cpp
  67. +0
    -50
      source/View.hpp
  68. +0
    -77
      source/main.cpp
  69. +0
    -37
      source/models/Action.cpp
  70. +0
    -43
      source/models/Action.hpp
  71. +0
    -21
      source/models/Touch.cpp
  72. +0
    -23
      source/models/Touch.hpp
  73. +0
    -177
      source/scenes/AppUpdateScene.cpp
  74. +0
    -56
      source/scenes/AppUpdateScene.hpp
  75. +0
    -83
      source/scenes/ExFatWarningScene.cpp
  76. +0
    -42
      source/scenes/ExFatWarningScene.hpp
  77. +0
    -171
      source/scenes/PackageDownloadScene.cpp
  78. +0
    -57
      source/scenes/PackageDownloadScene.hpp
  79. +0
    -212
      source/scenes/PackageSelectScene.cpp
  80. +0
    -60
      source/scenes/PackageSelectScene.hpp
  81. +0
    -56
      source/views/AlertButtonView.cpp
  82. +0
    -40
      source/views/AlertButtonView.hpp
  83. +0
    -125
      source/views/AlertView.cpp
  84. +0
    -49
      source/views/AlertView.hpp
  85. +0
    -84
      source/views/ControlView.cpp
  86. +0
    -32
      source/views/ControlView.hpp
  87. +0
    -125
      source/views/FooterView.cpp
  88. +0
    -37
      source/views/FooterView.hpp
  89. +0
    -73
      source/views/HeaderView.cpp
  90. +0
    -36
      source/views/HeaderView.hpp
  91. +0
    -33
      source/views/ImageView.cpp
  92. +0
    -35
      source/views/ImageView.hpp
  93. +0
    -129
      source/views/ListRowView.cpp
  94. +0
    -58
      source/views/ListRowView.hpp
  95. +0
    -64
      source/views/ProgressBarView.cpp
  96. +0
    -32
      source/views/ProgressBarView.hpp
  97. +0
    -61
      source/views/StatusView.cpp
  98. +0
    -41
      source/views/StatusView.hpp
  99. +0
    -118
      source/views/TextView.cpp
  100. +0
    -63
      source/views/TextView.hpp

+ 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

+ 16
- 38
Makefile View File

@ -37,38 +37,28 @@ 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))
BUILD := build
SOURCES := source source/models source/scenes source/views
DATA := data
INCLUDES := include
ROMFS := romfs
TARGET := KosmosUpdater
BUILD := Build
SOURCES := Source Source/Models Source/Scenes Source/Utils Source/Views
ROMFS := RomFS
APP_TITLE := Kosmos Updater
APP_AUTHOR := Nichole Mattera
APP_VERSION := 3.0.9
APP_VERSION_MAJOR := 3
APP_VERSION_MAJOR := 4
APP_VERSION_MINOR := 0
APP_VERSION_PATCH := 9
API_VERSION := v4
SETTING_CONFIG_VERSION := 1
INTERNAL_CONFIG_VERSION := 2
APP_VERSION_PATCH := 0
APP_VERSION := $(APP_VERSION_MAJOR).$(APP_VERSION_MINOR).$(APP_VERSION_PATCH)
#---------------------------------------------------------------------------------
# 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)
-DVERSION_PATCH=$(APP_VERSION_PATCH)
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES) $(INCLUDE)
@ -76,14 +66,10 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \
CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
-Wl,-Map,$(notdir $*.map)
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`
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx -lpng -lconfig++ -lnx \
`sdl2-config --libs` `freetype-config --libs`
ifneq ($(shell which ccache),)
CXX := $(shell which ccache) $(CXX)
@ -94,7 +80,7 @@ endif
# 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 +94,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 +123,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 +176,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
#---------------------------------------------------------------------------------


+ 1
- 18
README.md View File

@ -1,20 +1,3 @@
# Kosmos Updater
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 clean up Kosmos Updater codebase, but keep SDL. This was code I was working on for Skyline (UI Library). Even then this UI code is out of date with the effort I put into Chocolate Doom Launcher, so I would recommend looking at that project.

+ 10
- 0
RomFS/config.cfg View File

@ -0,0 +1,10 @@
auto_update = true;
ignored_files = [ ];
install_es_patches = false;
installed_files = [ ];
installed_version = "";
proxy_enabled = false;
proxy_url = "";
proxy_username = "";
proxy_password = "";
hide_exfat_warning = false;

romfs/dark/downloading.png → RomFS/dark/downloading.png View File


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


+ 12
- 0
RomFS/lang.en-us.cfg View File

@ -0,0 +1,12 @@
WarningHeader = "Warning - SD Card Corruption";
WarningBody = "Kosmos Updater may cause corruption to your SD card if it is formatted as ExFAT. This\nis due to an issue with Nintendo's ExFAT drivers built into the Switch. It is recommended\nthat you use an SD card formatted as FAT32, however if you wish to continue and you are\nusing ExFAT you do so at your own risk. This warning will not show up again.";
WarningFooter = "Press any button or tap to continue.";
AppTitle = "Kosmos Updater";
ActionQuit = "Quit";
CheckingKosmosUpdaterUpdate = "Checking for updates to Kosmos Updater...";
DownloadKosmosUpdaterUpdate = "Getting the latest version of Kosmos Updater...";
SuccessKosmosUpdaterUpdateText = "Kosmos Updater has been updated to version %s!";
SuccessKosmosUpdaterUpdateSubtext = "Please restart the app to update your files.";
ErrorKosmosUpdaterUpdateText = "Please restart the app to try again.";

romfs/light/downloading.png → RomFS/light/downloading.png View File


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


+ 0
- 1
SimpleIniParser

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

+ 244
- 0
Source/Application.cpp View File

@ -0,0 +1,244 @@
/*
* 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 <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include "Application.hpp"
#include "Constants.hpp"
#include "Utils/FontManager.hpp"
#include "Utils/ThemeManager.hpp"
#include "Utils/VersionService.hpp"
using namespace KosmosUpdater::Utils;
namespace KosmosUpdater {
Application::Application() {
currentApplication = this;
Result rc;
#ifdef DEBUG
nxlinkStdio();
#endif
rc = romfsInit();
if (R_FAILED(rc))
return;
_initializedServices |= ROMFS_SERVICE;
rc = setInitialize();
if (R_FAILED(rc))
return;
_initializedServices |= SET_SERVICE;
rc = setsysInitialize();
if (R_FAILED(rc))
return;
_initializedServices |= SETSYS_SERVICE;
rc = plInitialize();
if (R_FAILED(rc))
return;
_initializedServices |= PL_SERVICE;
if (!SDL_Init(SDL_INIT_EVERYTHING))
return;
_initializedServices |= SDL_SERVICE;
if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG))
return;
_initializedServices |= SDL_IMG_SERVICE;
window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_FULLSCREEN);
if (!window)
return;
renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE);
if (!renderer)
return;
SDL_SetRenderDrawBlendMode(Application::renderer, SDL_BLENDMODE_BLEND);
if (TTF_Init() == -1)
return;
_initializedServices |= SDL_TTF_SERVICE;
_nowTime = _lastTime = SDL_GetPerformanceCounter();
_initialized = true;
}
Application::~Application() {
FontManager::Instance()->dealloc();
if (_currentScene != NULL)
delete _currentScene;
if (_initializedServices & SDL_TTF_SERVICE)
TTF_Quit();
if (renderer != NULL)
SDL_DestroyRenderer(renderer);
if (window != NULL)
SDL_DestroyWindow(window);
if (_initializedServices & SDL_IMG_SERVICE)
IMG_Quit();
if (_initializedServices & SDL_SERVICE)
SDL_Quit();
if (_initializedServices & PL_SERVICE)
plExit();
if (_initializedServices & SETSYS_SERVICE)
setsysExit();
if (_initializedServices & SET_SERVICE)
setExit();
if (_initializedServices & ROMFS_SERVICE)
romfsExit();
}
int Application::start(Scene * scene) {
if (!_initialized || !window || !renderer)
return -1;
_currentScene = scene;
// Main Game Loop
while (appletMainLoop())
{
double dTime = _getDeltaTime();
// Handle controller inputs
hidScanInput();
if (modal != NULL) {
_processControllerForModal(CONTROLLER_P1_AUTO, dTime);
} else {
_processControllerForScene(CONTROLLER_P1_AUTO, dTime);
}
if (_handlePossibleSceneChange())
break;
_render(dTime);
if (_handlePossibleSceneChange())
break;
// Present our frame.
SDL_RenderPresent(renderer);
}
return 0;
}
void Application::render() {
double dTime = _getDeltaTime();
_render(dTime);
// Present our frame.
SDL_RenderPresent(renderer);
}
void Application::switchScene(Scene * scene) {
if (_currentScene != NULL) {
_previousScene = _currentScene;
}
_currentScene = scene;
}
double Application::_getDeltaTime() {
_lastTime = _nowTime;
_nowTime = SDL_GetPerformanceCounter();
return (double) ((_nowTime - _lastTime) * 1000 / SDL_GetPerformanceFrequency());
}
void Application::_processControllerForModal(HidControllerID id, double dTime) {
if (modal->enabledEvents & BUTTON_HELD_EVENT) {
u32 kHeld = hidKeysHeld(id);
modal->buttonsHeld(kHeld, dTime);
}
if (modal->enabledEvents & BUTTON_DOWN_EVENT) {
u32 kDown = hidKeysDown(id);
modal->buttonsDown(kDown, dTime);
}
if (modal->enabledEvents & BUTTON_UP_EVENT) {
u32 kHeld = hidKeysUp(id);
modal->buttonsUp(kHeld, dTime);
}
}
void Application::_processControllerForScene(HidControllerID id, double dTime) {
if (_currentScene != NULL && _currentScene->enabledEvents & BUTTON_HELD_EVENT) {
u32 kHeld = hidKeysHeld(id);
_currentScene->buttonsHeld(kHeld, dTime);
}
if (_currentScene != NULL && _currentScene->enabledEvents & BUTTON_DOWN_EVENT) {
u32 kDown = hidKeysDown(id);
_currentScene->buttonsDown(kDown, dTime);
}
if (_currentScene != NULL && _currentScene->enabledEvents & BUTTON_UP_EVENT) {
u32 kHeld = hidKeysUp(id);
_currentScene->buttonsUp(kHeld, dTime);
}
}
bool Application::_handlePossibleSceneChange() {
// We should clean up our previous scene after switching.
if (_previousScene != NULL) {
delete _previousScene;
_previousScene = NULL;
}
// Kill the app when there is no scene.
if (_currentScene == NULL) {
return true;
}
return false;
}
void Application::_render(double dTime) {
// Clear the screen.
SDL_SetRenderDrawColor(
renderer,
_currentScene->background.r,
_currentScene->background.g,
_currentScene->background.b,
_currentScene->background.a
);
SDL_RenderClear(renderer);
// Call rendering routines.
_currentScene->render({ 0, 0, 1280, 720 }, dTime);
if (modal != NULL) {
modal->render({ 0, 0, 1280, 720 }, dTime);
}
}
}

+ 59
- 0
Source/Application.hpp View File

@ -0,0 +1,59 @@
/*
* 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 <SDL2/SDL.h>
#include "Modal.hpp"
#include "Scene.hpp"
#pragma once
namespace KosmosUpdater {
class Application {
public:
static inline Application * currentApplication = NULL;
static inline SDL_Window * window = NULL;
static inline SDL_Renderer * renderer = NULL;
static inline Modal * modal = NULL;
Application();
~Application();
int start(Scene * scene);
void render();
static void switchScene(Scene * scene);
private:
bool _initialized = false;
u8 _initializedServices = 0;
u64 _nowTime;
u64 _lastTime;
static inline Scene * _currentScene = NULL;
static inline Scene * _previousScene = NULL;
double _getDeltaTime();
void _processControllerForModal(HidControllerID id, double dTime);
void _processControllerForScene(HidControllerID id, double dTime);
bool _handlePossibleSceneChange();
void _render(double dTime);
};
}

+ 53
- 0
Source/Constants.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 <switch.h>
#pragma once
namespace KosmosUpdater {
typedef enum {
BUTTON_HELD_EVENT = BIT(0),
BUTTON_DOWN_EVENT = BIT(1),
BUTTON_UP_EVENT = BIT(2)
} EventTypes;
typedef enum {
ROMFS_SERVICE = BIT(0),
SETSYS_SERVICE = BIT(1),
PL_SERVICE = BIT(2),
SDL_SERVICE = BIT(3),
SDL_IMG_SERVICE = BIT(4),
SDL_TTF_SERVICE = BIT(5),
SET_SERVICE = BIT(6)
} Services;
typedef enum {
LEFT_ALIGN,
CENTER_ALIGN,
RIGHT_ALIGN
} TextAlignment;
typedef enum {
A_BUTTON,
B_BUTTON,
X_BUTTON,
Y_BUTTON
} FooterActionButton;
}

+ 50
- 0
Source/Modal.cpp 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 "Modal.hpp"
#include "Utils/ThemeManager.hpp"
#include "Application.hpp"
using namespace KosmosUpdater::Utils;
namespace KosmosUpdater {
void Modal::buttonsHeld(u32 buttons, double dTime) {}
void Modal::buttonsDown(u32 buttons, double dTime) {}
void Modal::buttonsUp(u32 buttons, double dTime) {}
void Modal::render(SDL_Rect rect, double dTime) {
// Draw Faded background.
SDL_Color background = ThemeManager::Instance()->modal_faded_background;
SDL_SetRenderDrawColor(Application::renderer, background.r, background.g, background.b, background.a);
SDL_RenderFillRect(Application::renderer, &rect);
View::render(rect, dTime);
}
void Modal::show() {
Application::modal = this;
}
void Modal:: dismiss(bool success) {
Application::modal = NULL;
if (onDismiss) {
onDismiss(this, success);
}
}
}

+ 46
- 0
Source/Modal.hpp View File

@ -0,0 +1,46 @@
/*
* 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 <functional>
#include <switch.h>
#include "Constants.hpp"
#include "View.hpp"
#pragma once
namespace KosmosUpdater {
class Modal : public View {
public:
u8 enabledEvents = BUTTON_DOWN_EVENT;
std::function<void(Modal *, bool)> onDismiss;
virtual void buttonsHeld(u32 buttons, double dTime);
virtual void buttonsDown(u32 buttons, double dTime);
virtual void buttonsUp(u32 buttons, double dTime);
virtual void render(SDL_Rect rect, double dTime);
void show();
void dismiss(bool success);
private:
};
}

+ 38
- 0
Source/Models/FooterAction.hpp View File

@ -0,0 +1,38 @@
/*
* 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 <SDL2/SDL.h>
#include <string>
#include "../Constants.hpp"
#pragma once
namespace KosmosUpdater::Models {
class FooterAction {
public:
FooterActionButton button;
std::string text;
SDL_Texture * texture;
int width;
int height;
};
}

+ 32
- 0
Source/Models/TextLine.hpp View File

@ -0,0 +1,32 @@
/*
* 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 <SDL2/SDL.h>
#pragma once
namespace KosmosUpdater::Models {
class TextLine {
public:
SDL_Texture * texture;
int width;
int height;
};
}

+ 40
- 0
Source/Scene.cpp 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 "Scene.hpp"
namespace KosmosUpdater {
void Scene::render(SDL_Rect rect, double dTime) {
for (auto const& view : subviews) {
if (!view->isHidden) {
SDL_Rect subviewFrame = view->frame;
view->render({ rect.x + subviewFrame.x, rect.y + subviewFrame.y, subviewFrame.w, subviewFrame.h }, dTime);
}
}
}
void Scene::addSubView(View * view) {
view->superview = NULL;
subviews.push_back(view);
}
void Scene::removeSubView(View * view) {
view->superview = NULL;
subviews.push_back(view);
}
}

+ 50
- 0
Source/Scene.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 <list>
#include <switch.h>
#include "Constants.hpp"
#include "View.hpp"
#pragma once
namespace KosmosUpdater {
class Scene {
public:
SDL_Color background = { 0, 0, 0, 255 };
u8 enabledEvents = BUTTON_DOWN_EVENT;
std::list<View *> subviews;
Scene(){};
virtual ~Scene(){};
virtual void buttonsHeld(u32 buttons, double dTime){};
virtual void buttonsDown(u32 buttons, double dTime){};
virtual void buttonsUp(u32 buttons, double dTime){};
virtual void render(SDL_Rect rect, double dTime);
void addSubView(View * view);
void removeSubView(View * view);
private:
};
}

+ 119
- 0
Source/Scenes/AppUpdateScene.cpp View File

@ -0,0 +1,119 @@
/*
* 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 <SDL2/SDL_image.h>
#include "AppUpdateScene.hpp"
#include "../Application.hpp"
#include "../Utils/FontManager.hpp"
#include "../Utils/StringManager.hpp"
#include "../Utils/ThemeManager.hpp"
#include "../Utils/VersionService.hpp"
using namespace KosmosUpdater;
using namespace KosmosUpdater::Utils;
using namespace KosmosUpdater::Views;
namespace KosmosUpdater::Scenes {
AppUpdateScene::AppUpdateScene() {
auto fm = FontManager::Instance();
auto sm = StringManager::Instance();
auto tm = ThemeManager::Instance();
background = tm->background;
_headerView = new HeaderView(sm->getLocalizedString(AppTitle), true);
_headerView->frame = { 0, 0, 1280, 88 };
addSubView(_headerView);
auto path = tm->getAssetDirectory() + "/downloading.png";
auto image = IMG_Load(path.c_str());
_downloading = SDL_CreateTextureFromSurface(Application::renderer, image);
SDL_FreeSurface(image);
_downloadImageView = new ImageView(_downloading);
_downloadImageView->frame = { 400, 200, 479, 197 };
addSubView(_downloadImageView);
_progressBarView = new ProgressBarView();
_progressBarView->frame = { 437, 457, 411, 10 };
addSubView(_progressBarView);
auto textColor = tm->text;
auto subBodyFont = fm->getFont(StandardFont, 18);
_statusTextView = new TextView(subBodyFont, sm->getLocalizedString(CheckingKosmosUpdaterUpdate), textColor);
_statusTextView->frame = { 0, 491, 1280, 21 };
_statusTextView->textAlignment = CENTER_ALIGN;
addSubView(_statusTextView);
_footerView = new FooterView();
_footerView->frame = { 0, 647, 1280, 73 };
addSubView(_footerView);
}
AppUpdateScene::~AppUpdateScene() {
if (_headerView != NULL)
delete _headerView;
if (_downloading != NULL)
SDL_DestroyTexture(_downloading);
if (_downloadImageView != NULL)
delete _downloadImageView;
if (_progressBarView != NULL)
delete _progressBarView;
if (_statusTextView != NULL)
delete _statusTextView;
if (_footerView != NULL)
delete _footerView;
}
void AppUpdateScene::buttonsDown(u32 buttons, double dTime) {
if (_state == ErrorState) {
if (buttons & KEY_A) {
Application::switchScene(NULL);
}
} else {
if (buttons & KEY_A) {
Application::switchScene(NULL);
}
}
}
void AppUpdateScene::render(SDL_Rect rect, double dTime) {
Scene::render(rect, dTime);
if (_state == InitState) {
_state = DownloadingVersionNumberState;
// TODO: Download Version Number.
} else if (_state == DownloadedVersionNumberState) {
// TODO: Check if version number is newer, then switch scense or download binary.
} else if (_state == DownloadedBinaryState) {
// TODO: Unload romfs, replace binary, and switch scenes.
}
}
void AppUpdateScene::_onProgressUpdate(double progress) {
_progressBarView->setProgress(progress);
Application::currentApplication->render();
}
}

+ 62
- 0
Source/Scenes/AppUpdateScene.hpp View File

@ -0,0 +1,62 @@
/*
* 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 <SDL2/SDL.h>
#include "../Scene.hpp"
#include "../Views/FooterView.hpp"
#include "../Views/HeaderView.hpp"
#include "../Views/ImageView.hpp"
#include "../Views/ProgressBarView.hpp"
#include "../Views/TextView.hpp"
#pragma once
namespace KosmosUpdater::Scenes {
typedef enum {
InitState = 0,
DownloadingVersionNumberState = 1,
DownloadedVersionNumberState = 2,
DownloadingBinaryState = 3,
DownloadedBinaryState = 4,
ErrorState = 5,
} AppUpdateState;
class AppUpdateScene : public KosmosUpdater::Scene {
public:
AppUpdateScene();
~AppUpdateScene();
void buttonsDown(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
SDL_Texture * _downloading = NULL;
KosmosUpdater::Views::HeaderView * _headerView = NULL;
KosmosUpdater::Views::ImageView * _downloadImageView = NULL;
KosmosUpdater::Views::ProgressBarView * _progressBarView = NULL;
KosmosUpdater::Views::TextView * _statusTextView = NULL;
KosmosUpdater::Views::FooterView * _footerView = NULL;
AppUpdateState _state = InitState;
void _onProgressUpdate(double progress);
};
}

+ 24
- 0
Source/Scenes/CompletionScene.cpp View File

@ -0,0 +1,24 @@
/*
* 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 "CompletionScene.hpp"
namespace KosmosUpdater::Scenes {
}

+ 31
- 0
Source/Scenes/CompletionScene.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 "../Scene.hpp"
#pragma once
namespace KosmosUpdater::Scenes {
class CompletionScene : public KosmosUpdater::Scene {
public:
private:
};
}

+ 24
- 0
Source/Scenes/ConfirmationScene.cpp View File

@ -0,0 +1,24 @@
/*
* 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 "ConfirmationScene.hpp"
namespace KosmosUpdater::Scenes {
}

+ 31
- 0
Source/Scenes/ConfirmationScene.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 "../Scene.hpp"
#pragma once
namespace KosmosUpdater::Scenes {
class ConfirmationScene : public KosmosUpdater::Scene {
public:
private:
};
}

+ 110
- 0
Source/Scenes/ExFatWarningScene.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 "AppUpdateScene.hpp"
#include "ExFatWarningScene.hpp"
#include "../Application.hpp"
#include "../Utils/ConfigManager.hpp"
#include "../Utils/FontManager.hpp"
#include "../Utils/StringManager.hpp"
#include "../Utils/ThemeManager.hpp"
#include "../Views/TextView.hpp"
using namespace KosmosUpdater;
using namespace KosmosUpdater::Utils;
using namespace KosmosUpdater::Views;
namespace KosmosUpdater::Scenes {
ExFatWarningScene::ExFatWarningScene() {
auto cm = ConfigManager::Instance();
auto fm = FontManager::Instance();
auto tm = ThemeManager::Instance();
auto sm = StringManager::Instance();
if (cm->shouldHideExFatWarning()) {
_skipWarning = true;
return;
}
background = tm->background;
auto textColor = tm->text;
auto headerFont = fm->getFont(StandardFont, 28);
auto bodyFont = fm->getFont(StandardFont, 23);
_headerTextView = new TextView(headerFont, sm->getLocalizedString(WarningHeader), textColor);
_headerTextView->frame = { 0, 122, 1280, 33 };
_headerTextView->textAlignment = CENTER_ALIGN;
_bodyTextView = new TextView(bodyFont, sm->getLocalizedString(WarningBody), textColor);
_bodyTextView->frame = { 0, 272, 1280, 178 };
_bodyTextView->textAlignment = CENTER_ALIGN;
_bodyTextView->lineHeight = 50;
_footerTextView = new TextView(headerFont, sm->getLocalizedString(WarningFooter), textColor);
_footerTextView->frame = { 0, 567, 1280, 34 };
_footerTextView->textAlignment = CENTER_ALIGN;
_footerTextView->alpha = 0;
addSubView(_headerTextView);
addSubView(_bodyTextView);
addSubView(_footerTextView);
}
ExFatWarningScene::~ExFatWarningScene() {
if (_headerTextView != NULL)
delete _headerTextView;
if (_bodyTextView != NULL)
delete _bodyTextView;
if (_footerTextView != NULL)
delete _footerTextView;
}
void ExFatWarningScene::buttonsDown(u32 buttons, double dTime) {
if (buttons > 0 && _footerVisible) {
ConfigManager::Instance()->setHideExFatWarning(true);
ConfigManager::Instance()->synchronize();
_showAppUpdateScene();
}
}
void ExFatWarningScene::render(SDL_Rect rect, double dTime) {
if (_skipWarning) {
_showAppUpdateScene();
} else if (_footerVisible == false) {
_timeSpent += dTime;
if (_timeSpent >= 0 && _timeSpent < 1000) {
_footerTextView->alpha = _timeSpent / 1000 * 255;
} else if (_timeSpent >= 1 && !_footerVisible) {
_footerVisible = true;
_footerTextView->alpha = 255;
}
}
Scene::render(rect, dTime);
}
void ExFatWarningScene::_showAppUpdateScene() {
Application::switchScene(new AppUpdateScene());
}
}

+ 46
- 0
Source/Scenes/ExFatWarningScene.hpp View File

@ -0,0 +1,46 @@
/*
* 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"
#include "../Views/TextView.hpp"
#pragma once
namespace KosmosUpdater::Scenes {
class ExFatWarningScene : public KosmosUpdater::Scene {
public:
ExFatWarningScene();
~ExFatWarningScene();
void buttonsDown(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
double _timeSpent = -10000;
bool _footerVisible = false;
bool _skipWarning = false;
KosmosUpdater::Views::TextView * _headerTextView = NULL;
KosmosUpdater::Views::TextView * _bodyTextView = NULL;
KosmosUpdater::Views::TextView * _footerTextView = NULL;
void _showAppUpdateScene();
};
}

+ 24
- 0
Source/Scenes/PackageInstallationScene.cpp View File

@ -0,0 +1,24 @@
/*
* 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 "PackageInstallationScene.hpp"
namespace KosmosUpdater::Scenes {
}

+ 31
- 0
Source/Scenes/PackageInstallationScene.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 "../Scene.hpp"
#pragma once
namespace KosmosUpdater::Scenes {
class PackageInstallationScene : public KosmosUpdater::Scene {
public:
private:
};
}

+ 188
- 0
Source/Utils/ConfigManager.cpp View File

@ -0,0 +1,188 @@
/*
* 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 <fstream>
#include <iostream>
#include "ConfigManager.hpp"
namespace KosmosUpdater::Utils {
ConfigManager * ConfigManager::Instance() {
if (_instance == NULL) {
_instance = new ConfigManager;
}
return _instance;
}
bool ConfigManager::shouldAutoUpdate() {
if (!_configLoaded || !_config.exists("auto_update")) return false;
return _config.lookup("auto_update");
}
void ConfigManager::setAutoUpdate(bool value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("auto_update");
setting = value;
}
std::vector<std::string> ConfigManager::getFilesToIgnore() {
std::vector<std::string> value;
if (!_configLoaded || !_config.exists("ignored_files")) return value;
libconfig::Setting & setting = _config.lookup("ignored_files");
for (int i = 0; i < setting.getLength(); i++) {
value.push_back(setting[i]);
}
return value;
}
void ConfigManager::pushFilesToIgnore(std::string value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("ignored_files");
setting.add(libconfig::Setting::TypeString);
setting[setting.getLength() - 1] = value;
}
void ConfigManager::removeFileFromIgnore(int index) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("ignored_files");
if (index >= setting.getLength() || index < 0) return;
setting.remove(index);
}
bool ConfigManager::shouldInstallESPatches() {
if (!_configLoaded || !_config.exists("install_es_patches")) return false;
return _config.lookup("install_es_patches");
}
void ConfigManager::setInstallESPatches(bool value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("install_es_patches");
setting = value;
}
std::string ConfigManager::getInstalledVersion() {
if (!_configLoaded || !_config.exists("installed_version")) return "";
return _config.lookup("installed_version");
}
void ConfigManager::setInstalledVersion(std::string value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("installed_version");
setting = value;
}
bool ConfigManager::shouldUseProxy() {
if (!_configLoaded) return false;
return _config.lookup("proxy_enabled");
}
void ConfigManager::setUseProxy(bool value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("proxy_enabled");
setting = value;
}
std::string ConfigManager::getProxy() {
if (!_configLoaded) return "";
return _config.lookup("proxy_url");
}
void ConfigManager::setProxy(std::string value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("proxy_url");
setting = value;
}
std::string ConfigManager::getProxyUsername() {
if (!_configLoaded) return "";
return _config.lookup("proxy_username");
}
void ConfigManager::setProxyUsername(std::string value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("proxy_username");
setting = value;
}
std::string ConfigManager::getProxyPassword() {
if (!_configLoaded) return "";
return _config.lookup("proxy_password");
}
void ConfigManager::setProxyPassword(std::string value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("proxy_password");
setting = value;
}
bool ConfigManager::shouldHideExFatWarning() {
if (!_configLoaded || !_config.exists("hide_exfat_warning")) return false;
return _config.lookup("hide_exfat_warning");
}
void ConfigManager::setHideExFatWarning(bool value) {
if (!_configLoaded) return;
libconfig::Setting & setting = _config.lookup("hide_exfat_warning");
setting = value;
}
bool ConfigManager::synchronize() {
try {
_config.writeFile("config.cfg");
return true;
} catch (...) {
return false;
}
}
ConfigManager::ConfigManager() {
try {
_config.readFile("config.cfg");
_configLoaded = true;
} catch (...) {
_createDefaultConfig();
}
}
void ConfigManager::_createDefaultConfig() {
try {
_config.readFile("romfs:/config.cfg");
_configLoaded = true;
if (_kosmosToolboxConfigPath())
pushFilesToIgnore("sdmc:/switch/KosmosToolbox/config.json");
synchronize();
} catch (...) {
_configLoaded = false;
}
}
bool ConfigManager::_kosmosToolboxConfigPath() {
std::ifstream file("sdmc:/switch/KosmosToolbox/config.json");
if (file.fail())
return false;
file.close();
return true;
}
}

+ 74
- 0
Source/Utils/ConfigManager.hpp View File

@ -0,0 +1,74 @@
/*
* 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