summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-03-04 13:03:58 -0500
committerGravatar Subv2018-03-04 14:30:07 -0500
commit0eefe6e4d15cbc7a5902dfbe5e7742ef4ea71902 (patch)
treed6fbf1e18b6b17fcb089306af26c48331100814c /src
parentMerge pull request #226 from Subv/buffer_queue_event (diff)
downloadyuzu-0eefe6e4d15cbc7a5902dfbe5e7742ef4ea71902.tar.gz
yuzu-0eefe6e4d15cbc7a5902dfbe5e7742ef4ea71902.tar.xz
yuzu-0eefe6e4d15cbc7a5902dfbe5e7742ef4ea71902.zip
FS: Make EnsureSaveData create the savedata folder when called for the first time.
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/filesystem.h3
-rw-r--r--src/core/file_sys/romfs_factory.cpp2
-rw-r--r--src/core/file_sys/romfs_factory.h2
-rw-r--r--src/core/file_sys/savedata_factory.cpp34
-rw-r--r--src/core/file_sys/savedata_factory.h4
-rw-r--r--src/core/hle/service/am/am.cpp22
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp13
-rw-r--r--src/core/hle/service/filesystem/filesystem.h7
8 files changed, 70 insertions, 17 deletions
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h
index df4e66a0b..94ad2abf2 100644
--- a/src/core/file_sys/filesystem.h
+++ b/src/core/file_sys/filesystem.h
@@ -183,10 +183,9 @@ public:
183 /** 183 /**
184 * Deletes the archive contents and then re-creates the base folder 184 * Deletes the archive contents and then re-creates the base folder
185 * @param path Path to the archive 185 * @param path Path to the archive
186 * @param format_info Format information for the new archive
187 * @return ResultCode of the operation, 0 on success 186 * @return ResultCode of the operation, 0 on success
188 */ 187 */
189 virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) = 0; 188 virtual ResultCode Format(const Path& path) = 0;
190 189
191 /** 190 /**
192 * Retrieves the format info about the archive with the specified path 191 * Retrieves the format info about the archive with the specified path
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp
index e0de49f05..b21427948 100644
--- a/src/core/file_sys/romfs_factory.cpp
+++ b/src/core/file_sys/romfs_factory.cpp
@@ -23,7 +23,7 @@ ResultVal<std::unique_ptr<FileSystemBackend>> RomFS_Factory::Open(const Path& pa
23 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive)); 23 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
24} 24}
25 25
26ResultCode RomFS_Factory::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 26ResultCode RomFS_Factory::Format(const Path& path) {
27 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str()); 27 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str());
28 // TODO(bunnei): Find the right error code for this 28 // TODO(bunnei): Find the right error code for this
29 return ResultCode(-1); 29 return ResultCode(-1);
diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h
index 10ea13966..e0698e642 100644
--- a/src/core/file_sys/romfs_factory.h
+++ b/src/core/file_sys/romfs_factory.h
@@ -23,7 +23,7 @@ public:
23 return "ArchiveFactory_RomFS"; 23 return "ArchiveFactory_RomFS";
24 } 24 }
25 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override; 25 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override;
26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 26 ResultCode Format(const Path& path) override;
27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
28 28
29private: 29private:
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp
index 4d83e100f..c3329ce52 100644
--- a/src/core/file_sys/savedata_factory.cpp
+++ b/src/core/file_sys/savedata_factory.cpp
@@ -17,20 +17,26 @@ SaveData_Factory::SaveData_Factory(std::string nand_directory)
17 : nand_directory(std::move(nand_directory)) {} 17 : nand_directory(std::move(nand_directory)) {}
18 18
19ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) { 19ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) {
20 u64 title_id = Kernel::g_current_process->program_id; 20 std::string save_directory = GetFullPath();
21 // TODO(Subv): Somehow obtain this value. 21 // Return an error if the save data doesn't actually exist.
22 u32 user = 0; 22 if (!FileUtil::IsDirectory(save_directory)) {
23 std::string save_directory = Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X", 23 // TODO(Subv): Find out correct error code.
24 nand_directory.c_str(), title_id, user); 24 return ResultCode(-1);
25 }
26
25 auto archive = std::make_unique<Disk_FileSystem>(save_directory); 27 auto archive = std::make_unique<Disk_FileSystem>(save_directory);
26 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive)); 28 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
27} 29}
28 30
29ResultCode SaveData_Factory::Format(const Path& path, 31ResultCode SaveData_Factory::Format(const Path& path) {
30 const FileSys::ArchiveFormatInfo& format_info) { 32 LOG_WARNING(Service_FS, "Format archive %s", GetName().c_str());
31 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str()); 33 // Create the save data directory.
32 // TODO(bunnei): Find the right error code for this 34 if (!FileUtil::CreateFullPath(GetFullPath())) {
33 return ResultCode(-1); 35 // TODO(Subv): Find the correct error code.
36 return ResultCode(-1);
37 }
38
39 return RESULT_SUCCESS;
34} 40}
35 41
36ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const { 42ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const {
@@ -39,4 +45,12 @@ ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) c
39 return ResultCode(-1); 45 return ResultCode(-1);
40} 46}
41 47
48std::string SaveData_Factory::GetFullPath() const {
49 u64 title_id = Kernel::g_current_process->program_id;
50 // TODO(Subv): Somehow obtain this value.
51 u32 user = 0;
52 return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id,
53 user);
54}
55
42} // namespace FileSys 56} // namespace FileSys
diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h
index 726743fde..73a42aab6 100644
--- a/src/core/file_sys/savedata_factory.h
+++ b/src/core/file_sys/savedata_factory.h
@@ -21,11 +21,13 @@ public:
21 return "SaveData_Factory"; 21 return "SaveData_Factory";
22 } 22 }
23 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override; 23 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override;
24 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 24 ResultCode Format(const Path& path) override;
25 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 25 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
26 26
27private: 27private:
28 std::string nand_directory; 28 std::string nand_directory;
29
30 std::string GetFullPath() const;
29}; 31};
30 32
31} // namespace FileSys 33} // namespace FileSys
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index d3a674cf6..d9f003ed4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -2,12 +2,15 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes>
6#include "core/file_sys/filesystem.h"
5#include "core/hle/ipc_helpers.h" 7#include "core/hle/ipc_helpers.h"
6#include "core/hle/kernel/event.h" 8#include "core/hle/kernel/event.h"
7#include "core/hle/service/am/am.h" 9#include "core/hle/service/am/am.h"
8#include "core/hle/service/am/applet_ae.h" 10#include "core/hle/service/am/applet_ae.h"
9#include "core/hle/service/am/applet_oe.h" 11#include "core/hle/service/am/applet_oe.h"
10#include "core/hle/service/apm/apm.h" 12#include "core/hle/service/apm/apm.h"
13#include "core/hle/service/filesystem/filesystem.h"
11#include "core/hle/service/nvflinger/nvflinger.h" 14#include "core/hle/service/nvflinger/nvflinger.h"
12 15
13namespace Service { 16namespace Service {
@@ -416,9 +419,24 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
416} 419}
417 420
418void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { 421void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
419 LOG_WARNING(Service, "(STUBBED) called"); 422 IPC::RequestParser rp{ctx};
423 u128 uid = rp.PopRaw<u128>();
424
425 LOG_WARNING(Service, "(STUBBED) called uid = %016" PRIX64 "%016" PRIX64, uid[1], uid[0]);
426
420 IPC::ResponseBuilder rb{ctx, 4}; 427 IPC::ResponseBuilder rb{ctx, 4};
421 rb.Push(RESULT_SUCCESS); 428
429 FileSys::Path unused;
430 auto savedata = FileSystem::OpenFileSystem(FileSystem::Type::SaveData, unused);
431 if (savedata.Failed()) {
432 // Create the save data and return an error indicating that the operation was performed.
433 FileSystem::FormatFileSystem(FileSystem::Type::SaveData);
434 // TODO(Subv): Find out the correct error code for this.
435 rb.Push(ResultCode(ErrorModule::FS, 40));
436 } else {
437 rb.Push(RESULT_SUCCESS);
438 }
439
422 rb.Push<u64>(0); 440 rb.Push<u64>(0);
423} 441}
424 442
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index 32752aea5..ef05955b9 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -43,6 +43,19 @@ ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
43 return itr->second->Open(path); 43 return itr->second->Open(path);
44} 44}
45 45
46ResultCode FormatFileSystem(Type type) {
47 LOG_TRACE(Service_FS, "Formatting FileSystem with type=%d", type);
48
49 auto itr = filesystem_map.find(type);
50 if (itr == filesystem_map.end()) {
51 // TODO(bunnei): Find a better error code for this
52 return ResultCode(-1);
53 }
54
55 FileSys::Path unused;
56 return itr->second->Format(unused);
57}
58
46void RegisterFileSystems() { 59void RegisterFileSystems() {
47 filesystem_map.clear(); 60 filesystem_map.clear();
48 61
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h
index 80f318676..8d30e94a1 100644
--- a/src/core/hle/service/filesystem/filesystem.h
+++ b/src/core/hle/service/filesystem/filesystem.h
@@ -44,6 +44,13 @@ ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& fact
44ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, 44ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
45 FileSys::Path& path); 45 FileSys::Path& path);
46 46
47/**
48 * Formats a file system
49 * @param type Type of the file system to format
50 * @return ResultCode of the operation
51 */
52ResultCode FormatFileSystem(Type type);
53
47/// Registers all Filesystem services with the specified service manager. 54/// Registers all Filesystem services with the specified service manager.
48void InstallInterfaces(SM::ServiceManager& service_manager); 55void InstallInterfaces(SM::ServiceManager& service_manager);
49 56