Jump to content

[Filesystem] folder list inside archive


photo

Recommended Posts

Hello,

I'm trying via filesystem api  to list all folder inside a folder ( non recursively ).

The code belove work when you list folder from a normal directory but, doesn't work on folder who are compressed.

std::vector<std::string> NQ::get_folder_list(const std::string& inDir)
{	
    std::vector<std::string> dirs;
  
    auto dir = Unigine::Dir::create();
    if (dir->open(inDir.c_str()))
    {
        int dirCount = dir->getNumDirs();
        for (int i = 0; i < dirCount; i++)
        {
            auto dirName = std::string(dir->getDirName(i));
            dirName.pop_back(); // remove last slash
  
            dirs.push_back(dirName);
  		}
	}
 }

Any clue ? 

Thanks.

Link to comment

Hi jmasclaux,

Unfortunately, Unigine::Dir only provides access to plain system directories and can't help in traversing compressed packages.
There are Unigine::FileSystem::*Package*() methods for inspecting *.zip and *.ung archives under the data path.
You can find example of traversing system catalogs along with the compressed packages in the data/samples/samples.cpp file in your SDK.
This is a master script that displays a menu enlisting all available UnigineScript samples in the SDK.

Link to comment

Hi 

I was pretty sure i'm gonna get this answer :) 

here i'm take this small part from another tread to get file list 

        // find package num
        int package_num = -1;
        for (int i = 0; i < Unigine::FileSystem::get()->getNumPackages(); i++)
        {
            NQ_INFO(GAME, "%1 == %2", packageName, Unigine::FileSystem::get()->getPackageName(i));
            if (packageName == Unigine::FileSystem::get()->getPackageName(i))
            {
                package_num = i;
                break;
            }
        }

        Unigine::Vector<Unigine::String> files;
        Unigine::FileSystem::get()->getPackageFileNames(package_num, files);

and it's work.

But before I made this code with normally the same result : 

        auto package = Unigine::FileSystem::get()->getPackage(packageName.c_str());
        if (package)
        {
            for(int i = 0; i < package->getNumFiles(); i++)
                dirs.push_back(package->getFileName(i));
        }

and it does not work.

I was thinking i'm not using the good filename so I wrote 

        auto packageT = Unigine::FileSystem::get()->getPackage(Unigine::FileSystem::get()->getPackageName(package_num));
        if (packageT)
        {
            for (int i = 0; i < packageT->getNumFiles(); i++)
                dirs.push_back(packageT->getFileName(i));
        }

And it does not work too.

I miss something ? 

PS at the start of the function I made :

Unigine::FileSystem::get()->loadPackage(packageName.c_str())

I'm on unigine 2.3.

 

Thank's

Edited by jmasclaux
Link to comment

Aside from the packages that Unigine file system load automatically, you can manage an additional list of packages.
They are actually loaded upon file system initialization or "filesystem_reload" command, but the list can be manipulated at any time.
Unigine::FileSystem::getPackage and Unigine::FileSystem::addPackage (both are static methods) are related to this additional list.

Naming is a bit confusing, I agree.
In the engine source code these are referred as "extern packages".
I don't know why they had lost "extern" qualifier in their API naming, perhaps we should fix this.

What you need is Unigine::FileSystem::findPackage, it basically does the same thing as your first code snippet.

Link to comment
×
×
  • Create New...