Skip to content

Commit bcbe6aa

Browse files
author
N3xoX1
committed
EnsureSaveData function as well as cleaning up the virtual file system and some code clean up
1 parent 5bc00fd commit bcbe6aa

49 files changed

Lines changed: 1040 additions & 321 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/nxemu-loader/core/file_sys/filesystem.cpp‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: GPL-2.0-or-later
33

44
#include "core/file_sys/filesystem.h"
5-
#include "core/file_sys/fs_filesystem.h"
65
#include "core/file_sys/vfs/vfs.h"
76
#include "core/file_sys/savedata_factory.h"
87
#include "core/file_sys/registered_cache.h"
@@ -40,6 +39,24 @@ IFileSysRegisteredCache * FileSystemController::GetSystemNANDContents() const
4039
return SystemNANDContents();
4140
}
4241

42+
ISaveDataController * FileSystemController::OpenSaveDataController() const
43+
{
44+
UNIMPLEMENTED();
45+
return nullptr;
46+
}
47+
48+
uint64_t FileSystemController::GetFreeSpaceSize(StorageId id) const
49+
{
50+
UNIMPLEMENTED();
51+
return 0;
52+
}
53+
54+
uint64_t FileSystemController::GetTotalSpaceSize(StorageId id) const
55+
{
56+
UNIMPLEMENTED();
57+
return 0;
58+
}
59+
4360
bool FileSystemController::OpenProcess(uint64_t* programId, ISaveDataFactory ** saveDataFactory, IRomFsController ** romFsController, uint64_t processId)
4461
{
4562
std::scoped_lock lk{ registration_lock };
@@ -96,15 +113,15 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem & vfs, bool ov
96113
using YuzuPath = Common::FS::YuzuPath;
97114
const auto sdmc_dir_path = Common::FS::GetYuzuPath(YuzuPath::SDMCDir);
98115
const auto sdmc_load_dir_path = sdmc_dir_path / "atmosphere/contents";
99-
const auto rw_mode = FileSys::OpenMode::ReadWrite;
116+
const auto rw_mode = VirtualFileOpenMode::ReadWrite;
100117

101118
auto nand_directory =
102119
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::NANDDir), rw_mode);
103120
auto sd_directory = vfs.OpenDirectory(Common::FS::PathToUTF8String(sdmc_dir_path), rw_mode);
104121
auto load_directory = vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::LoadDir),
105-
FileSys::OpenMode::Read);
122+
VirtualFileOpenMode::Read);
106123
auto sd_load_directory = vfs.OpenDirectory(Common::FS::PathToUTF8String(sdmc_load_dir_path),
107-
FileSys::OpenMode::Read);
124+
VirtualFileOpenMode::Read);
108125
auto dump_directory =
109126
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::DumpDir), rw_mode);
110127

@@ -128,7 +145,7 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem & vfs, bool ov
128145
std::shared_ptr<FileSys::SaveDataFactory> FileSystemController::CreateSaveDataFactory(
129146
ProgramId program_id) {
130147
using YuzuPath = Common::FS::YuzuPath;
131-
const auto rw_mode = FileSys::OpenMode::ReadWrite;
148+
const auto rw_mode = VirtualFileOpenMode::ReadWrite;
132149

133150
auto vfs = loader.GetFilesystem();
134151
const auto nand_directory =

‎src/nxemu-loader/core/file_sys/filesystem.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ class FileSystemController :
3535
void CreateFactories(FileSys::VfsFilesystem & vfs, bool overwrite = true);
3636

3737
//IFileSystemController
38-
IFileSysRegisteredCache * GetSystemNANDContents() const;
39-
bool OpenProcess(uint64_t * programId, ISaveDataFactory ** saveDataFactory, IRomFsController** romFsController, uint64_t processId);
40-
bool OpenSDMC(IVirtualDirectory ** out_sdmc) const;
38+
IFileSysRegisteredCache * GetSystemNANDContents() const override;
39+
ISaveDataController * OpenSaveDataController() const override;
40+
uint64_t GetFreeSpaceSize(StorageId id) const override;
41+
uint64_t GetTotalSpaceSize(StorageId id) const override;
42+
bool OpenProcess(uint64_t * programId, ISaveDataFactory ** saveDataFactory, IRomFsController ** romFsController, uint64_t processId) override;
43+
bool OpenSDMC(IVirtualDirectory ** out_sdmc) const override;
4144

4245
private:
4346
std::shared_ptr<FileSys::SaveDataFactory> CreateSaveDataFactory(ProgramId program_id);

‎src/nxemu-loader/core/file_sys/fs_filesystem.h‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎src/nxemu-loader/core/file_sys/fs_save_data_types.h‎

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <fmt/format.h>
88
#include "yuzu_common/common_funcs.h"
99
#include "yuzu_common/common_types.h"
10+
#include <nxemu-module-spec/system_loader.h>
1011

1112
namespace FileSys {
1213

@@ -15,27 +16,6 @@ using SystemSaveDataId = u64;
1516
using SystemBcatSaveDataId = SystemSaveDataId;
1617
using ProgramId = u64;
1718

18-
enum class SaveDataSpaceId : u8 {
19-
System = 0,
20-
User = 1,
21-
SdSystem = 2,
22-
Temporary = 3,
23-
SdUser = 4,
24-
25-
ProperSystem = 100,
26-
SafeMode = 101,
27-
};
28-
29-
enum class SaveDataType : u8 {
30-
System = 0,
31-
Account = 1,
32-
Bcat = 2,
33-
Device = 3,
34-
Temporary = 4,
35-
Cache = 5,
36-
SystemBcat = 6,
37-
};
38-
3919
enum class SaveDataRank : u8 {
4020
Primary = 0,
4121
Secondary = 1,
@@ -91,64 +71,6 @@ static_assert(std::is_trivially_copyable_v<SaveDataCreationInfo>,
9171
"Data type must be trivially copyable.");
9272
static_assert(sizeof(SaveDataCreationInfo) == 0x40, "SaveDataCreationInfo has invalid size.");
9373

94-
struct SaveDataAttribute {
95-
ProgramId program_id;
96-
UserId user_id;
97-
SystemSaveDataId system_save_data_id;
98-
SaveDataType type;
99-
SaveDataRank rank;
100-
u16 index;
101-
INSERT_PADDING_BYTES(0x1C);
102-
103-
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id,
104-
SystemSaveDataId system_save_data_id, u16 index,
105-
SaveDataRank rank) {
106-
return {
107-
.program_id = program_id,
108-
.user_id = user_id,
109-
.system_save_data_id = system_save_data_id,
110-
.type = type,
111-
.rank = rank,
112-
.index = index,
113-
};
114-
}
115-
116-
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id,
117-
SystemSaveDataId system_save_data_id, u16 index) {
118-
return Make(program_id, type, user_id, system_save_data_id, index, SaveDataRank::Primary);
119-
}
120-
121-
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id,
122-
SystemSaveDataId system_save_data_id) {
123-
return Make(program_id, type, user_id, system_save_data_id, 0, SaveDataRank::Primary);
124-
}
125-
126-
std::string DebugInfo() const {
127-
return fmt::format(
128-
"[title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, type={:02X}, "
129-
"rank={}, index={}]",
130-
program_id, user_id[1], user_id[0], system_save_data_id, static_cast<u8>(type),
131-
static_cast<u8>(rank), index);
132-
}
133-
};
134-
static_assert(sizeof(SaveDataAttribute) == 0x40);
135-
static_assert(std::is_trivially_destructible<SaveDataAttribute>::value);
136-
137-
constexpr inline bool operator<(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) {
138-
return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.index, lhs.rank) <
139-
std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.index, rhs.rank);
140-
}
141-
142-
constexpr inline bool operator==(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) {
143-
return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.type, lhs.rank,
144-
lhs.index) == std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id,
145-
rhs.type, rhs.rank, rhs.index);
146-
}
147-
148-
constexpr inline bool operator!=(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) {
149-
return !(lhs == rhs);
150-
}
151-
15274
struct SaveDataExtraData {
15375
SaveDataAttribute attr;
15476
u64 owner_id;

‎src/nxemu-loader/core/file_sys/romfs_factory.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ namespace FileSys {
2424
class ContentProvider;
2525
class NCA;
2626

27-
enum class StorageId : u8 {
28-
None = 0,
29-
Host = 1,
30-
GameCard = 2,
31-
NandSystem = 3,
32-
NandUser = 4,
33-
SdCard = 5,
34-
};
35-
3627
/// File system interface to the RomFS archive
3728
class RomFSFactory {
3829
public:

‎src/nxemu-loader/core/file_sys/savedata_factory.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ SaveDataFactory::~SaveDataFactory() = default;
6464

6565
VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
6666
const auto save_directory = GetFullPath(program_id, dir, space, meta.type, meta.program_id,
67-
meta.user_id, meta.system_save_data_id);
67+
u128{ meta.user_id[0], meta.user_id[1] }, meta.system_save_data_id);
6868

6969
return dir->CreateDirectoryRelative(save_directory);
7070
}
7171

7272
VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
7373

7474
const auto save_directory = GetFullPath(program_id, dir, space, meta.type, meta.program_id,
75-
meta.user_id, meta.system_save_data_id);
75+
u128{ meta.user_id[0], meta.user_id[1] }, meta.system_save_data_id);
7676

7777
auto out = dir->GetDirectoryRelative(save_directory);
7878

@@ -201,6 +201,12 @@ SaveDataFactoryPtr::~SaveDataFactoryPtr()
201201
{
202202
}
203203

204+
IVirtualDirectory* SaveDataFactoryPtr::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const
205+
{
206+
UNIMPLEMENTED();
207+
return nullptr;
208+
}
209+
204210
void SaveDataFactoryPtr::Release()
205211
{
206212
delete this;

‎src/nxemu-loader/core/file_sys/savedata_factory.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SaveDataFactoryPtr :
6868
operator bool() const;
6969

7070
// ISaveDataFactory
71+
IVirtualDirectory * Open(SaveDataSpaceId space, const SaveDataAttribute & meta) const override;
7172
void Release() override;
7273

7374
private:

‎src/nxemu-loader/core/file_sys/vfs/vfs.cpp‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const {
3535
return VfsEntryType::None;
3636
}
3737

38-
VirtualFile VfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) {
38+
VirtualFile VfsFilesystem::OpenFile(std::string_view path_, VirtualFileOpenMode perms) {
3939
const auto path = Common::FS::SanitizePath(path_);
4040
return root->GetFileRelative(path);
4141
}
4242

43-
VirtualFile VfsFilesystem::CreateFile(std::string_view path_, OpenMode perms) {
43+
VirtualFile VfsFilesystem::CreateFile(std::string_view path_, VirtualFileOpenMode perms) {
4444
const auto path = Common::FS::SanitizePath(path_);
4545
return root->CreateFileRelative(path);
4646
}
@@ -53,17 +53,17 @@ VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view
5353
if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) {
5454
if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path)))
5555
return nullptr;
56-
return OpenFile(new_path, OpenMode::ReadWrite);
56+
return OpenFile(new_path, VirtualFileOpenMode::ReadWrite);
5757
}
5858

5959
// Do it using RawCopy. Non-default impls are encouraged to optimize this.
60-
const auto old_file = OpenFile(old_path, OpenMode::Read);
60+
const auto old_file = OpenFile(old_path, VirtualFileOpenMode::Read);
6161
if (old_file == nullptr)
6262
return nullptr;
63-
auto new_file = OpenFile(new_path, OpenMode::Read);
63+
auto new_file = OpenFile(new_path, VirtualFileOpenMode::Read);
6464
if (new_file != nullptr)
6565
return nullptr;
66-
new_file = CreateFile(new_path, OpenMode::Write);
66+
new_file = CreateFile(new_path, VirtualFileOpenMode::Write);
6767
if (new_file == nullptr)
6868
return nullptr;
6969
if (!VfsRawCopy(old_file, new_file))
@@ -86,18 +86,18 @@ VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view
8686

8787
bool VfsFilesystem::DeleteFile(std::string_view path_) {
8888
const auto path = Common::FS::SanitizePath(path_);
89-
auto parent = OpenDirectory(Common::FS::GetParentPath(path), OpenMode::Write);
89+
auto parent = OpenDirectory(Common::FS::GetParentPath(path), VirtualFileOpenMode::Write);
9090
if (parent == nullptr)
9191
return false;
9292
return parent->DeleteFile(Common::FS::GetFilename(path));
9393
}
9494

95-
VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, OpenMode perms) {
95+
VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, VirtualFileOpenMode perms) {
9696
const auto path = Common::FS::SanitizePath(path_);
9797
return root->GetDirectoryRelative(path);
9898
}
9999

100-
VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, OpenMode perms) {
100+
VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, VirtualFileOpenMode perms) {
101101
const auto path = Common::FS::SanitizePath(path_);
102102
return root->CreateDirectoryRelative(path);
103103
}
@@ -107,13 +107,13 @@ VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_
107107
const auto new_path = Common::FS::SanitizePath(new_path_);
108108

109109
// Non-default impls are highly encouraged to provide a more optimized version of this.
110-
auto old_dir = OpenDirectory(old_path, OpenMode::Read);
110+
auto old_dir = OpenDirectory(old_path, VirtualFileOpenMode::Read);
111111
if (old_dir == nullptr)
112112
return nullptr;
113-
auto new_dir = OpenDirectory(new_path, OpenMode::Read);
113+
auto new_dir = OpenDirectory(new_path, VirtualFileOpenMode::Read);
114114
if (new_dir != nullptr)
115115
return nullptr;
116-
new_dir = CreateDirectory(new_path, OpenMode::Write);
116+
new_dir = CreateDirectory(new_path, VirtualFileOpenMode::Write);
117117
if (new_dir == nullptr)
118118
return nullptr;
119119

@@ -148,7 +148,7 @@ VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_v
148148

149149
bool VfsFilesystem::DeleteDirectory(std::string_view path_) {
150150
const auto path = Common::FS::SanitizePath(path_);
151-
auto parent = OpenDirectory(Common::FS::GetParentPath(path), OpenMode::Write);
151+
auto parent = OpenDirectory(Common::FS::GetParentPath(path), VirtualFileOpenMode::Write);
152152
if (parent == nullptr)
153153
return false;
154154
return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path));

‎src/nxemu-loader/core/file_sys/vfs/vfs.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "yuzu_common/common_funcs.h"
1515
#include "yuzu_common/common_types.h"
16-
#include "core/file_sys/fs_filesystem.h"
1716
#include "core/file_sys/vfs/vfs_types.h"
1817

1918
namespace FileSys {
@@ -48,9 +47,9 @@ class VfsFilesystem {
4847
virtual VfsEntryType GetEntryType(std::string_view path) const;
4948

5049
// Opens the file with path relative to root. If it doesn't exist, returns nullptr.
51-
virtual VirtualFile OpenFile(std::string_view path, OpenMode perms);
50+
virtual VirtualFile OpenFile(std::string_view path, VirtualFileOpenMode perms);
5251
// Creates a new, empty file at path
53-
virtual VirtualFile CreateFile(std::string_view path, OpenMode perms);
52+
virtual VirtualFile CreateFile(std::string_view path, VirtualFileOpenMode perms);
5453
// Copies the file from old_path to new_path, returning the new file on success and nullptr on
5554
// failure.
5655
virtual VirtualFile CopyFile(std::string_view old_path, std::string_view new_path);
@@ -61,9 +60,9 @@ class VfsFilesystem {
6160
virtual bool DeleteFile(std::string_view path);
6261

6362
// Opens the directory with path relative to root. If it doesn't exist, returns nullptr.
64-
virtual VirtualDir OpenDirectory(std::string_view path, OpenMode perms);
63+
virtual VirtualDir OpenDirectory(std::string_view path, VirtualFileOpenMode perms);
6564
// Creates a new, empty directory at path
66-
virtual VirtualDir CreateDirectory(std::string_view path, OpenMode perms);
65+
virtual VirtualDir CreateDirectory(std::string_view path, VirtualFileOpenMode perms);
6766
// Copies the directory from old_path to new_path, returning the new directory on success and
6867
// nullptr on failure.
6968
virtual VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path);

0 commit comments

Comments
 (0)