It's working! Hooray!

This commit is contained in:
Alexander Yakovlev 2011-09-03 17:41:22 +07:00
parent a3496fe02e
commit 0b7d72ebdd
4 changed files with 343 additions and 303 deletions

View file

@ -189,11 +189,11 @@ if [ "x$ans" = "x1" -o "x$ans" = "x" ]; then
echo " * Standalone version" echo " * Standalone version"
rm -f Rules.make rm -f Rules.make
ln -sf Rules.make.standalone Rules.make ln -sf Rules.make.standalone Rules.make
rm -f sdl-instead rm -f steed
ln -sf src/sdl-instead/sdl-instead sdl-instead ln -sf src/sdl-instead/sdl-instead steed
echo "Ok. We are ready to build. Use these commands:" echo "Ok. We are ready to build. Use these commands:"
echo " \$ make" echo " \$ make"
echo " \$ ./sdl-instead" echo " \$ ./steed"
elif [ "x$ans" = "x2" ]; then elif [ "x$ans" = "x2" ]; then
echo -n "Enter prefix path [/usr/local]: " echo -n "Enter prefix path [/usr/local]: "
read ans read ans
@ -223,7 +223,7 @@ elif [ "x$ans" = "x2" ]; then
echo "Ok. We are ready to build and install. Use these commands:" echo "Ok. We are ready to build and install. Use these commands:"
echo " \$ make" echo " \$ make"
echo " \$ sudo make install" echo " \$ sudo make install"
echo " \$ sdl-instead" echo " \$ steed"
else else
echo "Huh!!! Wrong answer." echo "Huh!!! Wrong answer."
exit 1 exit 1

View file

@ -1 +0,0 @@
src/sdl-instead/sdl-instead

View file

@ -21,12 +21,10 @@ sdl-instead$(EXE): $(OBJ) $(RESOURCES)
install: install:
$(INSTALLD) $(BIN) $(INSTALLD) $(BIN)
$(INSTALLB) sdl-instead$(EXE) $(BIN)/sdl-instead$(EXE) $(INSTALLB) sdl-instead$(EXE) $(BIN)/steed$(EXE)
$(LN) sdl-instead$(EXE) $(BIN)/instead$(EXE)
uninstall: uninstall:
$(RM) $(BIN)/sdl-instead$(EXE) $(RM) $(BIN)/steed$(EXE)
$(RM) $(BIN)/instead$(EXE)
clean: clean:
$(RM) -f *.o sdl-instead$(EXE) $(RM) -f *.o sdl-instead$(EXE)

View file

@ -19,7 +19,7 @@
#endif #endif
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
extern void libwince_init(const char* prog, int debug); extern void libwince_init(const char* prog, int debug);
#endif #endif
extern int debug_init(void); extern int debug_init(void);
@ -46,374 +46,417 @@ char *start_idf_sw = NULL;
extern int unpack(const char *zipfilename, const char *where); extern int unpack(const char *zipfilename, const char *where);
extern char zip_game_dirname[]; extern char zip_game_dirname[];
static void
get_url (const char *url, const char *outfile)
{
const char *name;
static SoupSession *session;
SoupMessage *msg;
const char *header;
session = soup_session_sync_new_with_options (
SOUP_SESSION_SSL_CA_FILE, NULL,
SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_COOKIE_JAR,
SOUP_SESSION_USER_AGENT, "get ",
SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE,
NULL);
msg = soup_message_new (SOUP_METHOD_GET, url);
soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
soup_session_send_message (session, msg);
name = soup_message_get_uri (msg)->path;
if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
header = soup_message_headers_get_one (msg->response_headers,
"Location");
if (header) {
SoupURI *uri;
char *uri_string;
uri = soup_uri_new_with_base (soup_message_get_uri (msg), header);
uri_string = soup_uri_to_string (uri, FALSE);
get_url (uri_string,outfile);
g_free (uri_string);
soup_uri_free (uri);
}
} else if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
//FILE * temp = fopen(outfile,"w");
//fwrite (msg->response_body->data, 1, msg->response_body->length, temp);
int fd = open (outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
write (fd, msg->response_body->data, msg->response_body->length);
close (fd);
//fclose(temp);
}
}
static int setup_zip(const char *file, char *p) static int setup_zip(const char *file, char *p)
{ {
if (!p) if (!p) return -1;
return -1;
#ifdef _USE_HTTP #ifdef _USE_HTTP
SoupSession * soup_session = soup_session_sync_new (); SoupURI * parsed = soup_uri_new (file);
SoupMessage * msg; if (parsed){
int fd; char * outfile = game_tmp_path();
if (soup_uri_new (file)){ strcat(outfile,"/temp_download.zip");
msg = soup_message_new ("GET", file); get_url(file,outfile);
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) return -2; file = outfile;
sprintf(file,"%s/temp_download.zip",p); }
fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0644); soup_uri_free (parsed);
write (fd, msg->response_body, msg->response_body->length);
}
#endif #endif
fprintf(stderr,"Trying to install: %s\n", file); fprintf(stderr,"Trying to install: %s\n", file);
if (unpack(file, p)) { if (unpack(file, p)) {
if (zip_game_dirname[0]) { if (zip_game_dirname[0]) {
p = getpath(p, zip_game_dirname); p = getpath(p, zip_game_dirname);
fprintf(stderr, "Cleaning: '%s'...\n", p); fprintf(stderr, "Cleaning: '%s'...\n", p);
remove_dir(p); remove_dir(p);
free(p); free(p);
} }
return -1; return -1;
} }
game_sw = zip_game_dirname; game_sw = zip_game_dirname;
games_sw = p; games_sw = p;
return 0; return 0;
} }
#endif #endif
static int start_idf(char *file) static int start_idf(char *file)
{ {
if (!file) if (!file)
return -1; return -1;
if (!idf_magic(file)) if (!idf_magic(file))
return -1; return -1;
start_idf_sw = file; start_idf_sw = file;
return 0; return 0;
} }
#ifdef __APPLE__ #ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
void macosx_init(void) { void macosx_init(void) {
char resourcePath[PATH_MAX]; char resourcePath[PATH_MAX];
CFBundleRef mainBundle; CFBundleRef mainBundle;
CFURLRef resourcesDirectoryURL; CFURLRef resourcesDirectoryURL;
mainBundle = CFBundleGetMainBundle(); mainBundle = CFBundleGetMainBundle();
if (!mainBundle) if (!mainBundle)
return; return;
resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle); resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
if (!resourcesDirectoryURL) if (!resourcesDirectoryURL)
return; return;
CFURLGetFileSystemRepresentation(resourcesDirectoryURL, true, (UInt8 *) resourcePath, PATH_MAX); CFURLGetFileSystemRepresentation(resourcesDirectoryURL, true, (UInt8 *) resourcePath, PATH_MAX);
CFRelease(resourcesDirectoryURL); CFRelease(resourcesDirectoryURL);
chdir(resourcePath); chdir(resourcePath);
return; return;
} }
#endif #endif
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
char *getcurdir(char *path) char *getcurdir(char *path)
{ {
char *p; char *p;
if (path == NULL || *path == '\0') if (path == NULL || *path == '\0')
return "."; return ".";
p = path + strlen(path) - 1; p = path + strlen(path) - 1;
while (*p == '/') { while (*p == '/') {
if (p == path) if (p == path)
return path; return path;
*p-- = '\0'; *p-- = '\0';
} }
while (p >= path && *p != '/') while (p >= path && *p != '/')
p--; p--;
return p < path ? "." : p == path ? "/" : (*p = '\0', path); return p < path ? "." : p == path ? "/" : (*p = '\0', path);
} }
void wince_init(char *path) void wince_init(char *path)
{ {
unix_path(path); unix_path(path);
strcpy(game_cwd, getcurdir(path)); strcpy(game_cwd, getcurdir(path));
} }
#endif #endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int clean_tmp = 0; int clean_tmp = 0;
int err = 0; int err = 0;
int i; int i;
#ifdef __APPLE__ #ifdef __APPLE__
macosx_init(); macosx_init();
#endif #endif
#ifdef _USE_GTK #ifdef _USE_GTK
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
#endif #endif
#ifndef S60 #ifndef S60
putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */ putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */
#endif #endif
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
libwince_init(argv[0], 1); libwince_init(argv[0], 1);
wince_init(argv[0]); wince_init(argv[0]);
#else #else
#ifdef S60 #ifdef S60
extern char s60_data[]; extern char s60_data[];
strcpy(game_cwd, s60_data); strcpy(game_cwd, s60_data);
#else #else
#ifdef _WIN32 #ifdef _WIN32
strcpy(game_cwd, dirname(argv[0])); strcpy(game_cwd, dirname(argv[0]));
#else #else
getcwd(game_cwd, sizeof(game_cwd)); getcwd(game_cwd, sizeof(game_cwd));
#endif #endif
#endif #endif
#endif #endif
unix_path(game_cwd); unix_path(game_cwd);
setdir(game_cwd); setdir(game_cwd);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (!strcmp(argv[i],"-alsa")) if (!strcmp(argv[i],"-alsa"))
alsa_sw = 1; alsa_sw = 1;
else if (!strcmp(argv[i], "-nosound")) else if (!strcmp(argv[i], "-nosound"))
nosound_sw = 1; nosound_sw = 1;
else if (!strcmp(argv[i], "-fullscreen")) else if (!strcmp(argv[i], "-fullscreen"))
fullscreen_sw = 1; fullscreen_sw = 1;
else if (!strcmp(argv[i], "-mode")) { else if (!strcmp(argv[i], "-mode")) {
if ((i + 1) < argc) if ((i + 1) < argc)
mode_sw = argv[++i]; mode_sw = argv[++i];
else else
mode_sw = "-1x-1"; mode_sw = "-1x-1";
} else if (!strcmp(argv[i], "-window")) } else if (!strcmp(argv[i], "-window"))
window_sw = 1; window_sw = 1;
else if (!strcmp(argv[i], "-debug")) else if (!strcmp(argv[i], "-debug"))
debug_sw = 1; debug_sw = 1;
else if (!strcmp(argv[i], "-noautosave")) else if (!strcmp(argv[i], "-noautosave"))
noauto_sw = 1; noauto_sw = 1;
else if (!strcmp(argv[i], "-game")) { else if (!strcmp(argv[i], "-game")) {
if ((i + 1) < argc) if ((i + 1) < argc)
game_sw = argv[++i]; game_sw = argv[++i];
else else
game_sw = ""; game_sw = "";
} else if (!strcmp(argv[i], "-theme")) { } else if (!strcmp(argv[i], "-theme")) {
if ((i + 1) < argc) if ((i + 1) < argc)
theme_sw = argv[++i]; theme_sw = argv[++i];
else else
theme_sw = ""; theme_sw = "";
} else if (!strcmp(argv[i], "-nostdgames")) { } else if (!strcmp(argv[i], "-nostdgames")) {
nostdgames_sw = 1; nostdgames_sw = 1;
#ifdef _LOCAL_APPDATA #ifdef _LOCAL_APPDATA
} else if (!strcmp(argv[i], "-appdata")) { } else if (!strcmp(argv[i], "-appdata")) {
if ((i + 1) < argc) if ((i + 1) < argc)
appdata_sw = argv[++i]; appdata_sw = argv[++i];
else else
appdata_sw = ""; appdata_sw = "";
#endif #endif
} else if (!strcmp(argv[i], "-chunksize")) { } else if (!strcmp(argv[i], "-chunksize")) {
if ((i + 1) < argc) if ((i + 1) < argc)
chunksize_sw = atoi(argv[++i]); chunksize_sw = atoi(argv[++i]);
else else
chunksize_sw = DEFAULT_CHUNKSIZE; chunksize_sw = DEFAULT_CHUNKSIZE;
} else if (!strcmp(argv[i], "-gamespath")) { } else if (!strcmp(argv[i], "-gamespath")) {
if ((i + 1) < argc) if ((i + 1) < argc)
games_sw = argv[++i]; games_sw = argv[++i];
else else
games_sw = ""; games_sw = "";
} else if (!strcmp(argv[i], "-themespath")) { } else if (!strcmp(argv[i], "-themespath")) {
if ((i + 1) < argc) if ((i + 1) < argc)
themes_sw = argv[++i]; themes_sw = argv[++i];
else else
themes_sw = ""; themes_sw = "";
} else if (!strcmp(argv[i], "-idf")) { } else if (!strcmp(argv[i], "-idf")) {
if ((i + 1) < argc) if ((i + 1) < argc)
idf_sw = argv[++i]; idf_sw = argv[++i];
else { else {
fprintf(stderr,"No data directory specified.\n"); fprintf(stderr,"No data directory specified.\n");
exit(1); exit(1);
} }
} else if (!strcmp(argv[i], "-encode")) { } else if (!strcmp(argv[i], "-encode")) {
if ((i + 1) < argc) if ((i + 1) < argc)
encode_sw = argv[++i]; encode_sw = argv[++i];
else { else {
fprintf(stderr,"No lua file specified.\n"); fprintf(stderr,"No lua file specified.\n");
exit(1); exit(1);
} }
if ((i + 1) < argc) if ((i + 1) < argc)
encode_output = argv[++i]; encode_output = argv[++i];
else else
encode_output = "lua.enc"; encode_output = "lua.enc";
} else if (!strcmp(argv[i], "-version")) { } else if (!strcmp(argv[i], "-version")) {
version_sw = 1; version_sw = 1;
} else if (!strcmp(argv[i], "-nopause")) { } else if (!strcmp(argv[i], "-nopause")) {
nopause_sw = 1; nopause_sw = 1;
#ifdef _USE_UNPACK #ifdef _USE_UNPACK
} else if (!strcmp(argv[i], "-install")) { } else if (!strcmp(argv[i], "-install")) {
if ((i + 1) < argc) { if ((i + 1) < argc) {
char *file = argv[++i]; char *file = argv[++i];
char *p; char *p;
if (games_sw) if (games_sw)
p = games_sw; p = games_sw;
else else
p = game_local_games_path(1); p = game_local_games_path(1);
if (setup_zip(file, p)) if (setup_zip(file, p))
exit(1); exit(1);
} }
#endif #endif
} else if (!strcmp(argv[i], "-quit")) { } else if (!strcmp(argv[i], "-quit")) {
exit(0); exit(0);
} else if (argv[i][0] == '-') { } else if (argv[i][0] == '-') {
fprintf(stderr,"Unknown option: %s\n", argv[i]); fprintf(stderr,"Unknown option: %s\n", argv[i]);
exit(1); exit(1);
} }
else if (!start_idf(argv[i])) { else if (!start_idf(argv[i])) {
fprintf(stderr, "Adding idf: %s\n", argv[i]); fprintf(stderr, "Adding idf: %s\n", argv[i]);
} }
#ifdef _USE_UNPACK #ifdef _USE_UNPACK
else { else {
char *p; char *p;
if (games_sw) if (games_sw)
p = games_sw; p = games_sw;
else else
p = game_tmp_path(); p = game_tmp_path();
if (setup_zip(argv[i], p)) if (setup_zip(argv[i], p))
exit(1); exit(1);
clean_tmp = 1; clean_tmp = 1;
} }
#endif #endif
} }
if (debug_sw) { if (debug_sw) {
debug_init(); debug_init();
} }
if (version_sw) { if (version_sw) {
fprintf(stdout, VERSION"\n"); fprintf(stdout, VERSION"\n");
goto out; goto out;
} }
if (encode_sw) { if (encode_sw) {
err = instead_encode(encode_sw, encode_output); err = instead_encode(encode_sw, encode_output);
goto out; goto out;
} }
if (idf_sw) { if (idf_sw) {
char *p = malloc(strlen(idf_sw) + 5); char *p = malloc(strlen(idf_sw) + 5);
if (p) { if (p) {
char *b; char *b;
strcpy(p, idf_sw); strcpy(p, idf_sw);
b = basename(p); b = basename(p);
strcat(b, ".idf"); strcat(b, ".idf");
idf_create(b, idf_sw); idf_create(b, idf_sw);
free(p); free(p);
} else } else
idf_create("data.idf", idf_sw); idf_create("data.idf", idf_sw);
goto out; goto out;
} }
menu_langs_lookup(dirpath(LANG_PATH)); menu_langs_lookup(dirpath(LANG_PATH));
if (!langs_nr) { if (!langs_nr) {
fprintf(stderr, "No languages found in: %s.\n", dirpath(LANG_PATH)); fprintf(stderr, "No languages found in: %s.\n", dirpath(LANG_PATH));
exit(1); exit(1);
} }
cfg_load(); cfg_load();
if (!opt_lang || !opt_lang[0]) if (!opt_lang || !opt_lang[0])
opt_lang = game_locale(); opt_lang = game_locale();
if (menu_lang_select(opt_lang) && menu_lang_select(LANG_DEF)) { if (menu_lang_select(opt_lang) && menu_lang_select(LANG_DEF)) {
fprintf(stderr, "Can not load default language.\n"); fprintf(stderr, "Can not load default language.\n");
exit(1); exit(1);
} }
if (games_sw) if (games_sw)
games_lookup(games_sw); games_lookup(games_sw);
if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH))) if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH)))
fprintf(stderr, "No games found in: %s.\n", GAMES_PATH); fprintf(stderr, "No games found in: %s.\n", GAMES_PATH);
if (themes_sw) if (themes_sw)
themes_lookup(themes_sw); themes_lookup(themes_sw);
if (!nostdthemes_sw) { if (!nostdthemes_sw) {
themes_lookup(dirpath(THEMES_PATH)); themes_lookup(dirpath(THEMES_PATH));
themes_lookup(game_local_themes_path()); themes_lookup(game_local_themes_path());
} }
if (!nostdgames_sw) if (!nostdgames_sw)
games_lookup(game_local_games_path(0)); games_lookup(game_local_games_path(0));
if (start_idf_sw) { if (start_idf_sw) {
char *d, *b; char *d, *b;
char *dd, *bb; char *dd, *bb;
static char idf_game[255]; static char idf_game[255];
d = strdup(start_idf_sw); d = strdup(start_idf_sw);
b = strdup(start_idf_sw); b = strdup(start_idf_sw);
if (d && b) { if (d && b) {
dd = dirname(d); dd = dirname(d);
bb = basename(b); bb = basename(b);
if (!games_replace(dirpath(dd), bb)) { if (!games_replace(dirpath(dd), bb)) {
game_sw = idf_game; game_sw = idf_game;
strncpy(idf_game, bb, sizeof(idf_game) - 1); strncpy(idf_game, bb, sizeof(idf_game) - 1);
idf_game[sizeof(idf_game) - 1] = 0; idf_game[sizeof(idf_game) - 1] = 0;
} }
} }
if (d) if (d)
free(d); free(d);
if (b) if (b)
free(b); free(b);
} }
if (noauto_sw) if (noauto_sw)
opt_autosave = 0; opt_autosave = 0;
if (window_sw) if (window_sw)
opt_fs = 0; opt_fs = 0;
if (fullscreen_sw) if (fullscreen_sw)
opt_fs = 1; opt_fs = 1;
if (mode_sw) if (mode_sw)
parse_mode(mode_sw, opt_mode); parse_mode(mode_sw, opt_mode);
if (game_sw) { if (game_sw) {
FREE(opt_game); FREE(opt_game);
opt_game = game_sw; opt_game = game_sw;
} }
if (theme_sw) { if (theme_sw) {
FREE(opt_theme); FREE(opt_theme);
opt_theme = theme_sw; opt_theme = theme_sw;
} }
if (opt_theme) if (opt_theme)
game_theme_select(opt_theme); game_theme_select(opt_theme);
if (!curtheme_dir) if (!curtheme_dir)
game_theme_select(DEFAULT_THEME); game_theme_select(DEFAULT_THEME);
// Initialize SDL // Initialize SDL
if (gfx_init() < 0) if (gfx_init() < 0)
return -1; return -1;
if (gfx_video_init() || input_init()) if (gfx_video_init() || input_init())
return -1; return -1;
if (game_init(opt_game)) { if (game_init(opt_game)) {
game_error(opt_game); game_error(opt_game);
} }
game_loop(); game_loop();
cfg_save(); cfg_save();
game_done(0); game_done(0);
gfx_video_done(); gfx_video_done();
#ifndef ANDROID #ifndef ANDROID
gfx_done(); gfx_done();
#endif #endif
out: out:
if (debug_sw) if (debug_sw)
debug_done(); debug_done();
#ifdef _USE_GTK #ifdef _USE_GTK
/* gtk_main_quit (); */ /* gtk_main_quit (); */
#endif #endif
#ifdef _USE_UNPACK #ifdef _USE_UNPACK
if (clean_tmp) if (clean_tmp)
remove_dir(game_tmp_path()); remove_dir(game_tmp_path());
#endif #endif
#ifdef ANDROID #ifdef ANDROID
exit(err); exit(err);
#endif #endif
return err; return err;
} }