mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Merge pull request #260 from archshift/opendir
Make OpenDirectory fail if the directory doesn't exist
This commit is contained in:
		
						commit
						72ad73519c
					
				
					 7 changed files with 40 additions and 3 deletions
				
			
		|  | @ -100,6 +100,8 @@ bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys: | |||
| std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const { | ||||
|     DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str()); | ||||
|     Directory_SDMC* directory = new Directory_SDMC(this, path); | ||||
|     if (!directory->Open()) | ||||
|         return nullptr; | ||||
|     return std::unique_ptr<Directory>(directory); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -41,6 +41,12 @@ public: | |||
|     Directory() { } | ||||
|     virtual ~Directory() { } | ||||
| 
 | ||||
|     /**
 | ||||
|     * Open the directory | ||||
|     * @return true if the directory opened correctly | ||||
|     */ | ||||
|     virtual bool Open() = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * List files contained in the directory | ||||
|      * @param count Number of entries to return at once in entries | ||||
|  |  | |||
|  | @ -17,6 +17,10 @@ Directory_RomFS::Directory_RomFS() { | |||
| Directory_RomFS::~Directory_RomFS() { | ||||
| } | ||||
| 
 | ||||
| bool Directory_RomFS::Open() { | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * List files contained in the directory | ||||
|  * @param count Number of entries to return at once in entries | ||||
|  |  | |||
|  | @ -19,6 +19,12 @@ public: | |||
|     Directory_RomFS(); | ||||
|     ~Directory_RomFS() override; | ||||
| 
 | ||||
|     /**
 | ||||
|     * Open the directory | ||||
|     * @return true if the directory opened correctly | ||||
|     */ | ||||
|     bool Open() override; | ||||
| 
 | ||||
|     /**
 | ||||
|      * List files contained in the directory | ||||
|      * @param count Number of entries to return at once in entries | ||||
|  |  | |||
|  | @ -19,15 +19,22 @@ Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) { | |||
|     // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
 | ||||
|     // the root directory we set while opening the archive.
 | ||||
|     // For example, opening /../../usr/bin can give the emulated program your installed programs.
 | ||||
|     std::string absolute_path = archive->GetMountPoint() + path.AsString(); | ||||
|     FileUtil::ScanDirectoryTree(absolute_path, directory); | ||||
|     children_iterator = directory.children.begin(); | ||||
|     this->path = archive->GetMountPoint() + path.AsString(); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| Directory_SDMC::~Directory_SDMC() { | ||||
|     Close(); | ||||
| } | ||||
| 
 | ||||
| bool Directory_SDMC::Open() { | ||||
|     if (!FileUtil::IsDirectory(path)) | ||||
|         return false; | ||||
|     FileUtil::ScanDirectoryTree(path, directory); | ||||
|     children_iterator = directory.children.begin(); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * List files contained in the directory | ||||
|  * @param count Number of entries to return at once in entries | ||||
|  |  | |||
|  | @ -22,6 +22,12 @@ public: | |||
|     Directory_SDMC(const Archive_SDMC* archive, const Path& path); | ||||
|     ~Directory_SDMC() override; | ||||
| 
 | ||||
|     /**
 | ||||
|     * Open the directory | ||||
|     * @return true if the directory opened correctly | ||||
|     */ | ||||
|     bool Open() override; | ||||
| 
 | ||||
|     /**
 | ||||
|      * List files contained in the directory | ||||
|      * @param count Number of entries to return at once in entries | ||||
|  | @ -37,6 +43,7 @@ public: | |||
|     bool Close() const override; | ||||
| 
 | ||||
| private: | ||||
|     std::string path; | ||||
|     u32 total_entries_in_directory; | ||||
|     FileUtil::FSTEntry directory; | ||||
| 
 | ||||
|  |  | |||
|  | @ -421,6 +421,11 @@ ResultVal<Handle> OpenDirectoryFromArchive(Handle archive_handle, const FileSys: | |||
|     directory->path = path; | ||||
|     directory->backend = archive->backend->OpenDirectory(path); | ||||
| 
 | ||||
|     if (!directory->backend) { | ||||
|         return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, | ||||
|                           ErrorSummary::NotFound, ErrorLevel::Permanent); | ||||
|     } | ||||
| 
 | ||||
|     return MakeResult<Handle>(handle); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue