mirror of
				https://git.zaroz.cloud/nintendo-back-up/yuzu/yuzu-mainline.git
				synced 2025-03-21 01:53:15 +00:00 
			
		
		
		
	vfs: Add GetEntries method
Maps name string to directory or file.
This commit is contained in:
		
							parent
							
								
									bd8db3f7f8
								
							
						
					
					
						commit
						d6cbb3a3e0
					
				@ -399,6 +399,15 @@ bool VfsDirectory::Copy(std::string_view src, std::string_view dest) {
 | 
				
			|||||||
    return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize();
 | 
					    return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::map<std::string, VfsEntryType> VfsDirectory::GetEntries() const {
 | 
				
			||||||
 | 
					    std::map<std::string, VfsEntryType> out;
 | 
				
			||||||
 | 
					    for (const auto& dir : GetSubdirectories())
 | 
				
			||||||
 | 
					        out.emplace(dir->GetName(), VfsEntryType::Directory);
 | 
				
			||||||
 | 
					    for (const auto& file : GetFiles())
 | 
				
			||||||
 | 
					        out.emplace(file->GetName(), VfsEntryType::File);
 | 
				
			||||||
 | 
					    return out;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string VfsDirectory::GetFullPath() const {
 | 
					std::string VfsDirectory::GetFullPath() const {
 | 
				
			||||||
    if (IsRoot())
 | 
					    if (IsRoot())
 | 
				
			||||||
        return GetName();
 | 
					        return GetName();
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <string_view>
 | 
					#include <string_view>
 | 
				
			||||||
@ -265,6 +266,10 @@ public:
 | 
				
			|||||||
    // dest.
 | 
					    // dest.
 | 
				
			||||||
    virtual bool Copy(std::string_view src, std::string_view dest);
 | 
					    virtual bool Copy(std::string_view src, std::string_view dest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Gets all of the entries directly in the directory (files and dirs), returning a map between
 | 
				
			||||||
 | 
					    // item name -> type.
 | 
				
			||||||
 | 
					    virtual std::map<std::string, VfsEntryType> GetEntries() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Interprets the file with name file instead as a directory of type directory.
 | 
					    // Interprets the file with name file instead as a directory of type directory.
 | 
				
			||||||
    // The directory must have a constructor that takes a single argument of type
 | 
					    // The directory must have a constructor that takes a single argument of type
 | 
				
			||||||
    // std::shared_ptr<VfsFile>. Allows to reinterpret container files (i.e NCA, zip, XCI, etc) as a
 | 
					    // std::shared_ptr<VfsFile>. Allows to reinterpret container files (i.e NCA, zip, XCI, etc) as a
 | 
				
			||||||
 | 
				
			|||||||
@ -413,6 +413,23 @@ std::string RealVfsDirectory::GetFullPath() const {
 | 
				
			|||||||
    return out;
 | 
					    return out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::map<std::string, VfsEntryType> RealVfsDirectory::GetEntries() const {
 | 
				
			||||||
 | 
					    if (perms == Mode::Append)
 | 
				
			||||||
 | 
					        return {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::map<std::string, VfsEntryType> out;
 | 
				
			||||||
 | 
					    FileUtil::ForeachDirectoryEntry(
 | 
				
			||||||
 | 
					        nullptr, path,
 | 
				
			||||||
 | 
					        [&out](u64* entries_out, const std::string& directory, const std::string& filename) {
 | 
				
			||||||
 | 
					            const std::string full_path = directory + DIR_SEP + filename;
 | 
				
			||||||
 | 
					            out.emplace(filename, FileUtil::IsDirectory(full_path) ? VfsEntryType::Directory
 | 
				
			||||||
 | 
					                                                                   : VfsEntryType::File);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return out;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
 | 
					bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -98,6 +98,7 @@ public:
 | 
				
			|||||||
    bool DeleteFile(std::string_view name) override;
 | 
					    bool DeleteFile(std::string_view name) override;
 | 
				
			||||||
    bool Rename(std::string_view name) override;
 | 
					    bool Rename(std::string_view name) override;
 | 
				
			||||||
    std::string GetFullPath() const override;
 | 
					    std::string GetFullPath() const override;
 | 
				
			||||||
 | 
					    std::map<std::string, VfsEntryType> GetEntries() const override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
    bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override;
 | 
					    bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user