mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-09-13 21:15:38 -05:00
TitleOptionState: Add system save protections.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "appstates/MainMenuState.hpp"
|
||||
#include "colors.hpp"
|
||||
#include "config.hpp"
|
||||
#include "curl/curl.hpp"
|
||||
#include "data/data.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "input.hpp"
|
||||
@@ -22,10 +23,8 @@ namespace
|
||||
{
|
||||
/// @brief Build month.
|
||||
constexpr uint8_t BUILD_MON = 5;
|
||||
|
||||
/// @brief Build day.
|
||||
constexpr uint8_t BUILD_DAY = 31;
|
||||
|
||||
/// @brief Year.
|
||||
constexpr uint16_t BUILD_YEAR = 2025;
|
||||
} // namespace
|
||||
@@ -70,6 +69,7 @@ JKSV::JKSV(void)
|
||||
ABORT_ON_FAILURE(initialize_service(setInitialize, "Set"));
|
||||
ABORT_ON_FAILURE(initialize_service(setsysInitialize, "SetSys"));
|
||||
ABORT_ON_FAILURE(initialize_service(socketInitializeDefault, "Socket"));
|
||||
ABORT_ON_FAILURE(curl::initialize());
|
||||
|
||||
// Input doesn't have anything to return.
|
||||
input::initialize();
|
||||
@@ -127,6 +127,7 @@ JKSV::~JKSV()
|
||||
// Try to save config first.
|
||||
config::save();
|
||||
|
||||
curl::exit();
|
||||
socketExit();
|
||||
setsysExit();
|
||||
setExit();
|
||||
|
||||
@@ -144,6 +144,15 @@ void TitleOptionState::update(void)
|
||||
|
||||
case RESET_SAVE_DATA:
|
||||
{
|
||||
// Need to check this first. For safety.
|
||||
FsSaveDataInfo *saveInfo = m_targetUser->get_save_info_by_id(m_titleInfo->get_application_id());
|
||||
if (!config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM) || fs::is_system_save_data(saveInfo))
|
||||
{
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_POPS, 6));
|
||||
return;
|
||||
}
|
||||
|
||||
// String
|
||||
std::string confirmString = stringutil::get_formatted_string(
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_CONFIRMATIONS, 2),
|
||||
@@ -166,6 +175,14 @@ void TitleOptionState::update(void)
|
||||
|
||||
case DELETE_SAVE_FROM_SYSTEM:
|
||||
{
|
||||
FsSaveDataInfo *saveInfo = m_targetUser->get_save_info_by_id(m_titleInfo->get_application_id());
|
||||
if (!config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM) || fs::is_system_save_data(saveInfo))
|
||||
{
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_POPS, 6));
|
||||
return;
|
||||
}
|
||||
|
||||
// String
|
||||
std::string confirmString = stringutil::get_formatted_string(
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_CONFIRMATIONS, 3),
|
||||
@@ -190,6 +207,14 @@ void TitleOptionState::update(void)
|
||||
|
||||
case EXTEND_CONTAINER:
|
||||
{
|
||||
FsSaveDataInfo *saveInfo = m_targetUser->get_save_info_by_id(m_titleInfo->get_application_id());
|
||||
if (!config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM) || fs::is_system_save_data(saveInfo))
|
||||
{
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_POPS, 6));
|
||||
return;
|
||||
}
|
||||
|
||||
// Data
|
||||
std::shared_ptr<TargetStruct> data = std::make_shared<TargetStruct>();
|
||||
data->m_targetUser = m_targetUser;
|
||||
@@ -202,6 +227,12 @@ void TitleOptionState::update(void)
|
||||
|
||||
case EXPORT_SVI:
|
||||
{
|
||||
// This type of save data can't have this exported anyway.
|
||||
FsSaveDataInfo *saveInfo = m_targetUser->get_save_info_by_id(m_titleInfo->get_application_id());
|
||||
if (fs::is_system_save_data(saveInfo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
export_svi_file(m_titleInfo);
|
||||
}
|
||||
break;
|
||||
@@ -459,3 +490,10 @@ static void export_svi_file(data::TitleInfo *titleInfo)
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::TITLE_OPTION_POPS, 4));
|
||||
}
|
||||
|
||||
static bool is_system_save_data(const FsSaveDataInfo *saveInfo)
|
||||
{
|
||||
// The config setting will override this
|
||||
return config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM) ||
|
||||
saveInfo->save_data_type == FsSaveDataType_System || saveInfo->save_data_type == FsSaveDataType_SystemBcat;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "curl.hpp"
|
||||
#include "curl/curl.hpp"
|
||||
#include "stringutil.hpp"
|
||||
|
||||
namespace
|
||||
@@ -82,7 +82,7 @@ void curl::prepare_get(curl::Handle &curl)
|
||||
|
||||
// Setup basic request.
|
||||
curl::set_option(curl, CURLOPT_HTTPGET, 1L);
|
||||
curl::set_option(curl, CURLOPT_ACCEPT_ENCODING, "") // I think this is how you set the defaults for this?
|
||||
curl::set_option(curl, CURLOPT_ACCEPT_ENCODING, ""); // I think this is how you set the defaults for this?
|
||||
}
|
||||
|
||||
void curl::prepare_post(curl::Handle &curl)
|
||||
@@ -99,6 +99,5 @@ void curl::prepare_upload(curl::Handle &curl)
|
||||
|
||||
curl::set_option(curl, CURLOPT_UPLOAD, 1L);
|
||||
curl::set_option(curl, CURLOPT_UPLOAD_BUFFERSIZE, SIZE_UPLOAD_BUFFER);
|
||||
curl::set_option(curl, CURLOPT_ACCEPT_ENCODING, "") // Not really sure this will have any affect here...
|
||||
curl::set_option(curl, CURLOPT_ACCEPT_ENCODING, ""); // Not really sure this will have any affect here...
|
||||
}
|
||||
`
|
||||
|
||||
@@ -75,3 +75,8 @@ bool fs::extend_save_data(const FsSaveDataInfo *saveInfo, int64_t size, int64_t
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fs::is_system_save_data(const FsSaveDataInfo *saveInfo)
|
||||
{
|
||||
return saveInfo->save_data_type == FsSaveDataType_System || saveInfo->save_data_type == FsSaveDataType_SystemBcat;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user