forked from suyu/suyu
filesystem: Open a read-only directory for SDMC mods
This prevents mod files from being locked due to the read-only share flag in Windows.
This commit is contained in:
parent
844e0114b0
commit
6ac978426c
3 changed files with 25 additions and 19 deletions
|
@ -12,19 +12,20 @@ namespace FileSys {
|
||||||
|
|
||||||
constexpr u64 SDMC_TOTAL_SIZE = 0x10000000000; // 1 TiB
|
constexpr u64 SDMC_TOTAL_SIZE = 0x10000000000; // 1 TiB
|
||||||
|
|
||||||
SDMCFactory::SDMCFactory(VirtualDir dir_)
|
SDMCFactory::SDMCFactory(VirtualDir sd_dir_, VirtualDir sd_mod_dir_)
|
||||||
: dir(std::move(dir_)), contents(std::make_unique<RegisteredCache>(
|
: sd_dir(std::move(sd_dir_)), sd_mod_dir(std::move(sd_mod_dir_)),
|
||||||
GetOrCreateDirectoryRelative(dir, "/Nintendo/Contents/registered"),
|
contents(std::make_unique<RegisteredCache>(
|
||||||
[](const VirtualFile& file, const NcaID& id) {
|
GetOrCreateDirectoryRelative(sd_dir, "/Nintendo/Contents/registered"),
|
||||||
return NAX{file, id}.GetDecrypted();
|
[](const VirtualFile& file, const NcaID& id) {
|
||||||
})),
|
return NAX{file, id}.GetDecrypted();
|
||||||
|
})),
|
||||||
placeholder(std::make_unique<PlaceholderCache>(
|
placeholder(std::make_unique<PlaceholderCache>(
|
||||||
GetOrCreateDirectoryRelative(dir, "/Nintendo/Contents/placehld"))) {}
|
GetOrCreateDirectoryRelative(sd_dir, "/Nintendo/Contents/placehld"))) {}
|
||||||
|
|
||||||
SDMCFactory::~SDMCFactory() = default;
|
SDMCFactory::~SDMCFactory() = default;
|
||||||
|
|
||||||
ResultVal<VirtualDir> SDMCFactory::Open() const {
|
ResultVal<VirtualDir> SDMCFactory::Open() const {
|
||||||
return MakeResult<VirtualDir>(dir);
|
return MakeResult<VirtualDir>(sd_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir SDMCFactory::GetSDMCModificationLoadRoot(u64 title_id) const {
|
VirtualDir SDMCFactory::GetSDMCModificationLoadRoot(u64 title_id) const {
|
||||||
|
@ -32,11 +33,11 @@ VirtualDir SDMCFactory::GetSDMCModificationLoadRoot(u64 title_id) const {
|
||||||
if (title_id == 0 || (title_id & 0xFFF) == 0x800) {
|
if (title_id == 0 || (title_id & 0xFFF) == 0x800) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return GetOrCreateDirectoryRelative(dir, fmt::format("/atmosphere/contents/{:016X}", title_id));
|
return GetOrCreateDirectoryRelative(sd_mod_dir, fmt::format("/{:016X}", title_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir SDMCFactory::GetSDMCContentDirectory() const {
|
VirtualDir SDMCFactory::GetSDMCContentDirectory() const {
|
||||||
return GetOrCreateDirectoryRelative(dir, "/Nintendo/Contents");
|
return GetOrCreateDirectoryRelative(sd_dir, "/Nintendo/Contents");
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredCache* SDMCFactory::GetSDMCContents() const {
|
RegisteredCache* SDMCFactory::GetSDMCContents() const {
|
||||||
|
@ -48,11 +49,11 @@ PlaceholderCache* SDMCFactory::GetSDMCPlaceholder() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir SDMCFactory::GetImageDirectory() const {
|
VirtualDir SDMCFactory::GetImageDirectory() const {
|
||||||
return GetOrCreateDirectoryRelative(dir, "/Nintendo/Album");
|
return GetOrCreateDirectoryRelative(sd_dir, "/Nintendo/Album");
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 SDMCFactory::GetSDMCFreeSpace() const {
|
u64 SDMCFactory::GetSDMCFreeSpace() const {
|
||||||
return GetSDMCTotalSpace() - dir->GetSize();
|
return GetSDMCTotalSpace() - sd_dir->GetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 SDMCFactory::GetSDMCTotalSpace() const {
|
u64 SDMCFactory::GetSDMCTotalSpace() const {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class PlaceholderCache;
|
||||||
/// File system interface to the SDCard archive
|
/// File system interface to the SDCard archive
|
||||||
class SDMCFactory {
|
class SDMCFactory {
|
||||||
public:
|
public:
|
||||||
explicit SDMCFactory(VirtualDir dir);
|
explicit SDMCFactory(VirtualDir sd_dir_, VirtualDir sd_mod_dir_);
|
||||||
~SDMCFactory();
|
~SDMCFactory();
|
||||||
|
|
||||||
ResultVal<VirtualDir> Open() const;
|
ResultVal<VirtualDir> Open() const;
|
||||||
|
@ -33,7 +33,8 @@ public:
|
||||||
u64 GetSDMCTotalSpace() const;
|
u64 GetSDMCTotalSpace() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VirtualDir dir;
|
VirtualDir sd_dir;
|
||||||
|
VirtualDir sd_mod_dir;
|
||||||
|
|
||||||
std::unique_ptr<RegisteredCache> contents;
|
std::unique_ptr<RegisteredCache> contents;
|
||||||
std::unique_ptr<PlaceholderCache> placeholder;
|
std::unique_ptr<PlaceholderCache> placeholder;
|
||||||
|
|
|
@ -743,20 +743,23 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
|
||||||
}
|
}
|
||||||
|
|
||||||
using YuzuPath = Common::FS::YuzuPath;
|
using YuzuPath = Common::FS::YuzuPath;
|
||||||
|
const auto sdmc_dir_path = Common::FS::GetYuzuPath(YuzuPath::SDMCDir);
|
||||||
|
const auto sdmc_load_dir_path = sdmc_dir_path / "atmosphere/contents";
|
||||||
const auto rw_mode = FileSys::Mode::ReadWrite;
|
const auto rw_mode = FileSys::Mode::ReadWrite;
|
||||||
|
|
||||||
auto nand_directory =
|
auto nand_directory =
|
||||||
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::NANDDir), rw_mode);
|
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::NANDDir), rw_mode);
|
||||||
auto sd_directory =
|
auto sd_directory = vfs.OpenDirectory(Common::FS::PathToUTF8String(sdmc_dir_path), rw_mode);
|
||||||
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::SDMCDir), rw_mode);
|
|
||||||
auto load_directory =
|
auto load_directory =
|
||||||
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::LoadDir), FileSys::Mode::Read);
|
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::LoadDir), FileSys::Mode::Read);
|
||||||
|
auto sd_load_directory =
|
||||||
|
vfs.OpenDirectory(Common::FS::PathToUTF8String(sdmc_load_dir_path), FileSys::Mode::Read);
|
||||||
auto dump_directory =
|
auto dump_directory =
|
||||||
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::DumpDir), rw_mode);
|
vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::DumpDir), rw_mode);
|
||||||
|
|
||||||
if (bis_factory == nullptr) {
|
if (bis_factory == nullptr) {
|
||||||
bis_factory =
|
bis_factory = std::make_unique<FileSys::BISFactory>(
|
||||||
std::make_unique<FileSys::BISFactory>(nand_directory, load_directory, dump_directory);
|
nand_directory, std::move(load_directory), std::move(dump_directory));
|
||||||
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SysNAND,
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SysNAND,
|
||||||
bis_factory->GetSystemNANDContents());
|
bis_factory->GetSystemNANDContents());
|
||||||
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::UserNAND,
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::UserNAND,
|
||||||
|
@ -769,7 +772,8 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdmc_factory == nullptr) {
|
if (sdmc_factory == nullptr) {
|
||||||
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory));
|
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory),
|
||||||
|
std::move(sd_load_directory));
|
||||||
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SDMC,
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SDMC,
|
||||||
sdmc_factory->GetSDMCContents());
|
sdmc_factory->GetSDMCContents());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue