first working prototype
This commit is contained in:
+50
-10
@@ -45,7 +45,7 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
|
||||
}
|
||||
FILE* dst = fopen(dstPath.c_str(), "wb");
|
||||
if (dst == NULL) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to open destination file " + dstPath + " during copy with errno %d. Skipping...", errno);
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to open destination file " + dstPath + " during copy with errno " + std::to_string(errno) + ". Skipping...");
|
||||
fclose(src);
|
||||
return;
|
||||
}
|
||||
@@ -70,9 +70,7 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
|
||||
fclose(src);
|
||||
fclose(dst);
|
||||
|
||||
// commit each file to the save
|
||||
if (dstPath.rfind("save:/", 0) == 0) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Committing file " + dstPath + " to the save archive.");
|
||||
fsdevCommitDevice("save");
|
||||
}
|
||||
|
||||
@@ -217,32 +215,74 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, AccountUid uid,
|
||||
Logger::getInstance().log(Logger::INFO, "Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(),
|
||||
title.userId().uid[1], title.userId().uid[0]);
|
||||
|
||||
// Если сейв ещё не существует (игра не запускалась) — создаём его через NACP.
|
||||
// fsCreateSaveDataFileSystem возвращает ошибку если сейв уже есть — это нормально.
|
||||
{
|
||||
NsApplicationControlData* nsacd = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
|
||||
if (nsacd != NULL) {
|
||||
memset(nsacd, 0, sizeof(NsApplicationControlData));
|
||||
size_t outsize = 0;
|
||||
if (R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage, title.id(), nsacd, sizeof(NsApplicationControlData), &outsize))) {
|
||||
static const FsSaveDataMetaInfo meta = {.size = 0x40060, .type = FsSaveDataMetaType_Thumbnail};
|
||||
|
||||
FsSaveDataAttribute attr = {};
|
||||
attr.application_id = title.id();
|
||||
attr.uid = uid;
|
||||
attr.save_data_type = FsSaveDataType_Account;
|
||||
attr.save_data_rank = FsSaveDataRank_Primary;
|
||||
|
||||
FsSaveDataCreationInfo createInfo = {};
|
||||
createInfo.save_data_size = (s64)nsacd->nacp.user_account_save_data_size;
|
||||
createInfo.journal_size = (s64)nsacd->nacp.user_account_save_data_journal_size;
|
||||
createInfo.available_size = 0x4000;
|
||||
createInfo.owner_id = nsacd->nacp.save_data_owner_id;
|
||||
createInfo.save_data_space_id = FsSaveDataSpaceId_User;
|
||||
|
||||
fsCreateSaveDataFileSystem(&attr, &createInfo, &meta);
|
||||
}
|
||||
free(nsacd);
|
||||
}
|
||||
}
|
||||
|
||||
FsFileSystem fileSystem;
|
||||
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
|
||||
res = FileSystem::mount(&fileSystem, title.id(), uid);
|
||||
if (R_SUCCEEDED(res)) {
|
||||
int rc = FileSystem::mount(fileSystem);
|
||||
if (rc == -1) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during restore. Title id: 0x%016lX; User id: 0x%lX%lX.", title.id(),
|
||||
title.userId().uid[1], title.userId().uid[0]);
|
||||
uid.uid[1], uid.uid[0]);
|
||||
return std::make_tuple(false, -2, "Failed to mount save.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::ERROR,
|
||||
"Failed to mount filesystem during restore with result 0x%08lX. Title id: 0x%016lX; User id: 0x%lX%lX.", res, title.id(),
|
||||
title.userId().uid[1], title.userId().uid[0]);
|
||||
uid.uid[1], uid.uid[0]);
|
||||
return std::make_tuple(false, res, "Failed to mount save.");
|
||||
}
|
||||
|
||||
std::string srcPath = title.fullPath(cellIndex) + "/";
|
||||
std::string suggestion = StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(uid)));
|
||||
std::string srcPath = title.path() + "/" + suggestion + "/";
|
||||
std::string dstPath = "save:/";
|
||||
|
||||
res = io::deleteFolderRecursively(dstPath.c_str());
|
||||
{
|
||||
Directory saveRoot(dstPath);
|
||||
for (size_t i = 0, sz = saveRoot.size(); i < sz; i++) {
|
||||
if (saveRoot.folder(i)) {
|
||||
io::deleteFolderRecursively((dstPath + saveRoot.entry(i) + "/").c_str());
|
||||
rmdir((dstPath + saveRoot.entry(i)).c_str());
|
||||
} else {
|
||||
std::remove((dstPath + saveRoot.entry(i)).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res = fsdevCommitDevice("save");
|
||||
if (R_FAILED(res)) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to recursively delete directory " + dstPath + " with result 0x%08lX.", res);
|
||||
return std::make_tuple(false, res, "Failed to delete save.");
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to commit save after clearing with result 0x%08lX.", res);
|
||||
return std::make_tuple(false, res, "Failed to commit save after delete.");
|
||||
}
|
||||
|
||||
res = io::copyDirectory(srcPath, dstPath);
|
||||
|
||||
Reference in New Issue
Block a user