2013-11-22 10:46:25 +01:00
|
|
|
#include "OResource.h"
|
|
|
|
|
|
|
|
using namespace Oyster::Resource;
|
|
|
|
|
|
|
|
OResource::OResource(OHRESOURCE handle, ResourceType type, size_t resourceSize, size_t elementSize, ::std::wstring filename)
|
|
|
|
: resourceData (handle)
|
|
|
|
, resourceFilename (filename)
|
|
|
|
, resourceSize (resourceSize)
|
|
|
|
, resourceElementSize (elementSize)
|
|
|
|
, resourceType (type)
|
2013-11-26 10:55:51 +01:00
|
|
|
, customData (0)
|
2013-11-22 10:46:25 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
OResource::~OResource()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2013-11-26 10:55:51 +01:00
|
|
|
OResource* OResource::Load (const wchar_t filename[], ResourceType type)
|
2013-11-22 10:46:25 +01:00
|
|
|
{
|
2013-11-26 10:55:51 +01:00
|
|
|
switch (type)
|
2013-11-22 10:46:25 +01:00
|
|
|
{
|
2013-11-26 10:55:51 +01:00
|
|
|
case Oyster::Resource::ResourceType_Byte_Raw:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_ANSI:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF8:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
|
|
|
return OResource::ByteLoader(filename, type);
|
2013-11-22 10:46:25 +01:00
|
|
|
break;
|
2013-11-26 10:55:51 +01:00
|
|
|
}
|
2013-11-22 10:46:25 +01:00
|
|
|
|
2013-11-26 10:55:51 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
OResource* OResource::Load (const wchar_t filename[], CustomLoadFunction loadFnc)
|
|
|
|
{
|
|
|
|
return OResource::CustomLoader(filename, loadFnc);
|
|
|
|
}
|
|
|
|
OResource* OResource::Reload (OResource* resource)
|
|
|
|
{
|
|
|
|
if(!resource) return 0;
|
2013-11-22 10:46:25 +01:00
|
|
|
|
2013-11-26 10:55:51 +01:00
|
|
|
switch (resource->resourceType)
|
|
|
|
{
|
2013-11-22 10:46:25 +01:00
|
|
|
case Oyster::Resource::ResourceType_Byte_Raw:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_ANSI:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF8:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
2013-11-26 10:55:51 +01:00
|
|
|
resource->ByteReloader();
|
2013-11-22 10:46:25 +01:00
|
|
|
break;
|
2013-11-26 10:55:51 +01:00
|
|
|
|
|
|
|
case Oyster::Resource::ResourceType_UNKNOWN:
|
|
|
|
resource->CustomReloader();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
bool OResource::Release (OResource* resource)
|
|
|
|
{
|
|
|
|
if(resource->resourceRef.Decref() == 0)
|
|
|
|
{
|
|
|
|
switch (resource->resourceType)
|
|
|
|
{
|
|
|
|
case Oyster::Resource::ResourceType_Byte_Raw:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_ANSI:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF8:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
|
|
|
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
|
|
|
resource->ByteUnloader();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Oyster::Resource::ResourceType_UNKNOWN:
|
|
|
|
resource->CustomUnloader();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2013-11-22 10:46:25 +01:00
|
|
|
}
|
2013-11-26 10:55:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|