Archive 17/01/2023.

How to get raw resource file as binrary data?

elemusic

Trying to load binrary file from reousrce fold.

Say Data\Urho2D\myBin.bin

the example project use something like

Sprite2D* sprite = cache->GetResource<Sprite2D>("Urho2D/Aster.png");

to load png resource as Sprite2D object,what if i want to load my own raw bin file?

something like

unsigned char* rawBuf = cache-GetResource<SomeMagicNameMayWork>("Urho2D/myBin.bin");

is there a way to do so,or some other way to do the same thing.

1vanK

SharedPtr<File> file(new File(context_, fileName, FILE_READ)); if (file->IsOpen()) { ... }

1vanK
cadaver

ResourceCache::GetFile() if you want to take advantage of the resource paths / packages, instead of specifying the full absolute filename. This just opens the file from the filesystem and doesn’t do any caching, after which you can do your own reading.

elemusic

Thank you,guys,just figure it out myself.

ResourceCache* cache = GetSubsystem<ResourceCache>();
SharedPtr<File> myfile = cache->GetFile("Urho2D/xxx.bin", true);
unsigned int bufSize = myfile->GetSize();
unsigned char* buf = new unsigned char[bufSize];
myfile->Read((void*)buf, bufSize);

for some reason,i found it’s hard to work with Urho build-in xml and json parser.
Now i’m trying to load file as binrary and parsing them with boost.that could save me a lot of time to figure out the Urho document.
just a lazy guy :smiley: