diff --git a/src/lib/miniz.c b/src/lib/miniz.c index 9ded4c7..2e4c619 100644 --- a/src/lib/miniz.c +++ b/src/lib/miniz.c @@ -3635,6 +3635,10 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag cdir_ofs = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_OFS_OFS); } + /* Calculate the offset and compare to written offset to get size of data offset at front. */ + if (pZip->m_pState->m_file_archive_start_ofs == 0) + pZip->m_pState->m_file_archive_start_ofs = cur_file_ofs - cdir_size - cdir_ofs; + if (pZip->m_total_files != cdir_entries_on_this_disk) return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); diff --git a/src/raylua.lua b/src/raylua.lua index 19c806f..8f59238 100644 --- a/src/raylua.lua +++ b/src/raylua.lua @@ -43,9 +43,9 @@ function raylua.repl() end end -if raylua.loadfile then - package.path = "?.lua;?/init.lua" +package.path = "?.lua;?/init.lua" +if raylua.loadfile then -- Change the second loader to load files using raylua.loadfile package.loaders[2] = function (name) for path in package.path:gmatch "([^;]+);?" do diff --git a/src/raylua_builder.c b/src/raylua_builder.c index 1c56238..c175408 100644 --- a/src/raylua_builder.c +++ b/src/raylua_builder.c @@ -48,19 +48,9 @@ static void append_file(FILE *dst, FILE *src) } while(count == 4096); } -static void append_file_offset(FILE *output, FILE *source, FILE *input) -{ - append_file(output, source); - fpos_t pos; - fgetpos(output, &pos); - append_file(output, input); - fwrite(&pos, sizeof(fpos_t), 1, output); -} - typedef struct raylua_builder { mz_zip_archive zip; FILE *file; - fpos_t offset; } raylua_builder; static int raylua_builder_new(lua_State *L) @@ -194,9 +184,6 @@ int raylua_builder_boot(lua_State *L) lua_pushcfunction(L, list_dir); lua_setglobal(L, "list_dir"); - lua_pushlightuserdata(L, append_file_offset); - lua_setglobal(L, "append_file_offset"); - lua_pushcfunction(L, raylua_builder_new); lua_setglobal(L, "builder_new"); diff --git a/src/raylua_builder.lua b/src/raylua_builder.lua index ee27c80..8b0cc7b 100644 --- a/src/raylua_builder.lua +++ b/src/raylua_builder.lua @@ -149,7 +149,8 @@ elseif t == "file" then local source = assert(io.open(self_path, "rb"), "Can't open self file.") local input = assert(io.open(input_path, "rb"), "Can't open zip file.") - append_file_offset(dest, source, input) + append_file(dest, source) + append_file(dest, input) dest:close() source:close() diff --git a/src/raylua_e.c b/src/raylua_e.c index 0fa84a8..6778b79 100644 --- a/src/raylua_e.c +++ b/src/raylua_e.c @@ -66,33 +66,11 @@ int raylua_loadfile(lua_State *L) return 1; } -static bool raylua_init_payload(const char *path, bool direct) +static bool raylua_init_payload(const char *path) { mz_zip_zero_struct(&zip_file); - if (direct) { - if (!mz_zip_reader_init_file(&zip_file, path, 0)) - return false; - } else { - FILE *f = fopen(path, "rb"); - - if (f == NULL) { - puts("RAYLUA: Can't load self."); - return false; - } else { - /* Read offset at the end of the file */ - fpos_t offset; - fseek(f, -(long)sizeof(fpos_t), SEEK_END); - fread(&offset, sizeof(fpos_t), 1, f); - - fsetpos(f, &offset); - - if (!mz_zip_reader_init_cfile(&zip_file, f, 0, 0)) - return false; - } - } - - return true; + return mz_zip_reader_init_file(&zip_file, path, 0); } int main(int argc, const char **argv) @@ -131,7 +109,7 @@ int main(int argc, const char **argv) } #endif - if (!raylua_init_payload(path, false)) { + if (!raylua_init_payload(path)) { #ifdef RAYLUA_NO_BUILDER puts("RAYLUA: No payload."); #else