… | |
… | |
9 | #include <errno.h> |
9 | #include <errno.h> |
10 | #include <string.h> |
10 | #include <string.h> |
11 | #include <time.h> |
11 | #include <time.h> |
12 | #include <fcntl.h> |
12 | #include <fcntl.h> |
13 | |
13 | |
14 | #include "lzf_d.c" |
14 | #include "liblzf/lzf_d.c" |
15 | |
15 | |
16 | #define TAIL_MAGIC "SCHMORPPACK0" |
16 | #define TAIL_MAGIC "SCHMORPPACK0" |
17 | |
17 | |
18 | #ifdef _WIN32 |
18 | #ifdef _WIN32 |
19 | |
19 | |
… | |
… | |
105 | return; |
105 | return; |
106 | } |
106 | } |
107 | } |
107 | } |
108 | |
108 | |
109 | static void |
109 | static void |
110 | systemv (const char *const argv[]) |
110 | systemv (const char *const argv[], int dowait) |
111 | { |
111 | { |
112 | #ifdef _WIN32 |
112 | #ifdef _WIN32 |
113 | _spawnv (P_WAIT, argv [0], argv); |
113 | _spawnv (P_WAIT, argv [0], argv); |
114 | #else |
114 | #else |
115 | pid_t pid = fork (); |
115 | pid_t pid = dowait ? fork () : 0; |
116 | |
116 | |
117 | if (pid < 0) |
117 | if (pid < 0) |
118 | fatal ("fork failure"); |
118 | fatal ("fork failure"); |
119 | |
119 | |
120 | if (!pid) |
120 | if (!pid) |
… | |
… | |
136 | const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 }; |
136 | const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 }; |
137 | sprintf (buf, "\"%s\"", path); |
137 | sprintf (buf, "\"%s\"", path); |
138 | #else |
138 | #else |
139 | const char *argv[] = { "/bin/rm", "-rf", path, 0 }; |
139 | const char *argv[] = { "/bin/rm", "-rf", path, 0 }; |
140 | #endif |
140 | #endif |
141 | systemv (argv); |
141 | systemv (argv, 1); |
142 | } |
|
|
143 | |
|
|
144 | static void |
|
|
145 | execute (void) |
|
|
146 | { |
|
|
147 | exe_argv [exe_argc] = 0; |
|
|
148 | systemv (exe_argv); |
|
|
149 | } |
142 | } |
150 | |
143 | |
151 | enum |
144 | enum |
152 | { |
145 | { |
153 | T_NULL, // 5 |
146 | T_NULL, // 5 |
… | |
… | |
180 | char magic[12]; |
173 | char magic[12]; |
181 | }; |
174 | }; |
182 | |
175 | |
183 | static char *pack_base, *pack_end; |
176 | static char *pack_base, *pack_end; |
184 | static struct hdr *pack_cur; |
177 | static struct hdr *pack_cur; |
|
|
178 | static char *scratch; |
|
|
179 | static unsigned int scratch_len; |
185 | |
180 | |
186 | #define PACK_NAME ((char *)(pack_cur + 1)) |
181 | #define PACK_NAME ((char *)(pack_cur + 1)) |
187 | #define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) |
182 | #define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) |
188 | #define PACK_VALID pack_cur->type |
183 | #define PACK_VALID pack_cur->type |
189 | |
184 | |
… | |
… | |
199 | pack_unmap (void) |
194 | pack_unmap (void) |
200 | { |
195 | { |
201 | if (!pack_base) |
196 | if (!pack_base) |
202 | return; |
197 | return; |
203 | |
198 | |
|
|
199 | free (scratch); |
|
|
200 | |
204 | #ifdef _WIN32 |
201 | #ifdef _WIN32 |
205 | UnmapViewOfFile (pack_base); |
202 | UnmapViewOfFile (pack_base); |
206 | #else |
203 | #else |
207 | munmap (pack_base, pack_end - pack_base); |
204 | munmap (pack_base, pack_end - pack_base); |
208 | #endif |
205 | #endif |
… | |
… | |
253 | |
250 | |
254 | if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) |
251 | if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) |
255 | return 0; |
252 | return 0; |
256 | |
253 | |
257 | pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); |
254 | pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); |
|
|
255 | |
|
|
256 | free (scratch); |
|
|
257 | scratch = malloc (scratch_len = u_32 (tail->max_filesize)); |
258 | |
258 | |
259 | return 1; |
259 | return 1; |
260 | } |
260 | } |
261 | |
261 | |
262 | static void |
262 | static void |
… | |
… | |
337 | break; |
337 | break; |
338 | |
338 | |
339 | case T_FILE: |
339 | case T_FILE: |
340 | { |
340 | { |
341 | u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); |
341 | u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); |
342 | unsigned int len = u_32 (pack_cur->datalen); |
342 | unsigned int dlen, len = u_32 (pack_cur->datalen); |
|
|
343 | char *data = PACK_DATA; |
|
|
344 | |
|
|
345 | if (pack_cur->flags & F_LZF) |
|
|
346 | if (dlen = lzf_decompress (data, len, scratch, scratch_len)) |
|
|
347 | { |
|
|
348 | data = scratch; |
|
|
349 | len = dlen; |
|
|
350 | } |
|
|
351 | else |
|
|
352 | fatal ("unable to uncompress file data - pack corrupted?"); |
343 | |
353 | |
344 | if (!h) |
354 | if (!h) |
345 | fatal ("unable to unpack file from packfile - disk full?"); |
355 | fatal ("unable to unpack file from packfile - disk full?"); |
346 | |
356 | |
347 | if (u_write (h, PACK_DATA, len) != len) |
357 | if (u_write (h, data, len) != len) |
348 | fatal ("unable to unpack file from packfile - disk full?"); |
358 | fatal ("unable to unpack file from packfile - disk full?"); |
349 | |
359 | |
350 | u_close (h); |
360 | u_close (h); |
351 | } |
361 | } |
352 | break; |
362 | break; |
… | |
… | |
362 | if (u_chdir (datadir)) |
372 | if (u_chdir (datadir)) |
363 | fatal ("unable to change to data directory"); |
373 | fatal ("unable to change to data directory"); |
364 | |
374 | |
365 | if (u_rename (tmppath, execdir)) |
375 | if (u_rename (tmppath, execdir)) |
366 | deltree (tmppath); // if move fails, delete new, assume other process created it independently |
376 | deltree (tmppath); // if move fails, delete new, assume other process created it independently |
367 | |
|
|
368 | if (u_chdir (execdir)) |
|
|
369 | fatal ("unable to change to application instance directory"); |
|
|
370 | } |
377 | } |
371 | |
378 | |
372 | pack_unmap (); |
379 | pack_unmap (); |
373 | u_close (pack_handle); |
380 | u_close (pack_handle); |
|
|
381 | |
|
|
382 | if (u_chdir (execdir)) |
|
|
383 | fatal ("unable to change to application instance directory"); |
374 | |
384 | |
375 | u_setenv ("URLADER_VERSION", URLADER_VERSION); |
385 | u_setenv ("URLADER_VERSION", URLADER_VERSION); |
376 | u_setenv ("URLADER_DATADIR", datadir); |
386 | u_setenv ("URLADER_DATADIR", datadir); |
377 | u_setenv ("URLADER_EXECDIR", execdir); |
387 | u_setenv ("URLADER_EXECDIR", execdir); |
378 | u_setenv ("URLADER_EXE_ID" , exe_id); |
388 | u_setenv ("URLADER_EXE_ID" , exe_id); |
… | |
… | |
388 | u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix |
398 | u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix |
389 | u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix |
399 | u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix |
390 | u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple |
400 | u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple |
391 | } |
401 | } |
392 | |
402 | |
|
|
403 | static void |
|
|
404 | execute (void) |
|
|
405 | { |
|
|
406 | exe_argv [exe_argc] = 0; |
|
|
407 | systemv (exe_argv, 0); |
|
|
408 | } |
|
|
409 | |
393 | #ifdef _WIN32 |
410 | #ifdef _WIN32 |
394 | |
411 | |
395 | int APIENTRY |
412 | int APIENTRY |
396 | WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) |
413 | WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) |
397 | { |
414 | { |