Jump to content

A way to read Leadwerks data files?


reepblue
 Share

Recommended Posts

I've noticed that by default the engine creates a settings file and saves it to the AppPath. The issue is that there is really no clear documentation about how to read or write keyvalues in a stream. So I just used PugiXML for settings instead.

 

Now I'm faced with this issue again. I want to get a custom value in a material file, but I want to check if it's there. and read the value after the equal symbol. I've spent the last few hours looking at the FileSystem/Stream classes. I'd hope there was a ReadKey() function. The only thing I saw that looked like what I was looking for is:

 


Stream* ReadFile(const std::string& path, uint64_t fileid, const std::string key);

 

But I have no idea how I'd set up the fileid. Any tips would be appreciated. Thanks.

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

Where do you see this command? There is a Readfile command, but it only has a path for an argument. Maybe I'm interpreting the question wrong.

 

FileSystem.h of the engine's API.

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

You might be looking for a command like ReadLine from the Stream commands. It includes and example but I'm happy to help if you want me to write a quick example for you. After that it's just about using a string command to read a portion of the string (after the equal sign).

 

What's the settings file name, by the way? I don't see it in my project.

  • Upvote 1
Link to comment
Share on other sites

I did it like this, I'll look into compare right now, thanks.

 


std::string GetKeyValue(std::string pPath, std::string pKeyVal)

{

std::string path = pPath;

Stream* stream = FileSystem::ReadFile(path);

string command(pKeyVal + "=");

std::size_t found = stream->ReadString().find(command);

 

if (found != std::string::npos)

std::cout << pKeyVal << " found at: " << found << '\n';

 

stream->Seek(found + command.size());

string finals = stream->ReadString();

finals.erase(

remove(finals.begin(), finals.end(), '\"'),

finals.end()

);

 

return finals;

 

EDIT: still has a problem if the value isn't the last.

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

Yeah, I was missing ReadLine, I got involved looking into raw C++ stuff meanwhile that function is what I needed. ><

 

All working now, thanks. Does not support everything, but it will support most things.

 


std::string GetKeyValue(std::string pPath, std::string pKey)

{

Stream* stream = FileSystem::ReadFile(pPath);

string command(pKey + "=");

 

std::size_t found = stream->ReadString().rfind(command);

if (found != std::string::npos)

{

std::cout << pKey << " found at: " << found << '\n';

}

 

stream->Seek(found + command.size());

 

// Read only the line we're on!

string finals = stream->ReadLine();

 

// Delete the quotes if any.

finals.erase(

remove(finals.begin(), finals.end(), '\"'),

finals.end()

);

 

// Return our value!

return finals;

}

 

// This function will be called once when the program starts.

bool Start()

{

std::string path = "materials/developer/bluegrid.mat";

cout << GetKeyValue(path, "shader") << endl;

}

  • Upvote 2

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

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...