SFML community forums

Help => General => Topic started by: Anthony11 on July 14, 2015, 11:25:05 am

Title: Load from memory/stream help?
Post by: Anthony11 on July 14, 2015, 11:25:05 am
I created a large file that contains some of the resources I use in my game. How can I load them if I have a length (in bytes) of each file and start position of each of them in a .ini file.

this is what i've got so far (ini is handled via inih plugin):
http://pastebin.com/Qs7E4MVf

example of ini:
p_file1.lua=main.pack
s_file1.lua=0
l_file1.lua=170
p_intro.png=main.pack
s_intro.png=170
l_intro.png=117
p_abc.jpg=main.pack
s_abc.jpg=287
l_abc.jpg=162

p_ = package name
s_ = start location
l_ = length (bytes)
Title: Re: Load from memory/stream help?
Post by: eXpl0it3r on July 14, 2015, 11:37:25 am
Load the file into memory, move the pointer to the starting position of your file, pass in the pointer and the size to the loadFromMemory function.
Title: Re: Load from memory/stream help?
Post by: Anthony11 on July 14, 2015, 11:39:40 am
the problem is that i don't know how to do that  :(
Title: AW: Load from memory/stream help?
Post by: eXpl0it3r on July 14, 2015, 11:41:35 am
Then this is a simple C++ problem for which you'll find a lot of solutions on the web.

Try to search for "open file C++" and "pointer arithmetic".
Title: Re: Load from memory/stream help?
Post by: Anthony11 on July 14, 2015, 12:20:25 pm
        // ......
        std::string Pack = defaultLocation;
        Pack.append(reader.Get("", x1.c_str(), "null"));
        std::string Start = reader.Get("", x2.c_str(), "null");
        std::string Length = reader.Get("", x3.c_str(), "null");
        unsigned long long StartI = ll_from_string(Start);
        unsigned long long LengthI = ll_from_string(Length);
        char *data;
        std::ifstream myfile;
        myfile.open(Pack.c_str());
        myfile.seekg(0, StartI); // here is the error
        myfile.read(&data,LengthI);
        myfile.close();

cannot convert long long int to sd::ios_base seekdir, and i don't even know if i'm doing this right
i really cant figure this out on my own
Title: Re: Load from memory/stream help?
Post by: Anthony11 on July 14, 2015, 01:19:18 pm
Still can't find a solution
Title: Re: Load from memory/stream help?
Post by: Anthony11 on July 14, 2015, 04:22:16 pm
solved finally, no worries, can lock
Title: Re: Load from memory/stream help?
Post by: dabbertorres on July 14, 2015, 06:10:44 pm
solved finally, no worries, can lock

It's good internet manners to add your solution for the next person who has the same issue and finds this topic (https://xkcd.com/979/).