Added base64 support for FileData, and inlined all resources in boot.lua/graphics.lua as base64. Also removed old reshax stuff.

This commit is contained in:
rude
2010-09-19 13:22:10 +02:00
parent 6492888c31
commit d27dd8b5dd
23 changed files with 7528 additions and 3237 deletions
+18
View File
@@ -59,5 +59,23 @@ namespace filesystem
return extension;
}
bool FileData::getConstant(const char * in, Decoder & out)
{
return decoders.find(in, out);
}
bool FileData::getConstant(Decoder in, const char *& out)
{
return decoders.find(in, out);
}
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
{
{"file", FileData::FILE},
{"base64", FileData::BASE64},
};
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM> FileData::decoders(FileData::decoderEntries, sizeof(FileData::decoderEntries));
} // filesystem
} // love
+16
View File
@@ -24,6 +24,7 @@
// LOVE
#include <string>
#include <common/Data.h>
#include <common/StringMap.h>
namespace love
{
@@ -47,6 +48,13 @@ namespace filesystem
public:
enum Decoder
{
FILE,
BASE64,
DECODE_MAX_ENUM
}; // Decoder
FileData(int size, const std::string & filename);
virtual ~FileData();
@@ -58,6 +66,14 @@ namespace filesystem
const std::string & getFilename() const;
const std::string & getExtension() const;
static bool getConstant(const char * in, Decoder & out);
static bool getConstant(Decoder in, const char *& out);
private:
static StringMap<Decoder, DECODE_MAX_ENUM>::Entry decoderEntries[];
static StringMap<Decoder, DECODE_MAX_ENUM> decoders;
}; // FileData
} // filesystem
+16 -1
View File
@@ -21,6 +21,7 @@
#include <common/config.h>
#include <common/utf8.h>
#include <common/b64.h>
#include "Filesystem.h"
@@ -146,12 +147,26 @@ namespace physfs
{
FileData * fd = new FileData(size, std::string(filename));
// Copy the data into
// Copy the data into FileData.
memcpy(fd->getData(), data, size);
return fd;
}
FileData * Filesystem::newFileData(const char * b64, const char * filename)
{
int size = strlen(b64);
int outsize = 0;
char * dst = b64_decode(b64, size, outsize);
FileData * fd = new FileData(outsize, std::string(filename));
// Copy the data into FileData.
memcpy(fd->getData(), dst, outsize);
delete [] dst;
return fd;
}
const char * Filesystem::getWorkingDirectory()
{
if(cwd.empty())
@@ -142,6 +142,12 @@ namespace physfs
**/
FileData * newFileData(void * data, int size, const char * filename);
/**
* Creates a new FileData object from base64 data.
* @param b64 The base64 data.
**/
FileData * newFileData(const char * b64, const char * filename);
/**
* Gets the current working directory.
**/
@@ -98,8 +98,26 @@ namespace physfs
size_t length = 0;
const char * str = lua_tolstring(L, 1, &length);
const char * filename = lua_tostring(L, 2);
const char * decstr = lua_isstring(L, 3) ? lua_tostring(L, 3) : 0;
FileData * t = instance->newFileData((void*)str, (int)length, filename);
FileData::Decoder decoder = FileData::FILE;
if(decstr)
FileData::getConstant(decstr, decoder);
FileData * t = 0;
switch(decoder)
{
case FileData::FILE:
t = instance->newFileData((void*)str, (int)length, filename);
break;
case FileData::BASE64:
t = instance->newFileData(str, filename);
break;
default:
return luaL_error(L, "Unrecognized FileData decoder: %s", decstr);
}
luax_newtype(L, "FileData", FILESYSTEM_FILE_DATA_T, (void*)t);
return 1;