mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-11-28 19:40:18 +00:00
begin configuration work
This commit is contained in:
parent
800ad628a5
commit
583d1d92e7
9 changed files with 210 additions and 27 deletions
|
@ -36,8 +36,8 @@ APP_DESCRIPTION := Fast and simple save manager
|
|||
APP_AUTHOR := Bernardo Giordano
|
||||
|
||||
VERSION_MAJOR := 3
|
||||
VERSION_MINOR := 2
|
||||
VERSION_MICRO := 0
|
||||
VERSION_MINOR := 3
|
||||
VERSION_MICRO := 1
|
||||
|
||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||
OUTDIR := out
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
},
|
||||
"nand_saves": false,
|
||||
"version_major": 3,
|
||||
"version_minor": 2,
|
||||
"version_micro": 0
|
||||
"version_minor": 3,
|
||||
"version_micro": 1
|
||||
}
|
|
@ -32,7 +32,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
|||
#---------------------------------------------------------------------------------
|
||||
VERSION_MAJOR := 3
|
||||
VERSION_MINOR := 3
|
||||
VERSION_MICRO := 0
|
||||
VERSION_MICRO := 1
|
||||
|
||||
APP_TITLE := Checkpoint
|
||||
APP_AUTHOR := Bernardo Giordano
|
||||
|
@ -45,7 +45,7 @@ SOURCES := source ../common
|
|||
DATA := data
|
||||
INCLUDES := include ../common
|
||||
EXEFS_SRC := exefs_src
|
||||
#ROMFS := romfs
|
||||
ROMFS := romfs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
|
|
67
switch/include/configuration.hpp
Normal file
67
switch/include/configuration.hpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2018 Bernardo Giordano
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#ifndef CONFIGHANDLER_HPP
|
||||
#define CONFIGHANDLER_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include "json.hpp"
|
||||
#include "io.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
static Configuration& getInstance(void)
|
||||
{
|
||||
static Configuration mConfiguration;
|
||||
return mConfiguration;
|
||||
}
|
||||
|
||||
bool filter(u64 id);
|
||||
bool nandSaves(void);
|
||||
std::vector<std::string> additionalSaveFolders(u64 id);
|
||||
|
||||
private:
|
||||
Configuration(void);
|
||||
~Configuration(void) { };
|
||||
|
||||
void store(void);
|
||||
|
||||
Configuration(Configuration const&) = delete;
|
||||
void operator=(Configuration const&) = delete;
|
||||
|
||||
nlohmann::json mJson;
|
||||
std::unordered_set<u64> mFilterIds;
|
||||
std::unordered_map<u64, std::vector<std::string>> mAdditionalSaveFolders;
|
||||
bool mNandSaves;
|
||||
std::string BASEPATH = "/switch/Checkpoint/config.json";
|
||||
};
|
||||
|
||||
#endif
|
|
@ -34,6 +34,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "configuration.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
|
|
12
switch/romfs/config.json
Normal file
12
switch/romfs/config.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"filter": [
|
||||
|
||||
],
|
||||
"additional_save_folders": {
|
||||
|
||||
},
|
||||
"nand_saves": false,
|
||||
"version_major": 3,
|
||||
"version_minor": 3,
|
||||
"version_micro": 1
|
||||
}
|
98
switch/source/configuration.cpp
Normal file
98
switch/source/configuration.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2018 Bernardo Giordano
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "configuration.hpp"
|
||||
|
||||
Configuration::Configuration(void)
|
||||
{
|
||||
// check for existing config.json files on the sd card, BASEPATH
|
||||
if (!io::fileExists(BASEPATH))
|
||||
{
|
||||
store();
|
||||
}
|
||||
|
||||
// load json config file
|
||||
std::ifstream i(BASEPATH);
|
||||
i >> mJson;
|
||||
i.close();
|
||||
|
||||
int version_major = mJson["version_major"];
|
||||
int version_minor = mJson["version_minor"];
|
||||
int version_micro = mJson["version_micro"];
|
||||
if (version_major != VERSION_MAJOR || version_minor != VERSION_MINOR || version_micro != VERSION_MICRO)
|
||||
{
|
||||
store();
|
||||
}
|
||||
|
||||
// parse filters
|
||||
std::vector<std::string> filter = mJson["filter"];
|
||||
for (auto& id : filter)
|
||||
{
|
||||
mFilterIds.emplace(strtoull(id.c_str(), NULL, 16));
|
||||
}
|
||||
|
||||
// parse nand saves
|
||||
mNandSaves = mJson["nand_saves"];
|
||||
|
||||
// parse additional save folders
|
||||
auto js = mJson["additional_save_folders"];
|
||||
for (auto it = js.begin(); it != js.end(); ++it)
|
||||
{
|
||||
std::vector<std::string> folders = it.value()["folders"];
|
||||
std::vector<std::string> sfolders;
|
||||
for (auto& folder : folders)
|
||||
{
|
||||
sfolders.push_back(folder);
|
||||
}
|
||||
mAdditionalSaveFolders.emplace(strtoull(it.key().c_str(), NULL, 16), sfolders);
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::store(void)
|
||||
{
|
||||
std::ifstream src("romfs:/config.json");
|
||||
std::ofstream dst(BASEPATH);
|
||||
dst << src.rdbuf();
|
||||
src.close();
|
||||
dst.close();
|
||||
}
|
||||
|
||||
bool Configuration::filter(u64 id)
|
||||
{
|
||||
return mFilterIds.find(id) != mFilterIds.end();
|
||||
}
|
||||
|
||||
bool Configuration::nandSaves(void)
|
||||
{
|
||||
return mNandSaves;
|
||||
}
|
||||
|
||||
std::vector<std::string> Configuration::additionalSaveFolders(u64 id)
|
||||
{
|
||||
std::vector<std::string> emptyvec;
|
||||
auto folders = mAdditionalSaveFolders.find(id);
|
||||
return folders == mAdditionalSaveFolders.end() ? emptyvec : folders->second;
|
||||
}
|
|
@ -202,33 +202,37 @@ void loadTitles(void)
|
|||
{
|
||||
u64 tid = info.titleID;
|
||||
u128 uid = info.userID;
|
||||
res = nsGetApplicationControlData(1, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
|
||||
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp)))
|
||||
if (!Configuration::getInstance().filter(tid))
|
||||
{
|
||||
res = nacpGetLanguageEntry(&nsacd->nacp, &nle);
|
||||
if (R_SUCCEEDED(res) && nle != NULL)
|
||||
res = nsGetApplicationControlData(1, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
|
||||
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp)))
|
||||
{
|
||||
Title title;
|
||||
title.init(tid, uid, std::string(nle->name), std::string(nle->author));
|
||||
loadIcon(tid, nsacd, outsize - sizeof(nsacd->nacp));
|
||||
res = nacpGetLanguageEntry(&nsacd->nacp, &nle);
|
||||
if (R_SUCCEEDED(res) && nle != NULL)
|
||||
{
|
||||
Title title;
|
||||
title.init(tid, uid, std::string(nle->name), std::string(nle->author));
|
||||
loadIcon(tid, nsacd, outsize - sizeof(nsacd->nacp));
|
||||
|
||||
// check if the vector is already created
|
||||
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
|
||||
if (it != titles.end())
|
||||
{
|
||||
// found
|
||||
it->second.push_back(title);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not found, insert into map
|
||||
std::vector<Title> v;
|
||||
v.push_back(title);
|
||||
titles.emplace(uid, v);
|
||||
// check if the vector is already created
|
||||
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
|
||||
if (it != titles.end())
|
||||
{
|
||||
// found
|
||||
it->second.push_back(title);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not found, insert into map
|
||||
std::vector<Title> v;
|
||||
v.push_back(title);
|
||||
titles.emplace(uid, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
nle = NULL;
|
||||
}
|
||||
nle = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ void servicesExit(void)
|
|||
Result servicesInit(void)
|
||||
{
|
||||
Result res = 0;
|
||||
romfsInit();
|
||||
res = io::createDirectory("sdmc:/switch");
|
||||
res = io::createDirectory("sdmc:/switch/Checkpoint");
|
||||
res = io::createDirectory("sdmc:/switch/Checkpoint/saves");
|
||||
|
|
Loading…
Reference in a new issue