使用SDL读
This commit is contained in:
parent
515938e24f
commit
270a104589
|
@ -4,6 +4,7 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_messagebox.h"
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_main.h"
|
||||
#include <windows.h>
|
||||
struct INFO {
|
||||
|
@ -20,26 +21,26 @@ static int GGE_LoadWindows(lua_State *L)
|
|||
size_t l;
|
||||
const char* path = lua_tolstring(L,1,&l);
|
||||
size_t i;
|
||||
FILE *f = fopen(path,"rb");
|
||||
SDL_RWops*f = SDL_RWFromFile(path,"rb");
|
||||
if (f==NULL)
|
||||
return 0;
|
||||
if (fseek(f,-(int)sizeof(info),SEEK_END)!=0){
|
||||
fclose(f);
|
||||
if (SDL_RWseek(f,-(int)sizeof(info), RW_SEEK_END)==0){
|
||||
SDL_FreeRW(f);
|
||||
return 0;
|
||||
}
|
||||
if (fread(&info,sizeof(info),1,f)!=1){
|
||||
fclose(f);
|
||||
if (SDL_RWread(f,&info,sizeof(info),1)==0){
|
||||
SDL_FreeRW(f);
|
||||
return 0;
|
||||
}
|
||||
if (info.signal==0x20454747){
|
||||
if (fseek(f,-(int)(sizeof(info)+info.coresize+info.packsize),SEEK_END)!=0){
|
||||
fclose(f);
|
||||
if (SDL_RWseek(f,-(int)(sizeof(info)+info.coresize+info.packsize), RW_SEEK_END)==0){
|
||||
SDL_FreeRW(f);
|
||||
return 0;
|
||||
}
|
||||
ggelua = (char*)SDL_malloc(info.coresize);
|
||||
fread(ggelua,info.coresize,1,f);
|
||||
SDL_RWread(f,ggelua,info.coresize,1);
|
||||
ggepack = (char*)SDL_malloc(info.packsize);
|
||||
fread(ggepack,info.packsize,1,f);
|
||||
SDL_RWread(f,ggepack,info.packsize,1);
|
||||
}else{
|
||||
char lpath[256];
|
||||
for (i=0;i<l;i++)
|
||||
|
@ -50,18 +51,10 @@ static int GGE_LoadWindows(lua_State *L)
|
|||
#else
|
||||
path = luaL_gsub(L, lpath, "ggelua.exe", "ggelua.lua");
|
||||
#endif
|
||||
FILE *f = fopen(path,"rb");
|
||||
if (f){
|
||||
fseek(f,0,SEEK_END);
|
||||
info.coresize = ftell(f);
|
||||
info.packsize = 0;
|
||||
fseek(f,0,SEEK_SET);
|
||||
ggelua = (char*)SDL_malloc(info.coresize);
|
||||
fread(ggelua,info.coresize,1,f);
|
||||
fclose(f);
|
||||
}
|
||||
ggelua = (char*)SDL_LoadFile(path, &info.coresize);
|
||||
info.packsize = 0;
|
||||
}
|
||||
fclose(f);
|
||||
SDL_FreeRW(f);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -99,7 +92,7 @@ int SDL_main(int argc, char* argv[])
|
|||
lua_setglobal(L, "arg");
|
||||
#if defined(__WIN32__)
|
||||
lua_pushcfunction(L,GGE_LoadWindows);//¶ÁÈ¡½Å±¾
|
||||
lua_pushstring(L,__argv[0]);
|
||||
lua_pushstring(L, argv[0]);
|
||||
lua_call(L, 1, 0);
|
||||
#endif /* __WIN32__ */
|
||||
if (ggelua){
|
||||
|
|
Loading…
Reference in New Issue