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)
130 #define TITLE_PNG "%s\\graphics\\ui\\title.png"
132 #define TITLE_PNG "%s/graphics/ui/title.png"
137 #if ! defined (DATA_PATH) || ! defined (SCRIPTS_PATH) || ! defined (STRATAGUS_BIN)
138 #error You need to define paths, see stratagus-game-launcher.h
143 #define WINVER 0x0501
154 #include <sys/stat.h>
155 #include <sys/types.h>
157 #if defined(_MSC_VER) || defined(__MINGW32__)
159 #define inline __inline
161 #define getcwd _getcwd
162 #define spawnvp _spawnvp
167 #pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
172 #include <X11/Xlib.h>
179 #define REGKEY "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Stratagus (64 bit)"
180 #elif defined (WIN32)
181 #define REGKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Stratagus"
184 #define TITLE GAME_NAME
185 #define STRATAGUS_NOT_FOUND "Stratagus is not installed.\nYou need Stratagus to run " GAME_NAME "!\nFirst install Stratagus from https://launchpad.net/stratagus"
186 #define DATA_NOT_EXTRACTED GAME_NAME " data was not extracted yet.\nYou need extract data from original " GAME_CD " first!"
187 #define NO_X_DISPLAY "Cannot open X Display"
188 #define CONSOLE_MODE_NOT_ROOT "You must be root to run " GAME_NAME " in console framebuffer mode"
190 #define BUFF_SIZE 1024
196 static void error(
char * title,
char * text) {
199 MessageBox(NULL, text, title, MB_OK | MB_ICONERROR);
204 if ( ! ConsoleMode ) {
205 GtkWidget * window = NULL;
206 GtkWidget * dialog = NULL;
208 dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
"%s", text);
209 gtk_window_set_title(GTK_WINDOW(dialog), title);
210 gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), 0);
211 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), 0);
212 gtk_label_set_selectable(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), 0);
213 gtk_dialog_run(GTK_DIALOG(dialog));
214 gtk_widget_destroy(dialog);
218 fprintf(stderr,
"%s -- Error: %s\n", title, text);
224 int main(
int argc,
char * argv[]) {
227 if ( ! XOpenDisplay(NULL) ) {
230 if ( !ConsoleMode ) {
232 gtk_init(&argc, &argv);
245 memset(executable_path, 0,
sizeof(executable_path));
246 GetModuleFileName(NULL, executable_path,
sizeof(executable_path)-1);
248 char executable_drive[_MAX_DRIVE];
249 char executable_dir[_MAX_DIR];
250 memset(executable_drive, 0,
sizeof(executable_drive));
251 memset(executable_dir, 0,
sizeof(executable_dir));
252 _splitpath(executable_path, executable_drive, executable_dir, NULL, NULL);
254 size_t data_path_size =
sizeof(data_path);
255 memset(data_path, 0, data_path_size);
257 if (executable_path[0] && executable_drive[0] && executable_dir[0]) {
258 strcpy(data_path, executable_drive);
259 strcpy(data_path+strlen(executable_drive), executable_dir);
261 getcwd(data_path, data_path_size);
263 const size_t data_path_length = strlen(data_path);
264 if (data_path_length != 0 && data_path[data_path_length - 1] ==
'\\') {
265 data_path[data_path_length - 1] =
'\0';
267 sprintf(scripts_path,
"\"%s\"", data_path);
272 sprintf(stratagus_bin,
"%s\\stratagus.exe", data_path);
273 if (stat(stratagus_bin, &st) != 0) {
275 DWORD stratagus_path_size =
sizeof(stratagus_path);
276 memset(stratagus_path, 0, stratagus_path_size);
279 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
REGKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
280 if (RegQueryValueEx(key,
"InstallLocation", NULL, NULL, (LPBYTE)stratagus_path, &stratagus_path_size) == ERROR_SUCCESS) {
281 if (stratagus_path_size == 0 || strlen(stratagus_path) == 0) {
288 if (chdir(stratagus_path) != 0) {
291 sprintf(stratagus_bin,
"%s\\stratagus.exe", stratagus_path);
299 if ( stat(stratagus_bin, &st) != 0 ) {
302 if ( stat(data_path, &st) != 0 ) {
305 sprintf(title_path,
TITLE_PNG, data_path);
307 int data_path_len = strlen(data_path);
309 for (
int i = data_path_len - 1; i >= 0; --i) {
310 data_path[i + 1] = data_path[i];
313 data_path[data_path_len + 1] =
'"';
314 data_path[data_path_len + 2] = 0;
317 if ( stat(title_path, &st) != 0 ) {
321 if ( strcmp(data_path, scripts_path) != 0 ) {
322 if ( chdir(data_path) != 0 ) {
329 char** stratagus_argv;
330 stratagus_argv = (
char**) malloc((argc + 3) *
sizeof (*stratagus_argv));
332 char * stratagus_argv[argc + 3];
337 memset(stratagus_argv0_esc, 0,
sizeof(stratagus_argv0_esc));
338 strcpy(stratagus_argv0_esc + 1, argv[0]);
339 stratagus_argv0_esc[0] =
'"';
340 stratagus_argv0_esc[strlen(argv[0]) + 1] =
'"';
341 stratagus_argv0_esc[strlen(argv[0]) + 2] = 0;
342 stratagus_argv[0] = stratagus_argv0_esc;
344 stratagus_argv[0] = argv[0];
347 stratagus_argv[1] =
"-d";
348 stratagus_argv[2] = scripts_path;
350 for (
int i = 3; i < argc + 2; ++i ) {
351 stratagus_argv[i] = argv[i - 2];
353 stratagus_argv[argc + 2] = NULL;
356 AttachConsole(ATTACH_PARENT_PROCESS);
359 int ret = spawnvp(_P_WAIT, stratagus_bin, stratagus_argv);
361 free (stratagus_argv);
367 execvp(stratagus_bin, stratagus_argv);
#define REGKEY
Definition: stratagus-game-launcher.h:181
#define SCRIPTS_PATH
Definition: stratagus-game-launcher.h:112
#define STRATAGUS_NOT_FOUND
Definition: stratagus-game-launcher.h:185
#define DATA_NOT_EXTRACTED
Definition: stratagus-game-launcher.h:186
#define BUFF_SIZE
Definition: stratagus-game-launcher.h:190
#define STRATAGUS_BIN
Definition: stratagus-game-launcher.h:113
#define TITLE_PNG
Definition: stratagus-game-launcher.h:130
int main(int argc, char *argv[])
Definition: stratagus-game-launcher.h:224
#define DATA_PATH
Definition: stratagus-game-launcher.h:111
#define TITLE
Definition: stratagus-game-launcher.h:184
static void error(char *title, char *text)
Definition: stratagus-game-launcher.h:196