浏览代码

savedata_factory: Expose accessors for SaveDataSpace

Zach Hilman 7 年之前
父节点
当前提交
df264d2ccb

+ 18 - 14
src/core/file_sys/savedata_factory.cpp

@@ -83,28 +83,32 @@ ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, SaveDataDescr
     return MakeResult<VirtualDir>(std::move(out));
 }
 
-std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
-                                         u128 user_id, u64 save_id) {
-    // According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
-    // be interpreted as the title id of the current process.
-    if (type == SaveDataType::SaveData && title_id == 0)
-        title_id = Core::CurrentProcess()->GetTitleID();
-
-    std::string out;
+VirtualDir SaveDataFactory::GetSaveDataSpaceDirectory(SaveDataSpaceId space) {
+    return dir->GetDirectoryRelative(GetSaveDataSpaceIdPath(space));
+}
 
+std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) {
     switch (space) {
     case SaveDataSpaceId::NandSystem:
-        out = "/system/";
-        break;
+        return "/system/";
     case SaveDataSpaceId::NandUser:
-        out = "/user/";
-        break;
+        return "/user/";
     case SaveDataSpaceId::TemporaryStorage:
-        out = "/temp/";
-        break;
+        return "/temp/";
     default:
         ASSERT_MSG(false, "Unrecognized SaveDataSpaceId: {:02X}", static_cast<u8>(space));
+        return "/unrecognized/"; ///< To prevent corruption when ignoring asserts.
     }
+}
+
+std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
+                                         u128 user_id, u64 save_id) {
+    // According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
+    // be interpreted as the title id of the current process.
+    if (type == SaveDataType::SaveData && title_id == 0)
+        title_id = Core::CurrentProcess()->GetTitleID();
+
+    std::string out = GetSaveDataSpaceIdPath(space);
 
     switch (type) {
     case SaveDataType::SystemSaveData:

+ 3 - 0
src/core/file_sys/savedata_factory.h

@@ -52,6 +52,9 @@ public:
 
     ResultVal<VirtualDir> Open(SaveDataSpaceId space, SaveDataDescriptor meta);
 
+    VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space);
+
+    static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
     static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
                                    u128 user_id, u64 save_id);
 

+ 10 - 0
src/core/hle/service/filesystem/filesystem.cpp

@@ -309,6 +309,16 @@ ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
     return save_data_factory->Open(space, save_struct);
 }
 
+ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) {
+    LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", static_cast<u8>(space));
+
+    if (save_data_factory == nullptr) {
+        return ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound);
+    }
+
+    return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space));
+}
+
 ResultVal<FileSys::VirtualDir> OpenSDMC() {
     LOG_TRACE(Service_FS, "Opening SDMC");
 

+ 1 - 0
src/core/hle/service/filesystem/filesystem.h

@@ -45,6 +45,7 @@ ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId stora
                                           FileSys::ContentRecordType type);
 ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
                                             FileSys::SaveDataDescriptor save_struct);
+ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space);
 ResultVal<FileSys::VirtualDir> OpenSDMC();
 
 std::unique_ptr<FileSys::RegisteredCacheUnion> GetUnionContents();