mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-24 23:37:24 -05:00
Commit before major surgery.
This commit is contained in:
parent
25f61b8a54
commit
14d9b7ffe1
2
Makefile
2
Makefile
|
|
@ -32,7 +32,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
|||
#---------------------------------------------------------------------------------
|
||||
TARGET := JKSV
|
||||
BUILD := build
|
||||
SOURCES := source source/appstates source/ui source/data source/system source/fs source/curl source/remote source/tasks
|
||||
SOURCES := source source/appstates source/ui source/data source/sys source/fs source/curl source/remote source/tasks
|
||||
DATA := data
|
||||
INCLUDES := include ./Libraries/FsLib/Switch/FsLib/include ./Libraries/SDLLib/SDL/include
|
||||
EXEFS_SRC := exefs_src
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "sys/sys.hpp"
|
||||
#include "ui/ui.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <switch.h>
|
||||
|
|
|
|||
36
include/appstates/TaskCallbackState.hpp
Normal file
36
include/appstates/TaskCallbackState.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
#include "appstates/BaseTask.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
/// @brief This is basically a task state that allows a callback and custom render function to be set.
|
||||
class TaskCallbackState final : public BaseTask
|
||||
{
|
||||
public:
|
||||
/// @brief
|
||||
using CallbackFunction = std::function<void(sys::Task *)>;
|
||||
|
||||
template <typename... Args>
|
||||
TaskCallbackState(void (*taskFunction)(sys::Task *, Args...),
|
||||
CallbackFunction callbackFunction,
|
||||
CallbackFunction renderFunction,
|
||||
Args... args)
|
||||
: m_callbackFunction(callbackFunction)
|
||||
, m_renderFunction(renderFunction)
|
||||
{
|
||||
m_task = std::make_unique<sys::Task>(taskFunction, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// @brief Update override. Calls m_callbackFunction.
|
||||
void update() override;
|
||||
|
||||
/// @brief Render override. Calls m_renderFunction.
|
||||
void render() override;
|
||||
|
||||
private:
|
||||
/// @brief Callback that is called on update.
|
||||
CallbackFunction m_callbackFunction{};
|
||||
|
||||
/// @brief Callback that is called on render.
|
||||
CallbackFunction m_renderFunction{};
|
||||
};
|
||||
33
include/sys/CallbackTask.hpp
Normal file
33
include/sys/CallbackTask.hpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
#include "sys/Task.hpp"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace sys
|
||||
{
|
||||
class CallbackTask final : public sys::Task
|
||||
{
|
||||
public:
|
||||
template <typename... Args>
|
||||
CallbackTask(void (*function)(sys::CallbackTask *, Args...), Args... args)
|
||||
{
|
||||
m_thread = std::thread(function, this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// @brief Signals that the main task is finished.
|
||||
void task_complete();
|
||||
|
||||
/// @brief
|
||||
void callback_complete();
|
||||
|
||||
/// @brief Returns whether both the main task and callback have finished.
|
||||
bool is_running() const;
|
||||
|
||||
private:
|
||||
/// @brief Bool to signal whether or not the task thread is completed.
|
||||
std::atomic<bool> m_taskFinished{};
|
||||
|
||||
/// @brief This signals whether or not the callback is finished.s
|
||||
bool m_callbackFinished{};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "sys/Task.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace sys
|
||||
|
|
@ -12,10 +13,14 @@ namespace sys
|
|||
/// @brief Contstructs a new ProgressTask
|
||||
/// @param function Function for thread to execute.
|
||||
/// @param args Arguments to forward to the thread function.
|
||||
/// @note All functions passed to this must follow this signature: void function(sys::ProgressTask *, <arguments>)
|
||||
/// @note All functions passed to this must follow this signature: void function(sys::ProgressTask *,
|
||||
//<arguments>)
|
||||
template <typename... Args>
|
||||
ProgressTask(void (*function)(sys::ProgressTask *, Args...), Args... args)
|
||||
: sys::Task(function, this, std::forward<Args>(args)...){};
|
||||
{
|
||||
m_thread = std::thread(function, this, std::forward<Args>(args)...);
|
||||
m_isRunning.store(true);
|
||||
}
|
||||
|
||||
/// @brief Resets the progress and sets a new goal.
|
||||
/// @param goal The goal we all strive for.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// This macro helps keep things a bit easier to read and cuts down on repetition.
|
||||
#define TASK_FINISH_RETURN(x) \
|
||||
x->finished(); \
|
||||
x->complete(); \
|
||||
return
|
||||
|
||||
namespace sys
|
||||
|
|
@ -16,11 +16,9 @@ namespace sys
|
|||
class Task
|
||||
{
|
||||
public:
|
||||
/// @brief Constructs a new task.
|
||||
/// @param function Function for task to run.
|
||||
/// @param args Arguments forwarded to thread.
|
||||
/// @note Functions passed to this class must follow the following signature: void function(sys::Task *,
|
||||
/// <arguments>)
|
||||
/// @brief Default constructor.
|
||||
Task() = default;
|
||||
|
||||
template <typename... Args>
|
||||
Task(void (*function)(sys::Task *, Args...), Args... args)
|
||||
{
|
||||
|
|
@ -28,18 +26,6 @@ namespace sys
|
|||
m_isRunning.store(true);
|
||||
}
|
||||
|
||||
/// @brief Alternate version of the above that allows derived classes to pass themselves to the thread instead.
|
||||
/// @tparam TaskType Type of task passed to the spawned thread. Ex: ProgressTask instead of Task.
|
||||
/// @param function Function for task to run.
|
||||
/// @param task Task passed to function. You don't really need to worry about this.
|
||||
/// @param args Arguments to forward to the function.
|
||||
template <typename TaskType, typename... Args>
|
||||
Task(void (*function)(TaskType *, Args...), TaskType *task, Args... args)
|
||||
{
|
||||
m_thread = std::thread(function, task, std::forward<Args>(args)...);
|
||||
m_isRunning.store(true);
|
||||
}
|
||||
|
||||
/// @brief Required destructor.
|
||||
virtual ~Task();
|
||||
|
||||
|
|
@ -49,7 +35,7 @@ namespace sys
|
|||
|
||||
/// @brief Allows thread to signal it's finished.
|
||||
/// @note Spawned task threads must call this when their work is finished.
|
||||
void finished();
|
||||
void complete();
|
||||
|
||||
/// @brief Sets the task/threads current status string. Thread safe.
|
||||
void set_status(std::string_view status);
|
||||
|
|
@ -58,17 +44,18 @@ namespace sys
|
|||
/// @return Copy of the status string.
|
||||
std::string get_status();
|
||||
|
||||
private:
|
||||
protected:
|
||||
// Whether task is still running.
|
||||
std::atomic<bool> m_isRunning;
|
||||
|
||||
// Status string the thread can set that the main thread can display.
|
||||
std::string m_status;
|
||||
|
||||
// Mutex so that string doesn't get messed up.
|
||||
std::mutex m_statusLock;
|
||||
std::atomic<bool> m_isRunning{};
|
||||
|
||||
// Thread
|
||||
std::thread m_thread;
|
||||
std::thread m_thread{};
|
||||
|
||||
private:
|
||||
// Status string the thread can set that the main thread can display.
|
||||
std::string m_status{};
|
||||
|
||||
// Mutex so that string doesn't get messed up.
|
||||
std::mutex m_statusLock{};
|
||||
};
|
||||
} // namespace sys
|
||||
|
|
|
|||
5
source/appstates/TaskCallbackState.cpp
Normal file
5
source/appstates/TaskCallbackState.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "appstates/TaskCallbackState.hpp"
|
||||
|
||||
void TaskCallbackState::update() { m_callbackFunction(m_task.get()); }
|
||||
|
||||
void TaskCallbackState::render() { m_renderFunction(m_task.get()); }
|
||||
|
|
@ -15,9 +15,18 @@
|
|||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <zstd.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
// clang-format off
|
||||
struct CacheEntry
|
||||
{
|
||||
uint64_t applicationID{};
|
||||
NsApplicationControlData controlData{};
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
/// @brief This contains the user accounts on the system.
|
||||
std::vector<data::User> s_users{};
|
||||
|
||||
|
|
@ -34,7 +43,9 @@ namespace
|
|||
constexpr AccountUid ID_CACHE_USER = {FsSaveDataType_Cache};
|
||||
|
||||
/// @brief This is for loading the cache.
|
||||
constexpr size_t SIZE_CTRL_DATA = sizeof(NsApplicationControlData);
|
||||
constexpr size_t SIZE_CTRL_DATA = sizeof(NsApplicationControlData);
|
||||
constexpr size_t SIZE_CACHE_ENTRY = sizeof(CacheEntry);
|
||||
constexpr size_t SIZE_SAVE_INFO = sizeof(FsSaveDataInfo);
|
||||
} // namespace
|
||||
|
||||
// Declarations here. Definitions at bottom. These should appear in the order called.
|
||||
|
|
@ -185,10 +196,13 @@ static bool read_cache_file()
|
|||
const bool read = cacheZip.read(&controlBuffer, SIZE_CTRL_DATA) == SIZE_CTRL_DATA;
|
||||
if (!read) { continue; }
|
||||
|
||||
const char *filename = cacheZip.get_filename();
|
||||
const uint64_t applicationID = std::strtoull(filename, nullptr, 16);
|
||||
data::TitleInfo newInfo{applicationID, controlBuffer};
|
||||
std::string filename{cacheZip.get_filename()};
|
||||
const size_t nameBegin = filename.find_first_not_of('/');
|
||||
if (nameBegin == filename.npos) { continue; } // This is required in order to get the application ID.
|
||||
|
||||
filename = filename.substr(nameBegin);
|
||||
const uint64_t applicationID = std::strtoull(filename.data(), nullptr, 16);
|
||||
data::TitleInfo newInfo{applicationID, controlBuffer};
|
||||
s_titleinfo.emplace(applicationID, std::move(newInfo));
|
||||
} while (cacheZip.next_file());
|
||||
|
||||
|
|
@ -205,7 +219,7 @@ static void create_cache_file()
|
|||
if (!titleInfo.has_control_data()) { continue; }
|
||||
|
||||
const NsApplicationControlData *controlData = titleInfo.get_control_data();
|
||||
const std::string cacheName = stringutil::get_formatted_string("%016llX", applicationID);
|
||||
const std::string cacheName = stringutil::get_formatted_string("//%016llX", applicationID);
|
||||
const bool opened = cacheZip.open_new_file(cacheName);
|
||||
if (!opened) { continue; }
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
// Definition at bottom.
|
||||
static zip_fileinfo create_zip_file_info();
|
||||
|
||||
fs::MiniZip::MiniZip(const fslib::Path &path) { MiniZip::open(path); }
|
||||
|
||||
fs::MiniZip::~MiniZip() { MiniZip::close(); }
|
||||
|
|
@ -34,6 +37,17 @@ bool fs::MiniZip::open_new_file(std::string_view filename, bool trimPath, size_t
|
|||
const size_t pathBegin = filename.find_first_of('/');
|
||||
if (pathBegin != filename.npos) { filename = filename.substr(pathBegin + 1); }
|
||||
|
||||
const zip_fileinfo fileInfo = create_zip_file_info();
|
||||
return zipOpenNewFileInZip64(m_zip, filename.data(), &fileInfo, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, zipLevel, 0) ==
|
||||
ZIP_OK;
|
||||
}
|
||||
|
||||
bool fs::MiniZip::close_current_file() { return zipCloseFileInZip(m_zip) == ZIP_OK; }
|
||||
|
||||
bool fs::MiniZip::write(const void *buffer, size_t dataSize) { return zipWriteInFileInZip(m_zip, buffer, dataSize) == ZIP_OK; }
|
||||
|
||||
static zip_fileinfo create_zip_file_info()
|
||||
{
|
||||
const std::time_t currentTime = std::time(nullptr);
|
||||
const std::tm *local = std::localtime(¤tTime);
|
||||
const zip_fileinfo fileInfo = {.tmz_date = {.tm_sec = local->tm_sec,
|
||||
|
|
@ -46,10 +60,5 @@ bool fs::MiniZip::open_new_file(std::string_view filename, bool trimPath, size_t
|
|||
.internal_fa = 0,
|
||||
.external_fa = 0};
|
||||
|
||||
return zipOpenNewFileInZip64(m_zip, filename.data(), &fileInfo, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, zipLevel, 0) ==
|
||||
ZIP_OK;
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
bool fs::MiniZip::close_current_file() { return zipCloseFileInZip(m_zip) == ZIP_OK; }
|
||||
|
||||
bool fs::MiniZip::write(const void *buffer, size_t dataSize) { return zipWriteInFileInZip(m_zip, buffer, dataSize) == ZIP_OK; }
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ static void drive_sign_in(sys::Task *task, remote::GoogleDrive *drive)
|
|||
ui::PopMessageManager::push_message(popTicks, popDriveFailed);
|
||||
}
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
static void drive_set_jksv_root(remote::GoogleDrive *drive)
|
||||
|
|
|
|||
7
source/sys/CallbackTask.cpp
Normal file
7
source/sys/CallbackTask.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "sys/CallbackTask.hpp"
|
||||
|
||||
void sys::CallbackTask::task_complete() { m_taskFinished = true; }
|
||||
|
||||
void sys::CallbackTask::callback_complete() { m_callbackFinished = true; }
|
||||
|
||||
bool sys::CallbackTask::is_running() const { return m_taskFinished && m_callbackFinished; }
|
||||
|
|
@ -12,7 +12,7 @@ sys::Task::~Task() { m_thread.join(); }
|
|||
|
||||
bool sys::Task::is_running() const { return m_isRunning.load(); }
|
||||
|
||||
void sys::Task::finished() { m_isRunning.store(false); }
|
||||
void sys::Task::complete() { m_isRunning.store(false); }
|
||||
|
||||
void sys::Task::set_status(std::string_view status)
|
||||
{
|
||||
|
|
@ -13,12 +13,13 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
constexpr const char *STRING_ZIP_EXT = ".zip";
|
||||
constexpr const char *STRING_JKSV_TEMP = "sdmc:/jksvTemp.zip"; // This is name this so if something fails, people know.
|
||||
constexpr size_t SIZE_SAVE_META = sizeof(fs::SaveMetaData);
|
||||
constexpr const char *STRING_ZIP_EXT = ".zip";
|
||||
constexpr const char *PATH_JKSV_TEMP = "sdmc:/jksvTemp.zip"; // This is named this so if something fails, people know.
|
||||
constexpr size_t SIZE_SAVE_META = sizeof(fs::SaveMetaData);
|
||||
}
|
||||
|
||||
// Definitions at bottom.
|
||||
static void auto_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskData);
|
||||
static bool read_and_process_meta(const fslib::Path &targetDir, BackupMenuState::TaskData taskData, sys::ProgressTask *task);
|
||||
static bool read_and_process_meta(fs::MiniUnzip &unzip, BackupMenuState::TaskData taskData, sys::ProgressTask *task);
|
||||
static void write_meta_file(const fslib::Path &target, const FsSaveDataInfo *saveInfo);
|
||||
|
|
@ -62,7 +63,7 @@ void tasks::backup::create_new_backup_local(sys::ProgressTask *task,
|
|||
|
||||
// This is like this so I can reuse this code.
|
||||
if (spawningState) { spawningState->refresh(); }
|
||||
if (killTask) { task->finished(); }
|
||||
if (killTask) { task->complete(); }
|
||||
}
|
||||
|
||||
void tasks::backup::create_new_backup_remote(sys::ProgressTask *task,
|
||||
|
|
@ -81,7 +82,7 @@ void tasks::backup::create_new_backup_remote(sys::ProgressTask *task,
|
|||
const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(applicationID);
|
||||
if (error::is_null(saveInfo)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const fslib::Path tempPath{STRING_JKSV_TEMP};
|
||||
const fslib::Path tempPath{PATH_JKSV_TEMP};
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
|
||||
fs::MiniZip zip{tempPath};
|
||||
|
|
@ -113,7 +114,7 @@ void tasks::backup::create_new_backup_remote(sys::ProgressTask *task,
|
|||
}
|
||||
|
||||
if (spawningState) { spawningState->refresh(); }
|
||||
if (killTask) { task->finished(); }
|
||||
if (killTask) { task->complete(); }
|
||||
}
|
||||
|
||||
void tasks::backup::overwrite_backup_local(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -153,7 +154,7 @@ void tasks::backup::overwrite_backup_remote(sys::ProgressTask *task, BackupMenuS
|
|||
const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(applicationID);
|
||||
if (error::is_null(saveInfo)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const fslib::Path tempPath{STRING_JKSV_TEMP};
|
||||
const fslib::Path tempPath{PATH_JKSV_TEMP};
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
|
||||
fs::MiniZip zip{tempPath};
|
||||
|
|
@ -181,7 +182,7 @@ void tasks::backup::overwrite_backup_remote(sys::ProgressTask *task, BackupMenuS
|
|||
ui::PopMessageManager::push_message(popTicks, popErrorDeleting);
|
||||
}
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::restore_backup_local(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -192,7 +193,6 @@ void tasks::backup::restore_backup_local(sys::ProgressTask *task, BackupMenuStat
|
|||
data::TitleInfo *titleInfo = taskData->titleInfo;
|
||||
const fslib::Path &target = taskData->path;
|
||||
BackupMenuState *spawningState = taskData->spawningState;
|
||||
remote::Storage *remote = remote::get_remote_storage();
|
||||
if (error::is_null(user) || error::is_null(titleInfo) || error::is_null(spawningState)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const uint64_t applicationID = titleInfo->get_application_id();
|
||||
|
|
@ -208,45 +208,7 @@ void tasks::backup::restore_backup_local(sys::ProgressTask *task, BackupMenuStat
|
|||
const bool hasZipExt = std::strstr(target.full_path(), STRING_ZIP_EXT);
|
||||
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
if (autoBackup)
|
||||
{
|
||||
const size_t lastSlash = target.find_last_of('/');
|
||||
if (lastSlash == target.NOT_FOUND)
|
||||
{
|
||||
const char *popErrorCreating = strings::get_by_name(strings::names::BACKUPMENU_POPS, 5);
|
||||
ui::PopMessageManager::push_message(popTicks, popErrorCreating);
|
||||
TASK_FINISH_RETURN(task);
|
||||
}
|
||||
|
||||
const char *safeNickname = user->get_path_safe_nickname();
|
||||
const std::string dateString = stringutil::get_date_string();
|
||||
const std::string autoName = stringutil::get_formatted_string("AUTO - %s - %s", safeNickname, dateString.c_str());
|
||||
fslib::Path autoTarget = target.sub_path(lastSlash) / autoName;
|
||||
if (exportZip) { autoTarget += ".zip"; };
|
||||
tasks::backup::create_new_backup_local(task, user, titleInfo, autoTarget, spawningState, false);
|
||||
|
||||
// Not sure if this is really needed here, but I'm sure someone will point it out.
|
||||
if (autoUpload && remote)
|
||||
{
|
||||
const char *statusUploading = strings::get_by_name(strings::names::IO_STATUSES, 5);
|
||||
const std::string status = stringutil::get_formatted_string(statusUploading, autoTarget.get_filename());
|
||||
task->set_status(status);
|
||||
remote->upload_file(autoTarget, autoTarget.get_filename(), task);
|
||||
fslib::delete_file(autoTarget); // I don't care if this fails,
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto scopedMount = create_scoped_mount(saveInfo);
|
||||
const bool resetError = error::fslib(fslib::delete_directory_recursively(fs::DEFAULT_SAVE_ROOT));
|
||||
const bool commitError = error::fslib(fslib::commit_data_to_file_system(fs::DEFAULT_SAVE_MOUNT));
|
||||
if (resetError || commitError)
|
||||
{
|
||||
const char *popErrorResetting = strings::get_by_name(strings::names::BACKUPMENU_POPS, 2);
|
||||
ui::PopMessageManager::push_message(popTicks, popErrorResetting);
|
||||
TASK_FINISH_RETURN(task);
|
||||
}
|
||||
}
|
||||
if (autoBackup) { auto_backup(task, taskData); }
|
||||
|
||||
if (!isDir && hasZipExt)
|
||||
{
|
||||
|
|
@ -275,7 +237,7 @@ void tasks::backup::restore_backup_local(sys::ProgressTask *task, BackupMenuStat
|
|||
}
|
||||
|
||||
spawningState->refresh();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::restore_backup_remote(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -287,13 +249,16 @@ void tasks::backup::restore_backup_remote(sys::ProgressTask *task, BackupMenuSta
|
|||
remote::Storage *remote = remote::get_remote_storage();
|
||||
if (error::is_null(user) || error::is_null(titleInfo) || error::is_null(remote)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const bool autoBackup = config::get_by_key(config::keys::AUTO_BACKUP_ON_RESTORE);
|
||||
const uint64_t applicationID = titleInfo->get_application_id();
|
||||
const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(applicationID);
|
||||
if (error::is_null(saveInfo)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
if (autoBackup) { auto_backup(task, taskData); }
|
||||
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
remote::Item *target = taskData->remoteItem;
|
||||
const fslib::Path tempPath{STRING_JKSV_TEMP};
|
||||
const fslib::Path tempPath{PATH_JKSV_TEMP};
|
||||
{
|
||||
const char *name = target->get_name().data();
|
||||
const char *downloadingFormat = strings::get_by_name(strings::names::IO_STATUSES, 4);
|
||||
|
|
@ -345,7 +310,7 @@ void tasks::backup::restore_backup_remote(sys::ProgressTask *task, BackupMenuSta
|
|||
ui::PopMessageManager::push_message(popTicks, popErrorDeleting);
|
||||
}
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::delete_backup_local(sys::Task *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -373,7 +338,7 @@ void tasks::backup::delete_backup_local(sys::Task *task, BackupMenuState::TaskDa
|
|||
}
|
||||
|
||||
spawningState->refresh();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::delete_backup_remote(sys::Task *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -401,7 +366,7 @@ void tasks::backup::delete_backup_remote(sys::Task *task, BackupMenuState::TaskD
|
|||
}
|
||||
|
||||
spawningState->refresh();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::upload_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -423,7 +388,7 @@ void tasks::backup::upload_backup(sys::ProgressTask *task, BackupMenuState::Task
|
|||
// The backup menu should've made sure the remote is pointing to the correct location.
|
||||
remote->upload_file(path, path.get_filename(), task);
|
||||
spawningState->refresh();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::backup::patch_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
|
|
@ -444,7 +409,52 @@ void tasks::backup::patch_backup(sys::ProgressTask *task, BackupMenuState::TaskD
|
|||
}
|
||||
|
||||
remote->patch_file(remoteItem, path, task);
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
static void auto_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskData)
|
||||
{
|
||||
if (error::is_null(task)) { return; }
|
||||
|
||||
remote::Storage *remote = remote::get_remote_storage();
|
||||
data::User *user = taskData->user;
|
||||
data::TitleInfo *titleInfo = taskData->titleInfo;
|
||||
fslib::Path &target = taskData->path;
|
||||
BackupMenuState *spawningState = taskData->spawningState;
|
||||
|
||||
const uint64_t applicationID = titleInfo->get_application_id();
|
||||
const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(applicationID);
|
||||
if (error::is_null(saveInfo)) { return; }
|
||||
|
||||
{
|
||||
fs::ScopedSaveMount testMount{fs::DEFAULT_SAVE_MOUNT, saveInfo, false};
|
||||
const bool hasData = fs::directory_has_contents(fs::DEFAULT_SAVE_ROOT);
|
||||
if (!testMount.is_open() || !hasData) { return; }
|
||||
}
|
||||
|
||||
const bool autoUpload = config::get_by_key(config::keys::AUTO_UPLOAD);
|
||||
const bool exportZip = config::get_by_key(config::keys::EXPORT_TO_ZIP);
|
||||
const bool zip = autoUpload || exportZip;
|
||||
|
||||
const char *safeNickname = user->get_path_safe_nickname();
|
||||
const std::string dateString = stringutil::get_date_string();
|
||||
std::string backupName = stringutil::get_formatted_string("AUTO - %s - %s", safeNickname, dateString.c_str());
|
||||
if (zip) { backupName += STRING_ZIP_EXT; }
|
||||
|
||||
if (autoUpload && remote)
|
||||
{
|
||||
tasks::backup::create_new_backup_remote(task, user, titleInfo, backupName, spawningState, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're going to get the target dir from the path passed.
|
||||
const size_t lastSlash = target.find_last_of('/');
|
||||
if (lastSlash == target.NOT_FOUND) { return; }
|
||||
|
||||
fslib::Path autoTarget{target.sub_path(lastSlash) / backupName};
|
||||
logger::log("%s", autoTarget.full_path());
|
||||
tasks::backup::create_new_backup_local(task, user, titleInfo, autoTarget, spawningState, false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool read_and_process_meta(const fslib::Path &targetDir, BackupMenuState::TaskData taskData, sys::ProgressTask *task)
|
||||
|
|
@ -455,7 +465,7 @@ static bool read_and_process_meta(const fslib::Path &targetDir, BackupMenuState:
|
|||
data::TitleInfo *titleInfo = taskData->titleInfo;
|
||||
if (error::is_null(user) || error::is_null(titleInfo))
|
||||
{
|
||||
task->finished();
|
||||
task->complete();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -499,7 +509,7 @@ static bool read_and_process_meta(fs::MiniUnzip &unzip, BackupMenuState::TaskDat
|
|||
data::TitleInfo *titleInfo = taskData->titleInfo;
|
||||
if (error::is_null(user) || error::is_null(titleInfo))
|
||||
{
|
||||
task->finished();
|
||||
task->complete();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void tasks::mainmenu::backup_all_for_all_local(sys::ProgressTask *task, MainMenu
|
|||
tasks::backup::create_new_backup_local(task, user, titleInfo, finalTarget, nullptr, false);
|
||||
}
|
||||
}
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::mainmenu::backup_all_for_all_remote(sys::ProgressTask *task, MainMenuState::TaskData taskData)
|
||||
|
|
@ -101,5 +101,5 @@ void tasks::mainmenu::backup_all_for_all_remote(sys::ProgressTask *task, MainMen
|
|||
remote->return_to_root();
|
||||
}
|
||||
}
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,5 +33,5 @@ void tasks::savecreate::create_save_data_for(sys::Task *task,
|
|||
}
|
||||
|
||||
spawningState->refresh_required();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ void tasks::titleoptions::blacklist_title(sys::Task *task, TitleOptionState::Tas
|
|||
TitleOptionState *spawningState = taskData->spawningState;
|
||||
if (error::is_null(titleInfo) || error::is_null(spawningState))
|
||||
{
|
||||
task->finished();
|
||||
task->complete();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ void tasks::titleoptions::blacklist_title(sys::Task *task, TitleOptionState::Tas
|
|||
spawningState->refresh_required();
|
||||
spawningState->close_on_update();
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::titleoptions::delete_all_local_backups_for_title(sys::Task *task, TitleOptionState::TaskData taskData)
|
||||
|
|
@ -71,7 +71,7 @@ void tasks::titleoptions::delete_all_local_backups_for_title(sys::Task *task, Ti
|
|||
ui::PopMessageManager::push_message(popTicks, popMessage);
|
||||
}
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::titleoptions::delete_all_remote_backups_for_title(sys::Task *task, TitleOptionState::TaskData taskData)
|
||||
|
|
@ -109,7 +109,7 @@ void tasks::titleoptions::delete_all_remote_backups_for_title(sys::Task *task, T
|
|||
|
||||
const std::string popMessage = stringutil::get_formatted_string(popSuccess, title);
|
||||
ui::PopMessageManager::push_message(popTicks, popMessage);
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::titleoptions::reset_save_data(sys::Task *task, TitleOptionState::TaskData taskData)
|
||||
|
|
@ -143,7 +143,7 @@ void tasks::titleoptions::reset_save_data(sys::Task *task, TitleOptionState::Tas
|
|||
else { ui::PopMessageManager::push_message(popTicks, popSuccess); }
|
||||
}
|
||||
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::titleoptions::delete_save_data_from_system(sys::Task *task, TitleOptionState::TaskData taskData)
|
||||
|
|
@ -188,7 +188,7 @@ void tasks::titleoptions::delete_save_data_from_system(sys::Task *task, TitleOpt
|
|||
user->erase_save_info_by_id(applicationID);
|
||||
titleSelect->refresh();
|
||||
spawningState->close_on_update();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::titleoptions::extend_save_data(sys::Task *task, TitleOptionState::TaskData taskData)
|
||||
|
|
@ -231,5 +231,5 @@ void tasks::titleoptions::extend_save_data(sys::Task *task, TitleOptionState::Ta
|
|||
const char *popFailed = strings::get_by_name(strings::names::TITLEOPTION_POPS, 11);
|
||||
ui::PopMessageManager::push_message(popTicks, popFailed);
|
||||
}
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ void tasks::useroptions::backup_all_for_user_local(sys::ProgressTask *task, User
|
|||
|
||||
tasks::backup::create_new_backup_local(task, user, titleInfo, finalTarget, nullptr, false);
|
||||
}
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::useroptions::backup_all_for_user_remote(sys::ProgressTask *task, UserOptionState::TaskData taskData)
|
||||
|
|
@ -91,7 +91,7 @@ void tasks::useroptions::backup_all_for_user_remote(sys::ProgressTask *task, Use
|
|||
|
||||
remote->return_to_root();
|
||||
}
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::useroptions::create_all_save_data_for_user(sys::Task *task, UserOptionState::TaskData taskData)
|
||||
|
|
@ -129,7 +129,7 @@ void tasks::useroptions::create_all_save_data_for_user(sys::Task *task, UserOpti
|
|||
}
|
||||
|
||||
spawningState->refresh_required();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
void tasks::useroptions::delete_all_save_data_for_user(sys::Task *task, UserOptionState::TaskData taskData)
|
||||
|
|
@ -171,5 +171,5 @@ void tasks::useroptions::delete_all_save_data_for_user(sys::Task *task, UserOpti
|
|||
|
||||
for (const uint64_t &applicationID : applicationIDs) { user->erase_save_info_by_id(applicationID); }
|
||||
spawningState->refresh_required();
|
||||
task->finished();
|
||||
task->complete();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user