mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-08-25 20:09:31 -05:00
Finish SaveImportState
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include "tasks/saveimport.hpp"
|
||||
|
||||
#include "appstates/MainMenuState.hpp"
|
||||
#include "appstates/SaveImportState.hpp"
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "tasks/backup.hpp"
|
||||
#include "stringutil.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
|
||||
// Defined at bottom.
|
||||
@@ -24,10 +25,42 @@ void tasks::saveimport::import_save_backup(sys::threadpool::JobData taskData)
|
||||
|
||||
fs::SaveMetaData metaData{};
|
||||
const bool metaRead = read_save_meta(target, metaData);
|
||||
if (!metaRead) { TASK_FINISH_RETURN(task); }
|
||||
if (!metaRead || metaData.revision < 1) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const bool saveExists = test_for_save(user, metaData);
|
||||
if (!saveExists) { fs::create_save_data_for(user, metaData); }
|
||||
if (!saveExists)
|
||||
{
|
||||
// Gonna borrow this.
|
||||
const char *statusFormat = strings::get_by_name(strings::names::USEROPTION_STATUS, 0);
|
||||
const std::string hexID = stringutil::get_formatted_string("%016llX", metaData.applicationID);
|
||||
std::string status = stringutil::get_formatted_string(statusFormat, hexID.c_str());
|
||||
task->set_status(status);
|
||||
|
||||
fs::create_save_data_for(user, metaData);
|
||||
user->clear_data_entries();
|
||||
user->load_user_data();
|
||||
MainMenuState::refresh_view_states();
|
||||
}
|
||||
|
||||
const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(metaData.applicationID);
|
||||
if (error::is_null(saveInfo)) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
{
|
||||
fs::ScopedSaveMount saveMount{fs::DEFAULT_SAVE_MOUNT, saveInfo};
|
||||
if (!saveMount.is_open()) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const bool isDir = fslib::directory_exists(target);
|
||||
if (isDir) { fs::copy_directory_commit(target, fs::DEFAULT_SAVE_ROOT, metaData.journalSize, task); }
|
||||
else
|
||||
{
|
||||
fs::MiniUnzip unzip{target};
|
||||
if (!unzip.is_open()) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
fs::copy_zip_to_directory(unzip, fs::DEFAULT_SAVE_ROOT, metaData.journalSize, task);
|
||||
}
|
||||
}
|
||||
|
||||
task->complete();
|
||||
}
|
||||
|
||||
static bool read_save_meta(const fslib::Path &path, fs::SaveMetaData &metaOut)
|
||||
|
||||
Reference in New Issue
Block a user