Merge yuzu-emu#13177
This commit is contained in:
parent
9629bb61d3
commit
431dc2a5fc
|
@ -9,9 +9,8 @@
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
OffsetVfsFile::OffsetVfsFile(VirtualFile file_, std::size_t size_, std::size_t offset_,
|
OffsetVfsFile::OffsetVfsFile(VirtualFile file_, std::size_t size_, std::size_t offset_,
|
||||||
std::string name_, VirtualDir parent_)
|
std::string name_)
|
||||||
: file(file_), offset(offset_), size(size_), name(std::move(name_)),
|
: file(file_), offset(offset_), size(size_), name(std::move(name_)) {}
|
||||||
parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {}
|
|
||||||
|
|
||||||
OffsetVfsFile::~OffsetVfsFile() = default;
|
OffsetVfsFile::~OffsetVfsFile() = default;
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ bool OffsetVfsFile::Resize(std::size_t new_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir OffsetVfsFile::GetContainingDirectory() const {
|
VirtualDir OffsetVfsFile::GetContainingDirectory() const {
|
||||||
return parent;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OffsetVfsFile::IsWritable() const {
|
bool OffsetVfsFile::IsWritable() const {
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace FileSys {
|
||||||
class OffsetVfsFile : public VfsFile {
|
class OffsetVfsFile : public VfsFile {
|
||||||
public:
|
public:
|
||||||
OffsetVfsFile(VirtualFile file, std::size_t size, std::size_t offset = 0,
|
OffsetVfsFile(VirtualFile file, std::size_t size, std::size_t offset = 0,
|
||||||
std::string new_name = "", VirtualDir new_parent = nullptr);
|
std::string new_name = "");
|
||||||
~OffsetVfsFile() override;
|
~OffsetVfsFile() override;
|
||||||
|
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
|
@ -44,7 +44,6 @@ private:
|
||||||
std::size_t offset;
|
std::size_t offset;
|
||||||
std::size_t size;
|
std::size_t size;
|
||||||
std::string name;
|
std::string name;
|
||||||
VirtualDir parent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
|
|
@ -76,6 +76,7 @@ VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::optional<u64> size,
|
VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::optional<u64> size,
|
||||||
|
std::optional<std::string> parent_path,
|
||||||
OpenMode perms) {
|
OpenMode perms) {
|
||||||
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
std::scoped_lock lk{list_lock};
|
std::scoped_lock lk{list_lock};
|
||||||
|
@ -94,14 +95,14 @@ VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::op
|
||||||
this->InsertReferenceIntoListLocked(*reference);
|
this->InsertReferenceIntoListLocked(*reference);
|
||||||
|
|
||||||
auto file = std::shared_ptr<RealVfsFile>(
|
auto file = std::shared_ptr<RealVfsFile>(
|
||||||
new RealVfsFile(*this, std::move(reference), path, perms, size));
|
new RealVfsFile(*this, std::move(reference), path, perms, size, std::move(parent_path)));
|
||||||
cache[path] = file;
|
cache[path] = file;
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) {
|
VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) {
|
||||||
return OpenFileFromEntry(path_, {}, perms);
|
return OpenFileFromEntry(path_, {}, {}, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, OpenMode perms) {
|
VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, OpenMode perms) {
|
||||||
|
@ -268,10 +269,11 @@ void RealVfsFilesystem::RemoveReferenceFromListLocked(FileReference& reference)
|
||||||
}
|
}
|
||||||
|
|
||||||
RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_,
|
RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_,
|
||||||
const std::string& path_, OpenMode perms_, std::optional<u64> size_)
|
const std::string& path_, OpenMode perms_, std::optional<u64> size_,
|
||||||
|
std::optional<std::string> parent_path_)
|
||||||
: base(base_), reference(std::move(reference_)), path(path_),
|
: base(base_), reference(std::move(reference_)), path(path_),
|
||||||
parent_path(FS::GetParentPath(path_)), path_components(FS::SplitPathComponentsCopy(path_)),
|
parent_path(parent_path_ ? std::move(*parent_path_) : FS::GetParentPath(path_)),
|
||||||
size(size_), perms(perms_) {}
|
path_components(FS::SplitPathComponentsCopy(path_)), size(size_), perms(perms_) {}
|
||||||
|
|
||||||
RealVfsFile::~RealVfsFile() {
|
RealVfsFile::~RealVfsFile() {
|
||||||
base.DropReference(std::move(reference));
|
base.DropReference(std::move(reference));
|
||||||
|
@ -348,7 +350,7 @@ std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>(
|
||||||
&out](const std::filesystem::directory_entry& entry) {
|
&out](const std::filesystem::directory_entry& entry) {
|
||||||
const auto full_path_string = FS::PathToUTF8String(entry.path());
|
const auto full_path_string = FS::PathToUTF8String(entry.path());
|
||||||
|
|
||||||
out.emplace_back(base.OpenFileFromEntry(full_path_string, entry.file_size(), perms));
|
out.emplace_back(base.OpenFileFromEntry(full_path_string, entry.file_size(), path, perms));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,6 +62,7 @@ private:
|
||||||
private:
|
private:
|
||||||
friend class RealVfsDirectory;
|
friend class RealVfsDirectory;
|
||||||
VirtualFile OpenFileFromEntry(std::string_view path, std::optional<u64> size,
|
VirtualFile OpenFileFromEntry(std::string_view path, std::optional<u64> size,
|
||||||
|
std::optional<std::string> parent_path,
|
||||||
OpenMode perms = OpenMode::Read);
|
OpenMode perms = OpenMode::Read);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -91,7 +92,7 @@ public:
|
||||||
private:
|
private:
|
||||||
RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference,
|
RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference,
|
||||||
const std::string& path, OpenMode perms = OpenMode::Read,
|
const std::string& path, OpenMode perms = OpenMode::Read,
|
||||||
std::optional<u64> size = {});
|
std::optional<u64> size = {}, std::optional<std::string> parent_path = {});
|
||||||
|
|
||||||
RealVfsFilesystem& base;
|
RealVfsFilesystem& base;
|
||||||
std::unique_ptr<FileReference> reference;
|
std::unique_ptr<FileReference> reference;
|
||||||
|
|
|
@ -36,22 +36,23 @@ std::optional<FileType> IdentifyFileLoader(FileSys::VirtualFile file) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FileType IdentifyFile(FileSys::VirtualFile file) {
|
FileType IdentifyFile(FileSys::VirtualFile file) {
|
||||||
if (const auto romdir_type = IdentifyFileLoader<AppLoader_DeconstructedRomDirectory>(file)) {
|
if (const auto nsp_type = IdentifyFileLoader<AppLoader_NSP>(file)) {
|
||||||
return *romdir_type;
|
return *nsp_type;
|
||||||
} else if (const auto nso_type = IdentifyFileLoader<AppLoader_NSO>(file)) {
|
} else if (const auto xci_type = IdentifyFileLoader<AppLoader_XCI>(file)) {
|
||||||
return *nso_type;
|
return *xci_type;
|
||||||
} else if (const auto nro_type = IdentifyFileLoader<AppLoader_NRO>(file)) {
|
} else if (const auto nro_type = IdentifyFileLoader<AppLoader_NRO>(file)) {
|
||||||
return *nro_type;
|
return *nro_type;
|
||||||
} else if (const auto nca_type = IdentifyFileLoader<AppLoader_NCA>(file)) {
|
} else if (const auto nca_type = IdentifyFileLoader<AppLoader_NCA>(file)) {
|
||||||
return *nca_type;
|
return *nca_type;
|
||||||
} else if (const auto xci_type = IdentifyFileLoader<AppLoader_XCI>(file)) {
|
|
||||||
return *xci_type;
|
|
||||||
} else if (const auto nax_type = IdentifyFileLoader<AppLoader_NAX>(file)) {
|
} else if (const auto nax_type = IdentifyFileLoader<AppLoader_NAX>(file)) {
|
||||||
return *nax_type;
|
return *nax_type;
|
||||||
} else if (const auto nsp_type = IdentifyFileLoader<AppLoader_NSP>(file)) {
|
|
||||||
return *nsp_type;
|
|
||||||
} else if (const auto kip_type = IdentifyFileLoader<AppLoader_KIP>(file)) {
|
} else if (const auto kip_type = IdentifyFileLoader<AppLoader_KIP>(file)) {
|
||||||
return *kip_type;
|
return *kip_type;
|
||||||
|
} else if (const auto nso_type = IdentifyFileLoader<AppLoader_NSO>(file)) {
|
||||||
|
return *nso_type;
|
||||||
|
} else if (const auto romdir_type =
|
||||||
|
IdentifyFileLoader<AppLoader_DeconstructedRomDirectory>(file)) {
|
||||||
|
return *romdir_type;
|
||||||
} else {
|
} else {
|
||||||
return FileType::Unknown;
|
return FileType::Unknown;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue