89 |
|
#include <sys/mman.h> |
90 |
|
#include <sys/ipc.h> |
91 |
|
#include <sys/shm.h> |
92 |
+ |
#include <sys/stat.h> |
93 |
|
#include <signal.h> |
94 |
|
|
95 |
|
#include "sysdeps.h" |
361 |
|
exit(0); |
362 |
|
} |
363 |
|
|
364 |
+ |
static bool valid_vmdir(const char *path) |
365 |
+ |
{ |
366 |
+ |
const int suffix_len = sizeof(".sheepvm") - 1; |
367 |
+ |
int len = strlen(path); |
368 |
+ |
if (len > suffix_len && !strcmp(path + len - suffix_len, ".sheepvm")) { |
369 |
+ |
struct stat d; |
370 |
+ |
if (!stat(path, &d) && S_ISDIR(d.st_mode)) { |
371 |
+ |
return true; |
372 |
+ |
} |
373 |
+ |
} |
374 |
+ |
return false; |
375 |
+ |
} |
376 |
+ |
|
377 |
|
int main(int argc, char **argv) |
378 |
|
{ |
379 |
|
char str[256]; |
384 |
|
uint8 *rom_tmp; |
385 |
|
time_t now, expire; |
386 |
|
bool memory_mapped_from_zero; |
387 |
+ |
const char *vmdir = NULL; |
388 |
|
|
389 |
|
#ifdef USE_SDL_VIDEO |
390 |
|
// Don't let SDL block the screensaver |
429 |
|
gui_connection_path = argv[i]; |
430 |
|
argv[i] = NULL; |
431 |
|
} |
432 |
+ |
} else if (valid_vmdir(argv[i])) { |
433 |
+ |
vmdir = argv[i]; |
434 |
+ |
argv[i] = NULL; |
435 |
+ |
printf("Using %s as vmdir.\n", vmdir); |
436 |
+ |
if (chdir(vmdir)) { |
437 |
+ |
printf("Failed to chdir to %s. Good bye.", vmdir); |
438 |
+ |
exit(1); |
439 |
+ |
} |
440 |
+ |
break; |
441 |
|
} |
442 |
|
} |
443 |
|
|
472 |
|
#endif |
473 |
|
|
474 |
|
// Read preferences |
475 |
< |
PrefsInit(argc, argv); |
475 |
> |
PrefsInit(vmdir, argc, argv); |
476 |
|
|
477 |
|
// Any command line arguments left? |
478 |
|
for (int i=1; i<argc; i++) { |
919 |
|
delete[] rom_tmp; |
920 |
|
|
921 |
|
// Initialize everything |
922 |
< |
if (!InitAll()) |
922 |
> |
if (!InitAll(vmdir)) |
923 |
|
goto quit; |
924 |
|
D(bug("Initialization complete\n")); |
925 |
|
|