mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-21 17:24:37 -05:00
Finish SaveImportState
This commit is contained in:
parent
9d542b4314
commit
cdc6937249
|
|
@ -17,13 +17,13 @@ namespace fs
|
|||
uint8_t saveDataType{};
|
||||
uint8_t saveDataRank{};
|
||||
uint16_t saveDataIndex{};
|
||||
uint8_t saveDataSpaceID{};
|
||||
uint64_t ownerID{};
|
||||
uint64_t timestamp{};
|
||||
uint32_t flags{};
|
||||
int64_t saveDataSize{};
|
||||
int64_t journalSize{};
|
||||
uint64_t commitID{};
|
||||
uint8_t saveDataSpaceID{};
|
||||
} __attribute__((packed));
|
||||
// clang-format on
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "fs/save_data_functions.hpp"
|
||||
#include "fs/save_mount.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -25,13 +26,13 @@ bool fs::fill_save_meta_data(const FsSaveDataInfo *saveInfo, fs::SaveMetaData &m
|
|||
.saveDataType = extraData.attr.save_data_type,
|
||||
.saveDataRank = extraData.attr.save_data_rank,
|
||||
.saveDataIndex = extraData.attr.save_data_index,
|
||||
.saveDataSpaceID = saveInfo->save_data_space_id,
|
||||
.ownerID = extraData.owner_id,
|
||||
.timestamp = extraData.timestamp,
|
||||
.flags = extraData.flags,
|
||||
.saveDataSize = extraData.data_size,
|
||||
.journalSize = extraData.journal_size,
|
||||
.commitID = extraData.commit_id};
|
||||
.commitID = extraData.commit_id,
|
||||
.saveDataSpaceID = saveInfo->save_data_space_id};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -42,6 +43,8 @@ bool fs::process_save_meta_data(const FsSaveDataInfo *saveInfo, const SaveMetaDa
|
|||
const bool extraRead = fs::read_save_extra_data(saveInfo, extraData);
|
||||
if (!extraRead) { return false; }
|
||||
|
||||
logger::log("size: %X, %X", extraData.data_size, meta.saveDataSize);
|
||||
|
||||
const bool needsExtend = extraData.data_size < meta.saveDataSize;
|
||||
const bool extended = needsExtend && fs::extend_save_data(saveInfo, meta.saveDataSize, meta.journalSize);
|
||||
if (needsExtend && !extended) { return false; }
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user