summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.h17
-rw-r--r--src/core/file_sys/archive_extsavedata.cpp59
-rw-r--r--src/core/file_sys/archive_extsavedata.h45
-rw-r--r--src/core/file_sys/archive_romfs.cpp5
-rw-r--r--src/core/file_sys/archive_romfs.h6
-rw-r--r--src/core/file_sys/archive_savedata.cpp25
-rw-r--r--src/core/file_sys/archive_savedata.h19
-rw-r--r--src/core/file_sys/disk_archive.h7
8 files changed, 168 insertions, 15 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index e153917ea..1612c35c2 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -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:
@@ -175,6 +178,20 @@ public:
}
/**
+ * 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.)
*/
virtual std::string GetName() const = 0;
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp
new file mode 100644
index 000000000..4759ef3ae
--- /dev/null
+++ b/src/core/file_sys/archive_extsavedata.cpp
@@ -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
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h
new file mode 100644
index 000000000..a3a144799
--- /dev/null
+++ b/src/core/file_sys/archive_extsavedata.h
@@ -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
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index fdaf73179..2fc3831b7 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -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
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 5e918f92d..d4b1eb7f2 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -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;
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index 97853567c..280d4ff5d 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -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
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h
index 5b0ce29e6..07c7f7eff 100644
--- a/src/core/file_sys/archive_savedata.h
+++ b/src/core/file_sys/archive_savedata.h
@@ -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
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 018ebd2ed..f18d96f5a 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -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;
}