Make file offset appending unneeded.

This commit is contained in:
TSnake41 2020-04-01 18:12:06 +02:00
parent 3eb0ed200c
commit ce6a446b70
5 changed files with 11 additions and 41 deletions

View File

@ -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); 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) if (pZip->m_total_files != cdir_entries_on_this_disk)
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);

View File

@ -43,9 +43,9 @@ function raylua.repl()
end end
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 -- Change the second loader to load files using raylua.loadfile
package.loaders[2] = function (name) package.loaders[2] = function (name)
for path in package.path:gmatch "([^;]+);?" do for path in package.path:gmatch "([^;]+);?" do

View File

@ -48,19 +48,9 @@ static void append_file(FILE *dst, FILE *src)
} while(count == 4096); } 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 { typedef struct raylua_builder {
mz_zip_archive zip; mz_zip_archive zip;
FILE *file; FILE *file;
fpos_t offset;
} raylua_builder; } raylua_builder;
static int raylua_builder_new(lua_State *L) 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_pushcfunction(L, list_dir);
lua_setglobal(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_pushcfunction(L, raylua_builder_new);
lua_setglobal(L, "builder_new"); lua_setglobal(L, "builder_new");

View File

@ -149,7 +149,8 @@ elseif t == "file" then
local source = assert(io.open(self_path, "rb"), "Can't open self file.") 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.") 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() dest:close()
source:close() source:close()

View File

@ -66,33 +66,11 @@ int raylua_loadfile(lua_State *L)
return 1; 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); mz_zip_zero_struct(&zip_file);
if (direct) { return mz_zip_reader_init_file(&zip_file, path, 0);
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;
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)
@ -131,7 +109,7 @@ int main(int argc, const char **argv)
} }
#endif #endif
if (!raylua_init_payload(path, false)) { if (!raylua_init_payload(path)) {
#ifdef RAYLUA_NO_BUILDER #ifdef RAYLUA_NO_BUILDER
puts("RAYLUA: No payload."); puts("RAYLUA: No payload.");
#else #else