Archives: Implemented ExtSaveData and SharedExtSaveData
They will be stored in /extsavedata/SDMC and /extsavedata/NAND respectively. Also redirect some APT_A functions to their APT_U equivalents. Implemented the gamecoin.dat file in SharedExtSaveData in the PTM module. Implemented formatting the savegame. Retake a previous savegame if it exists instead of reporting them as not formatted every time a game is loaded.
This commit is contained in:
parent
3d14eb2853
commit
2c89d4d5cd
17 changed files with 268 additions and 60 deletions
|
@ -46,6 +46,9 @@ public:
|
|||
Path(const char* path) : type(Char), string(path) {
|
||||
}
|
||||
|
||||
Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {
|
||||
}
|
||||
|
||||
Path(LowPathType type, u32 size, u32 pointer) : type(type) {
|
||||
switch (type) {
|
||||
case Binary:
|
||||
|
@ -174,6 +177,20 @@ public:
|
|||
virtual ~ArchiveBackend() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to open the archive of this type with the specified path
|
||||
* @param path Path to the archive
|
||||
* @return ResultCode of the operation
|
||||
*/
|
||||
virtual ResultCode Open(const Path& path) = 0;
|
||||
|
||||
/**
|
||||
* Deletes the archive contents and then re-creates the base folder
|
||||
* @param path Path to the archive
|
||||
* @return ResultCode of the operation, 0 on success
|
||||
*/
|
||||
virtual ResultCode Format(const Path& path) const = 0;
|
||||
|
||||
/**
|
||||
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
|
||||
*/
|
||||
|
|
59
src/core/file_sys/archive_extsavedata.cpp
Normal file
59
src/core/file_sys/archive_extsavedata.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
|
||||
#include "core/file_sys/archive_extsavedata.h"
|
||||
#include "core/file_sys/disk_archive.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
static std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) {
|
||||
std::vector<u8> vec_data = path.AsBinary();
|
||||
const u32* data = reinterpret_cast<const u32*>(vec_data.data());
|
||||
u32 media_type = data[0];
|
||||
u32 save_low = data[1];
|
||||
u32 save_high = data[2];
|
||||
return Common::StringFromFormat("%s%s/%08X/%08X/", mount_point.c_str(), media_type == 0 ? "nand" : "sdmc", save_high, save_low);
|
||||
}
|
||||
|
||||
Archive_ExtSaveData::Archive_ExtSaveData(const std::string& mount_point)
|
||||
: DiskArchive(mount_point), concrete_mount_point(mount_point) {
|
||||
LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", this->mount_point.c_str());
|
||||
}
|
||||
|
||||
bool Archive_ExtSaveData::Initialize() {
|
||||
if (!FileUtil::CreateFullPath(mount_point)) {
|
||||
LOG_ERROR(Service_FS, "Unable to create ExtSaveData base path.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ResultCode Archive_ExtSaveData::Open(const Path& path) {
|
||||
std::string fullpath = GetExtSaveDataPath(mount_point, path);
|
||||
if (!FileUtil::Exists(fullpath)) {
|
||||
// TODO(Subv): Check error code, this one is probably wrong
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
}
|
||||
concrete_mount_point = fullpath;
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ResultCode Archive_ExtSaveData::Format(const Path& path) const {
|
||||
std::string fullpath = GetExtSaveDataPath(mount_point, path);
|
||||
FileUtil::CreateFullPath(fullpath);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace FileSys
|
45
src/core/file_sys/archive_extsavedata.h
Normal file
45
src/core/file_sys/archive_extsavedata.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
#include "core/file_sys/disk_archive.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
/// File system interface to the ExtSaveData archive
|
||||
class Archive_ExtSaveData final : public DiskArchive {
|
||||
public:
|
||||
Archive_ExtSaveData(const std::string& mount_point);
|
||||
|
||||
/**
|
||||
* Initialize the archive.
|
||||
* @return true if it initialized successfully
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
ResultCode Open(const Path& path) override;
|
||||
ResultCode Format(const Path& path) const override;
|
||||
std::string GetName() const override { return "ExtSaveData"; }
|
||||
|
||||
const std::string& GetMountPoint() const override {
|
||||
return concrete_mount_point;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This holds the full directory path for this archive, it is only set after a successful call to Open,
|
||||
* this is formed as <base extsavedatapath>/<type>/<high>/<low>.
|
||||
* See GetExtSaveDataPath for the code that extracts this data from an archive path.
|
||||
*/
|
||||
std::string concrete_mount_point;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
|
@ -62,4 +62,9 @@ std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path)
|
|||
return Common::make_unique<Directory_RomFS>();
|
||||
}
|
||||
|
||||
ResultCode Archive_RomFS::Format(const Path& path) const {
|
||||
LOG_WARNING(Service_FS, "Attempted to format ROMFS.");
|
||||
return UnimplementedFunction(ErrorModule::FS);
|
||||
}
|
||||
|
||||
} // namespace FileSys
|
||||
|
|
|
@ -83,6 +83,12 @@ public:
|
|||
*/
|
||||
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
||||
|
||||
ResultCode Open(const Path& path) override {
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ResultCode Format(const Path& path) const override;
|
||||
|
||||
private:
|
||||
friend class File_RomFS;
|
||||
|
||||
|
|
|
@ -16,18 +16,29 @@
|
|||
|
||||
namespace FileSys {
|
||||
|
||||
Archive_SaveData::Archive_SaveData(const std::string& mount_point, u64 program_id)
|
||||
: DiskArchive(mount_point + Common::StringFromFormat("%016X", program_id) + DIR_SEP) {
|
||||
Archive_SaveData::Archive_SaveData(const std::string& mount_point)
|
||||
: DiskArchive(mount_point) {
|
||||
LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str());
|
||||
}
|
||||
|
||||
bool Archive_SaveData::Initialize() {
|
||||
if (!FileUtil::CreateFullPath(mount_point)) {
|
||||
LOG_ERROR(Service_FS, "Unable to create SaveData path.");
|
||||
return false;
|
||||
ResultCode Archive_SaveData::Open(const Path& path) {
|
||||
if (concrete_mount_point.empty())
|
||||
concrete_mount_point = Common::StringFromFormat("%s%016X", mount_point.c_str(), Kernel::g_program_id) + DIR_SEP;
|
||||
if (!FileUtil::Exists(concrete_mount_point)) {
|
||||
// When a SaveData archive is created for the first time, it is not yet formatted
|
||||
// and the save file/directory structure expected by the game has not yet been initialized.
|
||||
// Returning the NotFormatted error code will signal the game to provision the SaveData archive
|
||||
// with the files and folders that it expects.
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
return true;
|
||||
ResultCode Archive_SaveData::Format(const Path& path) const {
|
||||
FileUtil::DeleteDirRecursively(concrete_mount_point);
|
||||
FileUtil::CreateFullPath(concrete_mount_point);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace FileSys
|
||||
|
|
|
@ -17,15 +17,20 @@ namespace FileSys {
|
|||
/// File system interface to the SaveData archive
|
||||
class Archive_SaveData final : public DiskArchive {
|
||||
public:
|
||||
Archive_SaveData(const std::string& mount_point, u64 program_id);
|
||||
|
||||
/**
|
||||
* Initialize the archive.
|
||||
* @return true if it initialized successfully
|
||||
*/
|
||||
bool Initialize();
|
||||
Archive_SaveData(const std::string& mount_point);
|
||||
|
||||
std::string GetName() const override { return "SaveData"; }
|
||||
|
||||
ResultCode Open(const Path& path) override;
|
||||
|
||||
ResultCode Format(const Path& path) const override;
|
||||
|
||||
const std::string& GetMountPoint() const override {
|
||||
return concrete_mount_point;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string concrete_mount_point;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {}
|
||||
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual ResultCode Format(const Path& path) const { return RESULT_SUCCESS; }
|
||||
std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
|
||||
bool DeleteFile(const Path& path) const override;
|
||||
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||
|
@ -34,11 +35,15 @@ public:
|
|||
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
||||
|
||||
virtual ResultCode Open(const Path& path) override {
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the path used for this Archive
|
||||
* @return Mount point of that passthrough archive
|
||||
*/
|
||||
const std::string& GetMountPoint() const {
|
||||
virtual const std::string& GetMountPoint() const {
|
||||
return mount_point;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue