diff options
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/make_unique.h | 16 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/service/fs/archive.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/service/fs/fs_user.cpp | 33 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 6 |
7 files changed, 63 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 63738b5ff..61d5d524a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -5,8 +5,7 @@ cmake_minimum_required(VERSION 2.8.11) | |||
| 5 | project(citra) | 5 | project(citra) |
| 6 | 6 | ||
| 7 | if (NOT MSVC) | 7 | if (NOT MSVC) |
| 8 | # -std=c++14 is only supported on very new compilers, so use the old c++1y alias instead. | 8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes") |
| 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wno-attributes") | ||
| 10 | else() | 9 | else() |
| 11 | # Silence deprecation warnings | 10 | # Silence deprecation warnings |
| 12 | add_definitions(/D_CRT_SECURE_NO_WARNINGS) | 11 | add_definitions(/D_CRT_SECURE_NO_WARNINGS) |
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 15989708d..3c3419bbc 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -49,6 +49,7 @@ set(HEADERS | |||
| 49 | logging/filter.h | 49 | logging/filter.h |
| 50 | logging/log.h | 50 | logging/log.h |
| 51 | logging/backend.h | 51 | logging/backend.h |
| 52 | make_unique.h | ||
| 52 | math_util.h | 53 | math_util.h |
| 53 | mem_arena.h | 54 | mem_arena.h |
| 54 | memory_util.h | 55 | memory_util.h |
diff --git a/src/common/make_unique.h b/src/common/make_unique.h new file mode 100644 index 000000000..2a7b76412 --- /dev/null +++ b/src/common/make_unique.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | template <typename T, typename... Args> | ||
| 12 | std::unique_ptr<T> make_unique(Args&&... args) { | ||
| 13 | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | ||
| 14 | } | ||
| 15 | |||
| 16 | } // namespace | ||
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 0709b62a1..1e3e9dc60 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/make_unique.h" | ||
| 8 | 9 | ||
| 9 | #include "core/file_sys/archive_romfs.h" | 10 | #include "core/file_sys/archive_romfs.h" |
| 10 | #include "core/file_sys/directory_romfs.h" | 11 | #include "core/file_sys/directory_romfs.h" |
| @@ -29,7 +30,7 @@ Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) { | |||
| 29 | * @return Opened file, or nullptr | 30 | * @return Opened file, or nullptr |
| 30 | */ | 31 | */ |
| 31 | std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { | 32 | std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { |
| 32 | return std::make_unique<File_RomFS>(this); | 33 | return Common::make_unique<File_RomFS>(this); |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | /** | 36 | /** |
| @@ -78,7 +79,7 @@ bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys | |||
| 78 | * @return Opened directory, or nullptr | 79 | * @return Opened directory, or nullptr |
| 79 | */ | 80 | */ |
| 80 | std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { | 81 | std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { |
| 81 | return std::make_unique<Directory_RomFS>(); | 82 | return Common::make_unique<Directory_RomFS>(); |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | } // namespace FileSys | 85 | } // namespace FileSys |
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 5ab82729c..510d7320c 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 10 | #include "common/make_unique.h" | ||
| 10 | #include "common/math_util.h" | 11 | #include "common/math_util.h" |
| 11 | 12 | ||
| 12 | #include "core/file_sys/archive_savedata.h" | 13 | #include "core/file_sys/archive_savedata.h" |
| @@ -260,7 +261,7 @@ ResultCode CloseArchive(ArchiveHandle handle) { | |||
| 260 | // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in | 261 | // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in |
| 261 | // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22 | 262 | // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22 |
| 262 | ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) { | 263 | ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) { |
| 263 | auto result = id_code_map.emplace(id_code, std::make_unique<Archive>(std::move(backend), id_code)); | 264 | auto result = id_code_map.emplace(id_code, Common::make_unique<Archive>(std::move(backend), id_code)); |
| 264 | 265 | ||
| 265 | bool inserted = result.second; | 266 | bool inserted = result.second; |
| 266 | _dbg_assert_msg_(Service_FS, inserted, "Tried to register more than one archive with same id code"); | 267 | _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 | |||
| 281 | ErrorSummary::NotFound, ErrorLevel::Status); | 282 | ErrorSummary::NotFound, ErrorLevel::Status); |
| 282 | } | 283 | } |
| 283 | 284 | ||
| 284 | auto file = std::make_unique<File>(std::move(backend), path); | 285 | auto file = Common::make_unique<File>(std::move(backend), path); |
| 285 | Handle handle = Kernel::g_object_pool.Create(file.release()); | 286 | Handle handle = Kernel::g_object_pool.Create(file.release()); |
| 286 | return MakeResult<Handle>(handle); | 287 | return MakeResult<Handle>(handle); |
| 287 | } | 288 | } |
| @@ -378,7 +379,7 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F | |||
| 378 | ErrorSummary::NotFound, ErrorLevel::Permanent); | 379 | ErrorSummary::NotFound, ErrorLevel::Permanent); |
| 379 | } | 380 | } |
| 380 | 381 | ||
| 381 | auto directory = std::make_unique<Directory>(std::move(backend), path); | 382 | auto directory = Common::make_unique<Directory>(std::move(backend), path); |
| 382 | Handle handle = Kernel::g_object_pool.Create(directory.release()); | 383 | Handle handle = Kernel::g_object_pool.Create(directory.release()); |
| 383 | return MakeResult<Handle>(handle); | 384 | return MakeResult<Handle>(handle); |
| 384 | } | 385 | } |
| @@ -392,7 +393,7 @@ ResultCode FormatSaveData() { | |||
| 392 | 393 | ||
| 393 | // Create the SaveData archive | 394 | // Create the SaveData archive |
| 394 | std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX); | 395 | std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX); |
| 395 | auto savedata_archive = std::make_unique<FileSys::Archive_SaveData>(savedata_directory, | 396 | auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory, |
| 396 | Kernel::g_program_id); | 397 | Kernel::g_program_id); |
| 397 | 398 | ||
| 398 | if (savedata_archive->Initialize()) { | 399 | if (savedata_archive->Initialize()) { |
| @@ -414,14 +415,14 @@ void ArchiveInit() { | |||
| 414 | // archive type is SDMC, so it is the only one getting exposed. | 415 | // archive type is SDMC, so it is the only one getting exposed. |
| 415 | 416 | ||
| 416 | std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX); | 417 | std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX); |
| 417 | auto sdmc_archive = std::make_unique<FileSys::Archive_SDMC>(sdmc_directory); | 418 | auto sdmc_archive = Common::make_unique<FileSys::Archive_SDMC>(sdmc_directory); |
| 418 | if (sdmc_archive->Initialize()) | 419 | if (sdmc_archive->Initialize()) |
| 419 | CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC); | 420 | CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC); |
| 420 | else | 421 | else |
| 421 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); | 422 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); |
| 422 | 423 | ||
| 423 | std::string systemsavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX); | 424 | std::string systemsavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX); |
| 424 | auto systemsavedata_archive = std::make_unique<FileSys::Archive_SDMC>(systemsavedata_directory); | 425 | auto systemsavedata_archive = Common::make_unique<FileSys::Archive_SDMC>(systemsavedata_directory); |
| 425 | if (systemsavedata_archive->Initialize()) { | 426 | if (systemsavedata_archive->Initialize()) { |
| 426 | CreateArchive(std::move(systemsavedata_archive), ArchiveIdCode::SystemSaveData); | 427 | CreateArchive(std::move(systemsavedata_archive), ArchiveIdCode::SystemSaveData); |
| 427 | } else { | 428 | } else { |
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index f99d84b2f..8b908d691 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) { | |||
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | /** | 399 | /** |
| 400 | * FS_User::FormatSaveData service function | 400 | * FS_User::FormatSaveData service function, |
| 401 | * formats the SaveData specified by the input path. | ||
| 401 | * Inputs: | 402 | * Inputs: |
| 403 | * 0 : 0x084C0242 | ||
| 404 | * 1 : Archive ID | ||
| 405 | * 2 : Archive low path type | ||
| 406 | * 3 : Archive low path size | ||
| 407 | * 10 : (LowPathSize << 14) | 2 | ||
| 408 | * 11 : Archive low path | ||
| 402 | * Outputs: | 409 | * Outputs: |
| 403 | * 1 : Result of function, 0 on success, otherwise error code | 410 | * 1 : Result of function, 0 on success, otherwise error code |
| 404 | */ | 411 | */ |
| 405 | static void FormatSaveData(Service::Interface* self) { | 412 | static void FormatSaveData(Service::Interface* self) { |
| 413 | // TODO(Subv): Find out what the other inputs and outputs of this function are | ||
| 406 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 414 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 407 | LOG_DEBUG(Service_FS, "(STUBBED)"); | 415 | LOG_DEBUG(Service_FS, "(STUBBED)"); |
| 408 | 416 | ||
| 409 | // TODO(Subv): Find out what the inputs and outputs of this function are | 417 | auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]); |
| 418 | auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); | ||
| 419 | u32 archivename_size = cmd_buff[3]; | ||
| 420 | u32 archivename_ptr = cmd_buff[11]; | ||
| 421 | FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr); | ||
| 422 | |||
| 423 | LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str()); | ||
| 424 | |||
| 425 | if (archive_id != FS::ArchiveIdCode::SaveData) { | ||
| 426 | // TODO(Subv): What should happen if somebody attempts to format a different archive? | ||
| 427 | LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", cmd_buff[1]); | ||
| 428 | cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw; | ||
| 429 | return; | ||
| 430 | } | ||
| 431 | |||
| 432 | if (archive_path.GetType() != FileSys::LowPathType::Empty) { | ||
| 433 | // TODO(Subv): Implement formatting the SaveData of other games | ||
| 434 | LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported"); | ||
| 435 | cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw; | ||
| 436 | return; | ||
| 437 | } | ||
| 410 | 438 | ||
| 411 | cmd_buff[1] = FormatSaveData().raw; | 439 | cmd_buff[1] = FormatSaveData().raw; |
| 412 | } | 440 | } |
| @@ -414,6 +442,7 @@ static void FormatSaveData(Service::Interface* self) { | |||
| 414 | /** | 442 | /** |
| 415 | * FS_User::FormatThisUserSaveData service function | 443 | * FS_User::FormatThisUserSaveData service function |
| 416 | * Inputs: | 444 | * Inputs: |
| 445 | * 0: 0x080F0180 | ||
| 417 | * Outputs: | 446 | * Outputs: |
| 418 | * 1 : Result of function, 0 on success, otherwise error code | 447 | * 1 : Result of function, 0 on success, otherwise error code |
| 419 | */ | 448 | */ |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 480274d23..b3b58da72 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <string> |
| 6 | |||
| 7 | #include "common/make_unique.h" | ||
| 6 | 8 | ||
| 7 | #include "core/file_sys/archive_romfs.h" | 9 | #include "core/file_sys/archive_romfs.h" |
| 8 | #include "core/loader/3dsx.h" | 10 | #include "core/loader/3dsx.h" |
| @@ -75,7 +77,7 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 75 | // Load application and RomFS | 77 | // Load application and RomFS |
| 76 | if (ResultStatus::Success == app_loader.Load()) { | 78 | if (ResultStatus::Success == app_loader.Load()) { |
| 77 | Kernel::g_program_id = app_loader.GetProgramId(); | 79 | Kernel::g_program_id = app_loader.GetProgramId(); |
| 78 | Service::FS::CreateArchive(std::make_unique<FileSys::Archive_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS); | 80 | Service::FS::CreateArchive(Common::make_unique<FileSys::Archive_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS); |
| 79 | return ResultStatus::Success; | 81 | return ResultStatus::Success; |
| 80 | } | 82 | } |
| 81 | break; | 83 | break; |