Skip to content

Commit

Permalink
Merge pull request #3 from AnxietyWump/master
Browse files Browse the repository at this point in the history
teehee
  • Loading branch information
fennectech committed May 25, 2020
2 parents d8277f8 + 0923004 commit 57ac5c0
Show file tree
Hide file tree
Showing 50 changed files with 200 additions and 163 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -17,3 +17,4 @@ A homebrew application for the Nintendo Switch that will automatically update yo

* Thanks to vgmoose for examples on using minizip in appstorenx.
* Thanks to y4my4m and natinusala in the ReSwitched discord for their discussions around libcurl.
* Thanks to alex. for improving the config and other elements in FileManager.
2 changes: 1 addition & 1 deletion source/AssetManager.cpp
Expand Up @@ -20,7 +20,7 @@

using namespace std;

namespace ku {
namespace dsu {
void AssetManager::dealloc() {
if (AssetManager::large_button_font != NULL)
TTF_CloseFont(AssetManager::large_button_font);
Expand Down
2 changes: 1 addition & 1 deletion source/AssetManager.hpp
Expand Up @@ -23,7 +23,7 @@
#include <string>
#include <switch.h>

namespace ku {
namespace dsu {
class AssetManager {
public:
/* Textures */
Expand Down
21 changes: 9 additions & 12 deletions source/ConfigManager.cpp
Expand Up @@ -19,7 +19,7 @@

using namespace std;

namespace ku {
namespace dsu {
void ConfigManager::initialize() {
config_init(&_cfg);
config_init(&_internalDb);
Expand All @@ -36,8 +36,8 @@ namespace ku {
setting = config_setting_add(root, RECEIVED_EXFAT_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, RECEIVED_EXFAT_WARNING_DEF);

setting = config_setting_add(root, RECEIVED_IGNORE_CONFIG_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, RECEIVED_IGNORE_CONFIG_WARNING_DEF);
// setting = config_setting_add(root, RECEIVED_IGNORE_CONFIG_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
// config_setting_set_bool(setting, RECEIVED_IGNORE_CONFIG_WARNING_DEF);

setting = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, IGNORE_CONFIG_FILES_DEF);
Expand Down Expand Up @@ -116,12 +116,10 @@ namespace ku {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _cfg);
}


bool ConfigManager::setFilesToIgnore(vector<string> files) {
return _appendArrayOfStrings(IGNORE_KEY, files, _cfg, CONFIG_FILENAME);
}


string ConfigManager::getCurrentVersion() {
return _readString(VERSION_KEY, VERSION_DEF, _internalDb);
}
Expand All @@ -135,9 +133,9 @@ namespace ku {
return _readBoolean(RECEIVED_EXFAT_WARNING_KEY, RECEIVED_EXFAT_WARNING_DEF, _internalDb);
}

bool ConfigManager::getReceivedIgnoreConfigWarning() {
return _readBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, RECEIVED_IGNORE_CONFIG_WARNING_DEF, _internalDb);
}
// bool ConfigManager::getReceivedIgnoreConfigWarning() {
// return _readBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, RECEIVED_IGNORE_CONFIG_WARNING_DEF, _internalDb);
// }

bool ConfigManager::getIgnoreConfigFiles() {
return _readBoolean(IGNORE_CONFIG_FILES_KEY, IGNORE_CONFIG_FILES_DEF, _internalDb);
Expand All @@ -147,7 +145,6 @@ namespace ku {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _internalDb);
}


bool ConfigManager::setCurrentVersion(string version) {
return _writeString(VERSION_KEY, version, _internalDb, INTERNAL_FILENAME);
}
Expand All @@ -160,9 +157,9 @@ namespace ku {
return _writeBoolean(RECEIVED_EXFAT_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
}

bool ConfigManager::setReceivedIgnoreConfigWarning(bool received) {
return _writeBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
}
// bool ConfigManager::setReceivedIgnoreConfigWarning(bool received) {
// return _writeBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
// }

bool ConfigManager::setIgnoreConfigFiles(bool ignore) {
return _writeBoolean(IGNORE_CONFIG_FILES_KEY, ignore, _internalDb, INTERNAL_FILENAME);
Expand Down
10 changes: 5 additions & 5 deletions source/ConfigManager.hpp
Expand Up @@ -21,7 +21,7 @@
#include <string>
#include <vector>

namespace ku {
namespace dsu {
class ConfigManager {
public:
static void initialize();
Expand All @@ -40,14 +40,14 @@ namespace ku {
static std::string getCurrentVersion();
static std::vector<std::string> getInstalledFiles();
static bool getReceivedExFATWarning();
static bool getReceivedIgnoreConfigWarning();
// static bool getReceivedIgnoreConfigWarning();
static bool getIgnoreConfigFiles();
static int getInternalConfigVersion();

static bool setCurrentVersion(std::string version);
static bool setInstalledFiles(std::vector<std::string> files);
static bool setReceivedExFATWarning(bool received);
static bool setReceivedIgnoreConfigWarning(bool received);
// static bool setReceivedIgnoreConfigWarning(bool received);
static bool setIgnoreConfigFiles(bool ignore);

private:
Expand Down Expand Up @@ -99,8 +99,8 @@ namespace ku {
static inline const std::string RECEIVED_EXFAT_WARNING_KEY = "received_exfat_warning";
static inline const bool RECEIVED_EXFAT_WARNING_DEF = false;

static inline const std::string RECEIVED_IGNORE_CONFIG_WARNING_KEY = "received_ignore_config_warning";
static inline const bool RECEIVED_IGNORE_CONFIG_WARNING_DEF = false;
// static inline const std::string RECEIVED_IGNORE_CONFIG_WARNING_KEY = "received_ignore_config_warning";
// static inline const bool RECEIVED_IGNORE_CONFIG_WARNING_DEF = false;

static inline const std::string IGNORE_CONFIG_FILES_KEY = "ignore_config_files";
static inline const bool IGNORE_CONFIG_FILES_DEF = false;
Expand Down
69 changes: 51 additions & 18 deletions source/FileManager.cpp
Expand Up @@ -23,31 +23,34 @@
#include <switch.h>
#include <sys/stat.h>
#include <unistd.h>
#include <filesystem>

#include "FileManager.hpp"

#include "ConfigManager.hpp"

using namespace simpleIniParser;
using namespace std;
namespace fs = std::filesystem;

namespace ku
namespace dsu
{
std::vector<char> FileManager::readFile(std::string path)
vector<char> FileManager::readFile(string path)
{
std::ifstream file;
file.open(path, std::ios::in | std::ios::binary | std::ios::ate);
ifstream file;
file.open(path, ios::in | ios::binary | ios::ate);

auto size = file.tellg();
file.seekg(0, std::ios::beg);
file.seekg(0, ios::beg);

std::vector<char> buffer(size);
vector<char> buffer(size);
file.read(buffer.data(), size);
file.close();

return buffer;
}

// Overwrites a file if it already exists!
bool FileManager::writeFile(string filename, string data)
{
deleteFile(filename);
Expand All @@ -67,9 +70,23 @@ namespace ku
return (result == data.size());
}

bool FileManager::appendFile(string filename, string data)
{
ofstream file;
// Make sure we are only adding, not overwriting.
file.open(filename, ios_base::app);

if(!file.is_open()) return false;

file << data;

file.close();
return true;
}

bool FileManager::deleteFile(string filename)
{
if (fileExists(filename))
if (fs::exists(filename))
{
return remove(filename.c_str()) == 0;
}
Expand All @@ -79,19 +96,34 @@ namespace ku

bool FileManager::fileExists(string filename)
{
FILE *file = fopen(filename.c_str(), "r");

if (file)
{
fflush(file);
fsync(fileno(file));
fclose(file);
return true;
}

if(fs::exists(filename)) return true;
return false;
}

// This scans all FILES in the given directory and it's respective subdirs.
vector<string> FileManager::scanDirectoryRecursive(string path)
{
vector<string> files;

// First check if the dir even exists.
if(fs::exists(path))
{
// Then make sure it's actually a directory, and not a file. All before
// iterating all of the files in the directory.
if(fs::is_directory(path))
{
for (auto ft : fs::recursive_directory_iterator(path))
{
if(ft.is_directory()) continue;
string path = ft.path().string();

files.push_back(path);
}
}
}
return files;
}

// http://stackoverflow.com/a/11366985
bool FileManager::createSubfolder(string path)
{
Expand Down Expand Up @@ -127,6 +159,7 @@ namespace ku
bool FileManager::extract(string zipFilename, string destination)
{
unzFile unz = unzOpen(zipFilename.c_str());

vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
vector<string> filesInstalled = ConfigManager::getInstalledFiles();

Expand Down Expand Up @@ -367,4 +400,4 @@ namespace ku
unzCloseCurrentFile(unz);
return 0;
}
} // namespace ku
} // namespace dsu
4 changes: 3 additions & 1 deletion source/FileManager.hpp
Expand Up @@ -21,13 +21,15 @@
#include <string>
#include <vector>

namespace ku {
namespace dsu {
class FileManager {
public:
static std::vector<char> readFile(std::string path);
static bool writeFile(std::string filename, std::string data);
static bool deleteFile(std::string filename);
static bool appendFile(std::string filename, std::string data);
static bool fileExists(std::string filename);
static std::vector<std::string> scanDirectoryRecursive(std::string path);
static bool createSubfolder(std::string path);
static bool extract(std::string filename, std::string destination);
static void cleanUpFiles();
Expand Down
2 changes: 1 addition & 1 deletion source/ModalView.cpp
Expand Up @@ -18,7 +18,7 @@
#include "ModalView.hpp"
#include "SceneDirector.hpp"

namespace ku {
namespace dsu {
void ModalView::show() {
SceneDirector::modal = this;
}
Expand Down
4 changes: 2 additions & 2 deletions source/ModalView.hpp
Expand Up @@ -24,8 +24,8 @@

#include "View.hpp"

namespace ku {
class ModalView : public ku::View {
namespace dsu {
class ModalView : public dsu::View {
public:
std::function<void(ModalView *, bool)> onDismiss;

Expand Down
2 changes: 1 addition & 1 deletion source/Scene.cpp
Expand Up @@ -17,7 +17,7 @@

#include "Scene.hpp"

namespace ku {
namespace dsu {
Scene::Scene() {
_touchedView = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Scene.hpp
Expand Up @@ -23,7 +23,7 @@

#include "View.hpp"

namespace ku {
namespace dsu {
class Scene {
public:
Scene();
Expand Down
6 changes: 3 additions & 3 deletions source/SceneDirector.cpp
Expand Up @@ -21,9 +21,9 @@
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"

using namespace ku::scenes;
using namespace dsu::scenes;

namespace ku
namespace dsu
{
SceneDirector::SceneDirector()
{
Expand Down Expand Up @@ -222,4 +222,4 @@ namespace ku

SDL_RenderPresent(SceneDirector::renderer);
}
} // namespace ku
} // namespace dsu
2 changes: 1 addition & 1 deletion source/SceneDirector.hpp
Expand Up @@ -26,7 +26,7 @@
#include "scenes/PackageDownloadScene.hpp"
#include "scenes/PackageSelectScene.hpp"

namespace ku {
namespace dsu {
typedef enum {
SCENE_EXFAT_WARNING,
SCENE_APP_UPDATE,
Expand Down
2 changes: 1 addition & 1 deletion source/View.cpp
Expand Up @@ -17,7 +17,7 @@

#include "View.hpp"

namespace ku {
namespace dsu {
View::View() {
frame = { 0, 0, 0, 0 };
hidden = false;
Expand Down
2 changes: 1 addition & 1 deletion source/View.hpp
Expand Up @@ -20,7 +20,7 @@
#include <list>
#include <SDL2/SDL.h>

namespace ku {
namespace dsu {
class View {
public:
SDL_Rect frame;
Expand Down
7 changes: 3 additions & 4 deletions source/main.cpp
Expand Up @@ -20,11 +20,12 @@
#include <switch.h>
#include <Swurl.hpp>

#include "FileManager.hpp"
#include "AssetManager.hpp"
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"

using namespace ku;
using namespace dsu;
using namespace std;
using namespace swurl;

Expand All @@ -33,9 +34,7 @@ int main(int argc, char **argv)
SessionManager::initialize();
SessionManager::userAgent = string("DeepSea-updater/") + VERSION;

#ifdef DEBUG
nxlinkStdio();
#endif
nxlinkStdio();

ConfigManager::initialize();

Expand Down
2 changes: 1 addition & 1 deletion source/models/Action.cpp
Expand Up @@ -19,7 +19,7 @@

using namespace std;

namespace ku::models {
namespace dsu::models {
Action::Action(ActionButton actionButton, string actionText) {
button = actionButton;
text = actionText;
Expand Down
2 changes: 1 addition & 1 deletion source/models/Action.hpp
Expand Up @@ -20,7 +20,7 @@
#include <SDL2/SDL.h>
#include <string>

namespace ku::models {
namespace dsu::models {
typedef enum {
A_BUTTON,
B_BUTTON,
Expand Down

0 comments on commit 57ac5c0

Please sign in to comment.