aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/make_unique.h16
-rw-r--r--src/core/file_sys/archive_romfs.cpp5
-rw-r--r--src/core/hle/service/fs/archive.cpp13
-rw-r--r--src/core/hle/service/fs/fs_user.cpp33
-rw-r--r--src/core/loader/loader.cpp6
6 files changed, 62 insertions, 12 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 15989708..3c3419bb 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -49,6 +49,7 @@ set(HEADERS
logging/filter.h
logging/log.h
logging/backend.h
+ make_unique.h
math_util.h
mem_arena.h
memory_util.h
diff --git a/src/common/make_unique.h b/src/common/make_unique.h
new file mode 100644
index 00000000..2a7b7641
--- /dev/null
+++ b/src/common/make_unique.h
@@ -0,0 +1,16 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+
+namespace Common {
+
+template <typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args&&... args) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+} // namespace
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 0709b62a..1e3e9dc6 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -5,6 +5,7 @@
#include <memory>
#include "common/common_types.h"
+#include "common/make_unique.h"
#include "core/file_sys/archive_romfs.h"
#include "core/file_sys/directory_romfs.h"
@@ -29,7 +30,7 @@ Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) {
* @return Opened file, or nullptr
*/
std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
- return std::make_unique<File_RomFS>(this);
+ return Common::make_unique<File_RomFS>(this);
}
/**
@@ -78,7 +79,7 @@ bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys
* @return Opened directory, or nullptr
*/
std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const {
- return std::make_unique<Directory_RomFS>();
+ return Common::make_unique<Directory_RomFS>();
}
} // namespace FileSys
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 5ab82729..510d7320 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -7,6 +7,7 @@
#include "common/common_types.h"
#include "common/file_util.h"
+#include "common/make_unique.h"
#include "common/math_util.h"
#include "core/file_sys/archive_savedata.h"
@@ -260,7 +261,7 @@ ResultCode CloseArchive(ArchiveHandle handle) {
// TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
// http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) {
- auto result = id_code_map.emplace(id_code, std::make_unique<Archive>(std::move(backend), id_code));
+ auto result = id_code_map.emplace(id_code, Common::make_unique<Archive>(std::move(backend), id_code));
bool inserted = result.second;
_dbg_assert_msg_(Service_FS, inserted, "Tried to register more than one archive with same id code");
@@ -281,7 +282,7 @@ ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSy
ErrorSummary::NotFound, ErrorLevel::Status);
}
- auto file = std::make_unique<File>(std::move(backend), path);
+ auto file = Common::make_unique<File>(std::move(backend), path);
Handle handle = Kernel::g_object_pool.Create(file.release());
return MakeResult<Handle>(handle);
}
@@ -378,7 +379,7 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F
ErrorSummary::NotFound, ErrorLevel::Permanent);
}
- auto directory = std::make_unique<Directory>(std::move(backend), path);
+ auto directory = Common::make_unique<Directory>(std::move(backend), path);
Handle handle = Kernel::g_object_pool.Create(directory.release());
return MakeResult<Handle>(handle);
}
@@ -392,7 +393,7 @@ ResultCode FormatSaveData() {
// Create the SaveData archive
std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX);
- auto savedata_archive = std::make_unique<FileSys::Archive_SaveData>(savedata_directory,
+ auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory,
Kernel::g_program_id);
if (savedata_archive->Initialize()) {
@@ -414,14 +415,14 @@ void ArchiveInit() {
// archive type is SDMC, so it is the only one getting exposed.
std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
- auto sdmc_archive = std::make_unique<FileSys::Archive_SDMC>(sdmc_directory);
+ auto sdmc_archive = Common::make_unique<FileSys::Archive_SDMC>(sdmc_directory);
if (sdmc_archive->Initialize())
CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC);
else
LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
std::string systemsavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX);
- auto systemsavedata_archive = std::make_unique<FileSys::Archive_SDMC>(systemsavedata_directory);
+ auto systemsavedata_archive = Common::make_unique<FileSys::Archive_SDMC>(systemsavedata_directory);
if (systemsavedata_archive->Initialize()) {
CreateArchive(std::move(systemsavedata_archive), ArchiveIdCode::SystemSaveData);
} else {
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index f99d84b2..8b908d69 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -397,16 +397,44 @@ static void IsSdmcDetected(Service::Interface* self) {
}
/**
- * FS_User::FormatSaveData service function
+ * FS_User::FormatSaveData service function,
+ * formats the SaveData specified by the input path.
* Inputs:
+ * 0 : 0x084C0242
+ * 1 : Archive ID
+ * 2 : Archive low path type
+ * 3 : Archive low path size
+ * 10 : (LowPathSize << 14) | 2
+ * 11 : Archive low path
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void FormatSaveData(Service::Interface* self) {
+ // TODO(Subv): Find out what the other inputs and outputs of this function are
u32* cmd_buff = Kernel::GetCommandBuffer();
LOG_DEBUG(Service_FS, "(STUBBED)");
- // TODO(Subv): Find out what the inputs and outputs of this function are
+ auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
+ auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
+ u32 archivename_size = cmd_buff[3];
+ u32 archivename_ptr = cmd_buff[11];
+ FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
+
+ LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str());
+
+ if (archive_id != FS::ArchiveIdCode::SaveData) {
+ // TODO(Subv): What should happen if somebody attempts to format a different archive?
+ LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", cmd_buff[1]);
+ cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
+ return;
+ }
+
+ if (archive_path.GetType() != FileSys::LowPathType::Empty) {
+ // TODO(Subv): Implement formatting the SaveData of other games
+ LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported");
+ cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
+ return;
+ }
cmd_buff[1] = FormatSaveData().raw;
}
@@ -414,6 +442,7 @@ static void FormatSaveData(Service::Interface* self) {
/**
* FS_User::FormatThisUserSaveData service function
* Inputs:
+ * 0: 0x080F0180
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 480274d2..b3b58da7 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -2,7 +2,9 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
-#include <memory>
+#include <string>
+
+#include "common/make_unique.h"
#include "core/file_sys/archive_romfs.h"
#include "core/loader/3dsx.h"
@@ -75,7 +77,7 @@ ResultStatus LoadFile(const std::string& filename) {
// Load application and RomFS
if (ResultStatus::Success == app_loader.Load()) {
Kernel::g_program_id = app_loader.GetProgramId();
- Service::FS::CreateArchive(std::make_unique<FileSys::Archive_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
+ Service::FS::CreateArchive(Common::make_unique<FileSys::Archive_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
return ResultStatus::Success;
}
break;