Jump to content

Package::LoadDir is always empty.


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

This example demonstrates Package::LoadDir isn't working as expected. This makes it impossible to load or index any files within a package.

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Load packages
    auto pkg = LoadPackage("defaultmeshface.zip");

    auto files = pkg->LoadDir("./");
    if (files.empty()) Print("Package is empty!");

    for (const auto& p : files)
    {
        Print(p);
    }

    return 0;
}

Test Zip included:

defaultmeshface.zip

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Okay, this is not implemented yet, and not documented, although you can clearly see what I had in mind. I've been hesitating on this because ZIP files don't actually store a folder hierarchy, they just store a flat list of file paths. So the folder structure would have to be calculated at the time the package is loaded. I wasn't 100% sure this is how I wanted it to work, but it's probably for the best to do it that way.

 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Is the packaging system more tolerate to what files can actually load with ReadFile this time? My method is to preload all packages and load any unsupported extensions there. I used something like this in Cyclone when loading json files from packages since Leadwerks didn't support loading that file format with its Stream Class. 

I kind of wish I didn't have to worry about what was in a package and all files handle same way. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

It will work fine. The reason Leadwerks did not allow reading streams from zip files is because they were encrypted with a special algorithm. If I allowed the engine to read a stream from one of those archives, then it could load any game's contents. The system was never cracked.

In Ultra since you assign the password yourself, it's fine to read streams from zips. I don't have a solution for how Lua scripts could encrypt zip files because the password would have to be stored in a script, which makes password protection pointless. I'm not going to worry about that too much right now though.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 4 weeks later...
  • Solution

Fixed in 1.0.2.

Currently you will need to just use "" to indicate the current path, not using any dots. (RealPath does evaluate . and .. correctly, but it also turs the path into a full path, which you don't want for a package file).

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Would it be possible for a recursive override? I'm trying to locate every wav file within the package and add it to a list. I can only get a list of files and folders in that directory only.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

What you want to do is call Package::FileType() and when a folder is encountered, call the function again recursively. Something like this:

void LoadFiles(shared_ptr<Package> pak, const WString& path, std::vector<WString>& files)
{
	auto dir = pak->LoadDir(path);
	for (const auto& file : dir)
	{
		auto filepath = path;
		if (not filepath.empty()) filepath += L"/";
		filepath += file;
		switch (pak->FileType(filepath))
		{
		case 1:
			if (ExtractExt(file).Lower() == "wav") files.push_back(filepath);
			break;
		case 2:
			LoadFiles(pak, filepath, files);
			break;
		}
	}
}

 

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...