--- Urlader/urlader.c 2011/12/29 00:44:21 1.1 +++ Urlader/urlader.c 2011/12/29 10:20:56 1.2 @@ -11,7 +11,7 @@ #include #include -#include "lzf_d.c" +#include "liblzf/lzf_d.c" #define TAIL_MAGIC "SCHMORPPACK0" @@ -107,12 +107,12 @@ } static void -systemv (const char *const argv[]) +systemv (const char *const argv[], int dowait) { #ifdef _WIN32 _spawnv (P_WAIT, argv [0], argv); #else - pid_t pid = fork (); + pid_t pid = dowait ? fork () : 0; if (pid < 0) fatal ("fork failure"); @@ -138,14 +138,7 @@ #else const char *argv[] = { "/bin/rm", "-rf", path, 0 }; #endif - systemv (argv); -} - -static void -execute (void) -{ - exe_argv [exe_argc] = 0; - systemv (exe_argv); + systemv (argv, 1); } enum @@ -182,6 +175,8 @@ static char *pack_base, *pack_end; static struct hdr *pack_cur; +static char *scratch; +static unsigned int scratch_len; #define PACK_NAME ((char *)(pack_cur + 1)) #define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) @@ -201,6 +196,8 @@ if (!pack_base) return; + free (scratch); + #ifdef _WIN32 UnmapViewOfFile (pack_base); #else @@ -256,6 +253,9 @@ pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); + free (scratch); + scratch = malloc (scratch_len = u_32 (tail->max_filesize)); + return 1; } @@ -339,12 +339,22 @@ case T_FILE: { u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); - unsigned int len = u_32 (pack_cur->datalen); + unsigned int dlen, len = u_32 (pack_cur->datalen); + char *data = PACK_DATA; + + if (pack_cur->flags & F_LZF) + if (dlen = lzf_decompress (data, len, scratch, scratch_len)) + { + data = scratch; + len = dlen; + } + else + fatal ("unable to uncompress file data - pack corrupted?"); if (!h) fatal ("unable to unpack file from packfile - disk full?"); - if (u_write (h, PACK_DATA, len) != len) + if (u_write (h, data, len) != len) fatal ("unable to unpack file from packfile - disk full?"); u_close (h); @@ -364,14 +374,14 @@ if (u_rename (tmppath, execdir)) deltree (tmppath); // if move fails, delete new, assume other process created it independently - - if (u_chdir (execdir)) - fatal ("unable to change to application instance directory"); } pack_unmap (); u_close (pack_handle); + if (u_chdir (execdir)) + fatal ("unable to change to application instance directory"); + u_setenv ("URLADER_VERSION", URLADER_VERSION); u_setenv ("URLADER_DATADIR", datadir); u_setenv ("URLADER_EXECDIR", execdir); @@ -390,6 +400,13 @@ u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple } +static void +execute (void) +{ + exe_argv [exe_argc] = 0; + systemv (exe_argv, 0); +} + #ifdef _WIN32 int APIENTRY