mirror of
				https://github.com/edubart/otclient.git
				synced 2025-11-03 20:26:23 +01:00 
			
		
		
		
	Introduce g_resources.getDirectoryFiles
This can recursively find files in a directory that's not in physfs search path, this is needed for mapeditor needs, esp the file browser. We do not want to limit users to the application run directory so we have to use this. This function uses boost filesystem. Prototype: g_resources.getDirectoryFiles(directory STRING, filenameOnly BOOL, recursive BOOL) filenameOnly is there if we want to just get the filenames in the directory. recursive if we want to loop directories in the directory.
This commit is contained in:
		@@ -271,6 +271,37 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
 | 
			
		||||
    return files;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> ResourceManager::getDirectoryFiles(const std::string& path, bool filenameOnly, bool recursive)
 | 
			
		||||
{
 | 
			
		||||
    if(!fs::exists(path))
 | 
			
		||||
        return std::vector<std::string>();
 | 
			
		||||
 | 
			
		||||
    fs::path p(path);
 | 
			
		||||
    return discoverPath(p, filenameOnly, recursive);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> ResourceManager::discoverPath(const fs::path& path, bool filenameOnly, bool recursive)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> files;
 | 
			
		||||
 | 
			
		||||
    /* Before doing anything, we have to add this directory to search path,
 | 
			
		||||
     * this is needed so it works correctly when one wants to open a file.  */
 | 
			
		||||
    addSearchPath(path.generic_string(), true);
 | 
			
		||||
    for (fs::directory_iterator it(path), end; it != end; ++it) {
 | 
			
		||||
        if(fs::is_directory(it->path().generic_string()) && recursive) {
 | 
			
		||||
            std::vector<std::string> subfiles = discoverPath(it->path(), filenameOnly, recursive);
 | 
			
		||||
            files.insert(files.end(), subfiles.begin(), subfiles.end());
 | 
			
		||||
        } else {
 | 
			
		||||
            if(filenameOnly)
 | 
			
		||||
                files.push_back(it->path().filename().string());
 | 
			
		||||
            else
 | 
			
		||||
                files.push_back(it->path().generic_string() + "/" + it->path().filename().string());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return files;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string ResourceManager::resolvePath(const std::string& path)
 | 
			
		||||
{
 | 
			
		||||
    std::string fullPath;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user