113 #define STRATAGUS_BIN
116 #if ! defined (GAME_NAME) || ! defined (GAME_CD) || ! defined (GAME)
117 #error You need to define all Game macros, see stratagus-game-launcher.h
120 #if ( defined (_MSC_VER) || defined (_WIN32) || defined (_WIN64) ) && ! defined (WIN32)
125 #if ! defined (DATA_PATH) || ! defined (SCRIPTS_PATH) || ! defined (STRATAGUS_BIN)
126 #error You need to define paths, see stratagus-game-launcher.h
130 #if ( defined (MAEMO_GTK) || defined (MAEMO_CHANGES) ) && ! defined (MAEMO)
135 #define WINVER 0x0501
146 #include <sys/stat.h>
147 #include <sys/types.h>
149 #if defined(_MSC_VER) || defined(__MINGW32__)
151 #define inline __inline
153 #define getcwd _getcwd
154 #define spawnvp _spawnvp
160 #include <X11/Xlib.h>
165 #include <hildon/hildon.h>
169 #define REGKEY "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Stratagus (64 bit)"
170 #elif defined (WIN32)
171 #define REGKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Stratagus"
174 #define TITLE GAME_NAME
175 #define STRATAGUS_NOT_FOUND "Stratagus is not installed.\nYou need Stratagus to run " GAME_NAME "!\nFirst install Stratagus from https://launchpad.net/stratagus"
176 #define DATA_NOT_EXTRACTED GAME_NAME " data was not extracted yet.\nYou need extract data from original " GAME_CD " first!"
177 #define NO_X_DISPLAY "Cannot open X Display"
178 #define CONSOLE_MODE_NOT_ROOT "You must be root to run " GAME_NAME " in console framebuffer mode"
180 #define BUFF_SIZE 1024
186 static void error(
char * title,
char * text) {
189 MessageBox(NULL, text, title, MB_OK | MB_ICONERROR);
191 if ( ! ConsoleMode ) {
192 GtkWidget * window = NULL;
193 GtkWidget * dialog = NULL;
196 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
197 gtk_window_set_title(GTK_WINDOW(window), title);
198 gtk_widget_show(window);
201 dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
"%s", text);
202 gtk_window_set_title(GTK_WINDOW(dialog), title);
203 gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), 0);
204 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), 0);
205 gtk_label_set_selectable(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), 0);
206 gtk_dialog_run(GTK_DIALOG(dialog));
207 gtk_widget_destroy(dialog);
210 gtk_widget_destroy(window);
213 fprintf(stderr,
"%s -- Error: %s\n", title, text);
219 int main(
int argc,
char * argv[]) {
222 if ( ! XOpenDisplay(NULL) ) {
229 if ( getuid() != 0 ) {
234 gtk_init(&argc, &argv);
249 memset(executable_path, 0,
sizeof(executable_path));
250 GetModuleFileName(NULL, executable_path,
sizeof(executable_path)-1);
252 char executable_drive[_MAX_DRIVE];
253 char executable_dir[_MAX_DIR];
254 memset(executable_drive, 0,
sizeof(executable_drive));
255 memset(executable_dir, 0,
sizeof(executable_dir));
256 _splitpath(executable_path, executable_drive, executable_dir, NULL, NULL);
258 size_t data_path_size =
sizeof(data_path);
259 memset(data_path, 0, data_path_size);
261 if (executable_path[0] && executable_drive[0] && executable_dir[0]) {
262 strcpy(data_path, executable_drive);
263 strcpy(data_path+strlen(executable_drive), executable_dir);
265 getcwd(data_path, data_path_size);
267 const size_t data_path_length = strlen(data_path);
268 if (data_path_length != 0 && data_path[data_path_length - 1] ==
'\\') {
269 data_path[data_path_length - 1] =
'\0';
273 DWORD stratagus_path_size =
sizeof(stratagus_path);
274 memset(stratagus_path, 0, stratagus_path_size);
277 if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
REGKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS ) {
278 if ( RegQueryValueEx(key,
"InstallLocation", NULL, NULL, (LPBYTE) stratagus_path, &stratagus_path_size) == ERROR_SUCCESS ) {
279 if ( stratagus_path_size == 0 || strlen(stratagus_path) == 0 ) {
286 if ( chdir(stratagus_path) != 0 ) {
289 sprintf(scripts_path,
"\"%s\"", data_path);
290 sprintf(stratagus_bin,
"%s\\stratagus.exe", stratagus_path);
297 if ( stat(stratagus_bin, &st) != 0 ) {
300 if ( stat(data_path, &st) != 0 ) {
304 sprintf(title_path,
"%s\\graphics\\ui\\title.png", data_path);
306 int data_path_len = strlen(data_path);
308 for (
int i = data_path_len - 1; i >= 0; --i) {
309 data_path[i + 1] = data_path[i];
312 data_path[data_path_len + 1] =
'"';
313 data_path[data_path_len + 2] = 0;
315 sprintf(title_path,
"%s/graphics/ui/title.png", data_path);
318 if ( stat(title_path, &st) != 0 ) {
322 if ( strcmp(data_path, scripts_path) != 0 ) {
323 if ( chdir(data_path) != 0 ) {
330 char** stratagus_argv;
331 stratagus_argv = (
char**) malloc((argc + 3) *
sizeof (*stratagus_argv));
333 char * stratagus_argv[argc + 3];
338 memset(stratagus_argv0_esc, 0,
sizeof(stratagus_argv0_esc));
339 strcpy(stratagus_argv0_esc + 1, argv[0]);
340 stratagus_argv0_esc[0] =
'"';
341 stratagus_argv0_esc[strlen(argv[0]) + 1] =
'"';
342 stratagus_argv0_esc[strlen(argv[0]) + 2] = 0;
343 stratagus_argv[0] = stratagus_argv0_esc;
345 stratagus_argv[0] = argv[0];
348 stratagus_argv[1] =
"-d";
349 stratagus_argv[2] = scripts_path;
351 for (
int i = 3; i < argc + 2; ++i ) {
352 stratagus_argv[i] = argv[i - 2];
354 stratagus_argv[argc + 2] = NULL;
357 AttachConsole(ATTACH_PARENT_PROCESS);
360 int ret = spawnvp(_P_WAIT, stratagus_bin, stratagus_argv);
362 free (stratagus_argv);
368 execvp(stratagus_bin, stratagus_argv);
#define CONSOLE_MODE_NOT_ROOT
Definition: stratagus-game-launcher.h:178
#define REGKEY
Definition: stratagus-game-launcher.h:171
#define SCRIPTS_PATH
Definition: stratagus-game-launcher.h:112
#define STRATAGUS_NOT_FOUND
Definition: stratagus-game-launcher.h:175
#define DATA_NOT_EXTRACTED
Definition: stratagus-game-launcher.h:176
#define BUFF_SIZE
Definition: stratagus-game-launcher.h:180
#define STRATAGUS_BIN
Definition: stratagus-game-launcher.h:113
int main(int argc, char *argv[])
Definition: stratagus-game-launcher.h:219
#define DATA_PATH
Definition: stratagus-game-launcher.h:111
#define TITLE
Definition: stratagus-game-launcher.h:174
#define NO_X_DISPLAY
Definition: stratagus-game-launcher.h:177
static void error(char *title, char *text)
Definition: stratagus-game-launcher.h:186