summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-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/loader/loader.cpp6
6 files changed, 32 insertions, 12 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)
5project(citra) 5project(citra)
6 6
7if (NOT MSVC) 7if (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")
10else() 9else()
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
9namespace Common {
10
11template <typename T, typename... Args>
12std::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 */
31std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { 32std::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 */
80std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { 81std::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
262ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code) { 263ResultCode 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/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;