reepblue Posted February 5, 2023 Share Posted February 5, 2023 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 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted February 5, 2023 Share Posted February 5, 2023 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. 1 Quote 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 More sharing options...
reepblue Posted February 5, 2023 Author Share Posted February 5, 2023 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted February 5, 2023 Share Posted February 5, 2023 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. 1 Quote 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 More sharing options...
Solution Josh Posted March 4, 2023 Solution Share Posted March 4, 2023 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). 1 Quote 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 More sharing options...
reepblue Posted March 4, 2023 Author Share Posted March 4, 2023 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted March 5, 2023 Share Posted March 5, 2023 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; } } } 1 Quote 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 More sharing options...
Recommended Posts
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.