2010-07-28 08:07:28 +03:00
|
|
|
#ifdef __APPLE__
|
2010-07-24 16:14:25 +03:00
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
|
|
|
|
2009-09-05 07:44:45 +03:00
|
|
|
#include "externals.h"
|
|
|
|
#include "internals.h"
|
2009-08-26 08:25:53 +03:00
|
|
|
|
2010-06-02 15:43:28 +03:00
|
|
|
#ifdef _USE_GTK
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2010-11-04 17:01:34 +02:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include "android.h"
|
|
|
|
#endif
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
extern int debug_init(void);
|
|
|
|
extern void debug_done(void);
|
|
|
|
|
|
|
|
int debug_sw = 0;
|
2009-09-19 12:59:59 +03:00
|
|
|
int noauto_sw = 0;
|
2009-11-21 13:58:24 +02:00
|
|
|
int nostdgames_sw = 0;
|
|
|
|
int nostdthemes_sw = 0;
|
2010-01-20 14:41:38 +02:00
|
|
|
int version_sw = 0;
|
2010-03-12 20:06:15 +02:00
|
|
|
int nopause_sw = 0;
|
2009-08-31 22:50:29 +03:00
|
|
|
char *game_sw = NULL;
|
2009-09-03 13:34:53 +03:00
|
|
|
char *games_sw = NULL;
|
2009-09-07 09:14:26 +03:00
|
|
|
char *theme_sw = NULL;
|
2009-09-03 13:34:53 +03:00
|
|
|
char *themes_sw = NULL;
|
2009-10-12 08:07:15 +03:00
|
|
|
char *encode_sw = NULL;
|
|
|
|
char *encode_output = NULL;
|
2009-10-24 18:57:08 +03:00
|
|
|
char *mode_sw = NULL;
|
2009-02-21 12:52:44 +02:00
|
|
|
|
2010-07-10 20:18:52 +03:00
|
|
|
#ifdef _USE_UNPACK
|
2010-06-01 14:23:31 +03:00
|
|
|
extern int unpack(const char *zipfilename, const char *where);
|
|
|
|
extern char zip_game_dirname[];
|
|
|
|
|
2010-06-03 10:56:40 +03:00
|
|
|
static int setup_zip(const char *file, char *p)
|
|
|
|
{
|
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
fprintf(stderr,"Trying to install: %s\n", file);
|
2010-06-04 10:27:10 +03:00
|
|
|
if (unpack(file, p)) {
|
|
|
|
if (zip_game_dirname[0]) {
|
|
|
|
p = getpath(p, zip_game_dirname);
|
|
|
|
fprintf(stderr, "Cleaning: '%s'...\n", p);
|
|
|
|
remove_dir(p);
|
|
|
|
free(p);
|
|
|
|
}
|
2010-06-03 10:56:40 +03:00
|
|
|
return -1;
|
2010-06-04 10:27:10 +03:00
|
|
|
}
|
2010-06-03 10:56:40 +03:00
|
|
|
game_sw = zip_game_dirname;
|
|
|
|
games_sw = p;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-10 20:18:52 +03:00
|
|
|
#endif
|
2010-06-03 10:56:40 +03:00
|
|
|
|
2010-07-31 14:52:33 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
void macosx_init(void) {
|
|
|
|
char resourcePath[PATH_MAX];
|
|
|
|
CFBundleRef mainBundle;
|
|
|
|
CFURLRef resourcesDirectoryURL;
|
|
|
|
mainBundle = CFBundleGetMainBundle();
|
|
|
|
if (!mainBundle)
|
|
|
|
return;
|
|
|
|
resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
|
|
|
|
if (!resourcesDirectoryURL)
|
|
|
|
return;
|
|
|
|
CFURLGetFileSystemRepresentation(resourcesDirectoryURL, true, (UInt8 *) resourcePath, PATH_MAX);
|
|
|
|
CFRelease(resourcesDirectoryURL);
|
|
|
|
chdir(resourcePath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-10 13:06:30 +03:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
char *getcurdir(char *path)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
if (path == NULL || *path == '\0')
|
|
|
|
return ".";
|
|
|
|
p = path + strlen(path) - 1;
|
|
|
|
while (*p == '/') {
|
|
|
|
if (p == path)
|
|
|
|
return path;
|
|
|
|
*p-- = '\0';
|
|
|
|
}
|
|
|
|
while (p >= path && *p != '/')
|
|
|
|
p--;
|
|
|
|
return p < path ? "." : p == path ? "/" : (*p = '\0', path);
|
|
|
|
}
|
|
|
|
void wince_init(char *path)
|
|
|
|
{
|
|
|
|
unix_path(path);
|
|
|
|
strcpy(game_cwd, getcurdir(path));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-24 13:45:52 +03:00
|
|
|
int main(int argc, char *argv[])
|
2009-02-21 12:52:44 +02:00
|
|
|
{
|
2010-06-03 10:56:40 +03:00
|
|
|
int clean_tmp = 0;
|
2009-10-12 08:07:15 +03:00
|
|
|
int err = 0;
|
2009-08-26 08:25:53 +03:00
|
|
|
int i;
|
2010-07-31 14:52:33 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
macosx_init();
|
|
|
|
#endif
|
2010-06-02 14:33:40 +03:00
|
|
|
#ifdef _USE_GTK
|
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
#endif
|
2009-10-25 07:51:03 +02:00
|
|
|
putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */
|
2010-09-10 13:06:30 +03:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
wince_init(argv[0]);
|
|
|
|
#else
|
2010-06-05 12:13:06 +03:00
|
|
|
getcwd(game_cwd, sizeof(game_cwd));
|
2010-09-10 13:06:30 +03:00
|
|
|
#endif
|
2010-06-07 13:43:43 +03:00
|
|
|
unix_path(game_cwd);
|
2010-09-10 13:06:30 +03:00
|
|
|
setdir(game_cwd);
|
2009-08-26 08:25:53 +03:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i],"-alsa"))
|
|
|
|
alsa_sw = 1;
|
|
|
|
else if (!strcmp(argv[i], "-nosound"))
|
|
|
|
nosound_sw = 1;
|
|
|
|
else if (!strcmp(argv[i], "-fullscreen"))
|
|
|
|
fullscreen_sw = 1;
|
2009-10-24 18:57:08 +03:00
|
|
|
else if (!strcmp(argv[i], "-mode")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
mode_sw = argv[++i];
|
|
|
|
else
|
|
|
|
mode_sw = "-1x-1";
|
|
|
|
} else if (!strcmp(argv[i], "-window"))
|
2009-08-26 08:25:53 +03:00
|
|
|
window_sw = 1;
|
|
|
|
else if (!strcmp(argv[i], "-debug"))
|
|
|
|
debug_sw = 1;
|
2009-09-19 12:59:59 +03:00
|
|
|
else if (!strcmp(argv[i], "-noautosave"))
|
2010-09-10 13:06:30 +03:00
|
|
|
noauto_sw = 1;
|
2009-08-31 22:50:29 +03:00
|
|
|
else if (!strcmp(argv[i], "-game")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
game_sw = argv[++i];
|
|
|
|
else
|
|
|
|
game_sw = "";
|
2009-09-07 09:14:26 +03:00
|
|
|
} else if (!strcmp(argv[i], "-theme")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
theme_sw = argv[++i];
|
|
|
|
else
|
|
|
|
theme_sw = "";
|
2009-11-21 13:58:24 +02:00
|
|
|
} else if (!strcmp(argv[i], "-nostdgames")) {
|
|
|
|
nostdgames_sw = 1;
|
|
|
|
} else if (!strcmp(argv[i], "-nostdthemes")) {
|
|
|
|
nostdthemes_sw = 1;
|
2009-09-03 13:34:53 +03:00
|
|
|
} else if (!strcmp(argv[i], "-gamespath")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
games_sw = argv[++i];
|
|
|
|
else
|
|
|
|
games_sw = "";
|
|
|
|
} else if (!strcmp(argv[i], "-themespath")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
themes_sw = argv[++i];
|
|
|
|
else
|
|
|
|
themes_sw = "";
|
2009-10-12 08:07:15 +03:00
|
|
|
} else if (!strcmp(argv[i], "-encode")) {
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
encode_sw = argv[++i];
|
|
|
|
else {
|
|
|
|
fprintf(stderr,"No lua file specified.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((i + 1) < argc)
|
|
|
|
encode_output = argv[++i];
|
|
|
|
else
|
|
|
|
encode_output = "lua.enc";
|
2010-01-20 14:41:38 +02:00
|
|
|
} else if (!strcmp(argv[i], "-version")) {
|
|
|
|
version_sw = 1;
|
2010-03-12 20:06:15 +02:00
|
|
|
} else if (!strcmp(argv[i], "-nopause")) {
|
|
|
|
nopause_sw = 1;
|
2010-06-03 10:56:40 +03:00
|
|
|
#ifdef _USE_UNPACK
|
|
|
|
} else if (!strcmp(argv[i], "-install")) {
|
|
|
|
if ((i + 1) < argc) {
|
|
|
|
char *file = argv[++i];
|
|
|
|
char *p;
|
|
|
|
if (games_sw)
|
|
|
|
p = games_sw;
|
|
|
|
else
|
|
|
|
p = game_local_games_path(1);
|
2010-06-06 11:18:59 +03:00
|
|
|
if (setup_zip(file, p))
|
|
|
|
exit(1);
|
2010-06-03 10:56:40 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else if (!strcmp(argv[i], "-quit")) {
|
|
|
|
exit(0);
|
2010-01-24 15:14:32 +02:00
|
|
|
} else if (argv[i][0] == '-') {
|
2010-01-21 17:32:53 +02:00
|
|
|
fprintf(stderr,"Unknow option: %s\n", argv[i]);
|
|
|
|
exit(1);
|
2010-06-03 10:56:40 +03:00
|
|
|
}
|
2010-06-01 14:23:31 +03:00
|
|
|
#ifdef _USE_UNPACK
|
|
|
|
else {
|
|
|
|
char *p;
|
|
|
|
if (games_sw)
|
|
|
|
p = games_sw;
|
|
|
|
else
|
|
|
|
p = game_tmp_path();
|
2010-06-06 11:18:59 +03:00
|
|
|
if (setup_zip(argv[i], p))
|
|
|
|
exit(1);
|
2010-06-03 10:56:40 +03:00
|
|
|
clean_tmp = 1;
|
2009-10-12 08:07:15 +03:00
|
|
|
}
|
2010-06-01 14:23:31 +03:00
|
|
|
#endif
|
2010-01-20 14:41:38 +02:00
|
|
|
}
|
2009-09-03 13:34:53 +03:00
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
if (debug_sw) {
|
|
|
|
debug_init();
|
|
|
|
}
|
2010-01-20 14:41:38 +02:00
|
|
|
|
|
|
|
if (version_sw) {
|
|
|
|
fprintf(stdout, VERSION"\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-10-12 08:07:15 +03:00
|
|
|
if (encode_sw) {
|
|
|
|
err = instead_encode(encode_sw, encode_output);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-20 14:41:38 +02:00
|
|
|
|
2010-09-10 13:06:30 +03:00
|
|
|
menu_langs_lookup(dirpath(LANG_PATH));
|
2009-09-05 07:44:45 +03:00
|
|
|
|
|
|
|
if (!langs_nr) {
|
2010-10-07 09:53:15 +03:00
|
|
|
fprintf(stderr, "No languages found in: %s.\n", dirpath(LANG_PATH));
|
2009-09-05 07:44:45 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-11-20 09:54:50 +02:00
|
|
|
cfg_load();
|
|
|
|
|
|
|
|
if (!opt_lang || !opt_lang[0])
|
|
|
|
opt_lang = game_locale();
|
|
|
|
|
2009-11-20 10:14:33 +02:00
|
|
|
if (menu_lang_select(opt_lang) && menu_lang_select(LANG_DEF)) {
|
|
|
|
fprintf(stderr, "Can not load default language.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-09-03 13:34:53 +03:00
|
|
|
if (games_sw)
|
|
|
|
games_lookup(games_sw);
|
|
|
|
|
2010-09-10 13:06:30 +03:00
|
|
|
if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH)))
|
2009-11-21 13:58:24 +02:00
|
|
|
fprintf(stderr, "No games found in: %s.\n", GAMES_PATH);
|
|
|
|
|
2009-09-03 13:34:53 +03:00
|
|
|
if (themes_sw)
|
|
|
|
themes_lookup(themes_sw);
|
2009-11-21 13:58:24 +02:00
|
|
|
|
|
|
|
if (!nostdthemes_sw) {
|
2010-09-10 13:06:30 +03:00
|
|
|
themes_lookup(dirpath(THEMES_PATH));
|
2009-11-21 13:58:24 +02:00
|
|
|
themes_lookup(game_local_themes_path());
|
|
|
|
}
|
2009-08-26 08:25:53 +03:00
|
|
|
|
2009-11-21 13:58:24 +02:00
|
|
|
if (!nostdgames_sw)
|
2010-06-02 20:37:15 +03:00
|
|
|
games_lookup(game_local_games_path(0));
|
2009-09-03 13:34:53 +03:00
|
|
|
|
2009-09-19 12:59:59 +03:00
|
|
|
if (noauto_sw)
|
|
|
|
opt_autosave = 0;
|
2009-09-15 12:47:23 +03:00
|
|
|
if (window_sw)
|
|
|
|
opt_fs = 0;
|
|
|
|
if (fullscreen_sw)
|
|
|
|
opt_fs = 1;
|
|
|
|
|
2009-10-24 18:57:08 +03:00
|
|
|
if (mode_sw)
|
|
|
|
parse_mode(mode_sw, opt_mode);
|
2009-09-15 12:47:23 +03:00
|
|
|
|
2009-09-01 20:42:05 +03:00
|
|
|
if (game_sw) {
|
2009-09-07 09:14:26 +03:00
|
|
|
FREE(opt_game);
|
2009-08-31 22:50:29 +03:00
|
|
|
opt_game = game_sw;
|
2009-09-01 20:42:05 +03:00
|
|
|
}
|
2009-09-07 09:14:26 +03:00
|
|
|
|
|
|
|
if (theme_sw) {
|
|
|
|
FREE(opt_theme);
|
|
|
|
opt_theme = theme_sw;
|
|
|
|
}
|
2009-09-01 20:42:05 +03:00
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
if (opt_theme)
|
|
|
|
game_theme_select(opt_theme);
|
2009-09-05 07:44:45 +03:00
|
|
|
if (!curtheme_dir)
|
2009-11-12 22:23:26 +02:00
|
|
|
game_theme_select(DEFAULT_THEME);
|
2009-09-10 19:58:50 +03:00
|
|
|
|
|
|
|
// Initialize SDL
|
2009-09-10 20:07:32 +03:00
|
|
|
if (gfx_init() < 0)
|
2009-09-10 19:58:50 +03:00
|
|
|
return -1;
|
2009-08-26 08:25:53 +03:00
|
|
|
if (game_init(opt_game)) {
|
|
|
|
game_error(opt_game);
|
2009-02-21 12:52:44 +02:00
|
|
|
}
|
|
|
|
game_loop();
|
2009-08-26 08:25:53 +03:00
|
|
|
cfg_save();
|
2009-10-03 20:01:56 +03:00
|
|
|
game_done(0);
|
2010-11-04 17:01:34 +02:00
|
|
|
#ifndef ANDROID
|
2009-10-12 08:07:15 +03:00
|
|
|
gfx_done();
|
2010-11-04 17:01:34 +02:00
|
|
|
#endif
|
2009-10-12 08:07:15 +03:00
|
|
|
out:
|
2009-08-26 08:25:53 +03:00
|
|
|
if (debug_sw)
|
|
|
|
debug_done();
|
2010-06-02 15:41:36 +03:00
|
|
|
#ifdef _USE_GTK
|
2010-06-08 19:17:08 +03:00
|
|
|
/* gtk_main_quit (); */
|
2010-06-03 10:56:40 +03:00
|
|
|
#endif
|
|
|
|
#ifdef _USE_UNPACK
|
|
|
|
if (clean_tmp)
|
|
|
|
remove_dir(game_tmp_path());
|
2010-11-05 11:27:06 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ANDROID
|
2010-11-05 11:50:25 +02:00
|
|
|
exit(err);
|
2010-06-02 15:41:36 +03:00
|
|
|
#endif
|
2009-10-12 08:07:15 +03:00
|
|
|
return err;
|
2009-02-21 12:52:44 +02:00
|
|
|
}
|
2009-08-26 08:25:53 +03:00
|
|
|
|