$treeview $search $mathjax
Stratagus
2.2.6
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 /* 00002 _________ __ __ 00003 / _____// |_____________ _/ |______ ____ __ __ ______ 00004 \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00005 / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00006 /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00007 \/ \/ \//_____/ \/ 00008 ______________________ ______________________ 00009 T H E W A R B E G I N S 00010 Stratagus - A free fantasy real time strategy game engine 00011 00012 stratagus-maemo-extract.h - Stratagus Game data extractor for Maemo 00013 Copyright (C) 2010-2011 Pali Rohár <pali.rohar@gmail.com> 00014 00015 This program is free software: you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation, either version 2 of the License, or 00018 (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program. If not, see <http://www.gnu.org/licenses/>. 00027 00028 */ 00029 00114 /* Fake definitions for Doxygen */ 00115 #ifdef DOXYGEN 00116 #define GAME_NAME 00117 #define GAME_CD 00118 #define GAME_CD_DIR 00119 #define GAME_CD_FILE 00120 #define GAME 00121 #define EXTRACT_BIN 00122 #define EXTRACT_COMMAND 00123 #define EXTRACT_INFO 00124 #endif 00125 00126 #if ! defined (GAME_NAME) || ! defined (GAME_CD) || ! defined (GAME_CD_DIR) || ! defined (GAME_CD_FILE) || ! defined (GAME) || ! defined (EXTRACT_BIN) || ! defined (EXTRACT_COMMAND) || ! defined (EXTRACT_INFO) 00127 #error You need to define all Game macros, see stratagus-maemo-extract.h 00128 #endif 00129 00130 #include <stdio.h> 00131 #include <stdlib.h> 00132 #include <string.h> 00133 00134 #include <unistd.h> 00135 #include <sys/stat.h> 00136 #include <sys/types.h> 00137 00138 #include <gtk/gtk.h> 00139 #include <hildon/hildon.h> 00140 00141 #define DATA_NEED_COPY "Note: You need the original " GAME_CD "\n(Battle.net edition doesn't work)\nto extract the game data files.\nData files are needed to run " GAME_NAME ".\n\nFirst copy " GAME_CD " to folder " GAME_CD_DIR "\n, then press OK." EXTRACT_INFO 00142 #define DATA_FOUND GAME_CD " data files was found in folder " GAME_CD_DIR "\n\nPlease be patient, the data may take\na couple of minutes to extract...\n\nPress OK to start extracting data now." 00143 #define DATA_NOT_FOUND "Error: " GAME_CD " data files was not found.\n\nCheck if you have file\n" GAME_CD_DIR"/"GAME_CD_FILE 00144 #define EXTRACT_OK GAME_CD " data files was successfull extracted." 00145 #define EXTRACT_FAILED "Error: Cannot extract " GAME_CD " data files,\nextract program crashed." 00146 00147 #define DATA_DIR "/home/user/" GAME_CD_DIR 00148 #define EXTRACT_DIR "/home/user/MyDocs/stratagus/" GAME 00149 00150 static void message(char * title, char * text, int error) { 00151 00152 GtkWidget * window = NULL; 00153 GtkWidget * dialog = NULL; 00154 00155 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 00156 gtk_window_set_title(GTK_WINDOW(window), title); 00157 gtk_widget_show(window); 00158 00159 dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_OK, text, NULL); 00160 gtk_window_set_title(GTK_WINDOW(dialog), title); 00161 gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), 0); 00162 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), 0); 00163 gtk_label_set_selectable(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), 0); 00164 gtk_dialog_run(GTK_DIALOG(dialog)); 00165 gtk_widget_destroy(dialog); 00166 00167 gtk_widget_destroy(window); 00168 00169 if ( error ) 00170 exit(error); 00171 00172 } 00173 00174 int main(int argc, char * argv[]) { 00175 00176 FILE * file; 00177 struct stat st; 00178 00179 hildon_gtk_init(&argc, &argv); 00180 00181 file = fopen(EXTRACT_DIR "/extracted", "r"); 00182 00183 if ( file ) { 00184 00185 char act_version[20]; 00186 fgets(act_version, 20, file); 00187 fclose(file); 00188 00189 file = popen(EXTRACTBIN " -V", "r"); 00190 00191 if ( file ) { 00192 00193 char new_version[20]; 00194 fgets(new_version, 20, file); 00195 pclose(file); 00196 00197 if ( strncmp(act_version, new_version, 19) == 0 ) 00198 return 0; 00199 00200 } 00201 00202 } 00203 00204 message(GAME_NAME, DATA_NEED_COPY, 0); 00205 00206 if ( stat(GAME_DIR "/" GAME_CD_FILE, &st) != 0 ) { 00207 00208 char * buf = strdup(GAME_CD_FILE); 00209 char * path = calloc(strlen(GAME_CD_FILE) + strlen(GAME_DIR) + 2, sizeof(char)); 00210 char * ptr = buf; 00211 00212 while ( *ptr ) { 00213 00214 *ptr = toupper(*ptr); 00215 ++ptr; 00216 00217 } 00218 00219 sprintf(path, GAME_DIR "/%s", buf); 00220 00221 if ( stat(path, &st) != 0 ) 00222 message(GAME_NAME, DATA_NOT_FOUND, 1); 00223 00224 free(buf); 00225 free(path); 00226 00227 } 00228 00229 if ( stat("/home/user/MyDocs/stratagus", &st) != 0 ) 00230 mkdir("/home/user/MyDocs/stratagus", 0777); 00231 00232 if ( stat("/home/user/MyDocs/stratagus/" GAME, &st) != 0 ) 00233 mkdir("/home/user/MyDocs/stratagus/" GAME, 0777); 00234 00235 message(GAME_NAME, DATA_FOUND, 0); 00236 00237 int ret = system(EXTRACT_COMMAND); 00238 00239 if ( ret != 0 ) 00240 message(GAMENAME, EXTRACT_FAILED, ret); 00241 00242 message(GAME_NAME, EXTRACT_OK, 0); 00243 return 0; 00244 00245 }