Aralox
29-01-2012 09:05:25
Hey there, i'm trying to figure out how to get a Stream (http://msdn.microsoft.com/en-us/library/system.io.stream.aspx) object from a resource loaded in Mogre,
such as a text file, and would appreciate any help.
Thanks!
Aralox
Edit: After some searching, i found http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=10413 where he had the same (unsolved) problem,
And http://www.ogre3d.org/addonforums/viewtopic.php?f=8&p=21661#p21661, which had the solution
In a nutshell, here it is:
Thanks to bekas and Madmark for coming up with the above method, I just sort of put it together.
such as a text file, and would appreciate any help.
Thanks!

Aralox
Edit: After some searching, i found http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=10413 where he had the same (unsolved) problem,
And http://www.ogre3d.org/addonforums/viewtopic.php?f=8&p=21661#p21661, which had the solution

In a nutshell, here it is:
//DataStreamPtr dataPtr = ResourceGroupManager.Singleton.OpenResource("my resource");
public MemoryStream DataPtrToStream(DataStreamPtr dataPtr)
{
if (dataPtr.Size() != 0)
{
byte[] buffer = new byte[dataPtr.Size()];
unsafe
{
//Get the pointer to the first element of our buffer of bytes (in C++, can just use 'buffer')
fixed (byte* bufferPtr = &buffer[0])
{
//Read buffer.Length amount of data into bufferPtr
dataPtr.Read(bufferPtr, (uint)buffer.Length);
}
}
MemoryStream stream = new MemoryStream(buffer);
return stream;
}
return null;
}
Thanks to bekas and Madmark for coming up with the above method, I just sort of put it together.