$treeview $search $mathjax
Stratagus
2.2.7
$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 00119 /* Fake definitions for Doxygen */ 00120 #ifdef DOXYGEN 00121 #define GAME_NAME 00122 #define GAME_CD 00123 #define GAME_CD_DIR 00124 #define GAME_CD_FILE 00125 #define GAME 00126 #define EXTRACT_BIN 00127 #endif 00128 00129 #if ! defined (GAME_NAME) || ! defined (GAME_CD) || ! defined (GAME_CD_DIR) || ! defined (GAME_CD_FILE) || ! defined (GAME) || ! defined (EXTRACT_BIN) 00130 #error You need to define all Game macros, see stratagus-maemo-extract.h 00131 #endif 00132 00133 #include <stdio.h> 00134 #include <stdlib.h> 00135 #include <string.h> 00136 00137 #include <unistd.h> 00138 #include <sys/stat.h> 00139 #include <sys/types.h> 00140 00141 #include <gtk/gtk.h> 00142 #include <hildon/hildon.h> 00143 00144 #define DATA_DIR "/home/user/" GAME_CD_DIR 00145 #define EXTRACT_DIR "/home/user/MyDocs/stratagus/" GAME 00146 00147 #ifndef EXTRACT_COMMAND 00148 #define EXTRACT_COMMAND EXTRACT_BIN " " DATA_DIR " " EXTRACT_DIR 00149 #endif 00150 00151 #ifndef EXTRACT_INFO 00152 #define EXTRACT_INFO "" 00153 #endif 00154 00155 #define DATA_NEED_COPY "Note: You need the original " GAME_CD "\nto extract the game data files.\nData files are needed to run " GAME_NAME ".\n\nFirst copy " GAME_CD " to folder\n" GAME_CD_DIR "\nthen press OK. " EXTRACT_INFO 00156 #define DATA_FOUND GAME_CD " data files was found in folder\n" 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." 00157 #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 00158 #define EXTRACT_OK GAME_CD " data files was successfull extracted." 00159 #define EXTRACT_FAILED "Error: Cannot extract " GAME_CD " data files\nextract program crashed." 00160 00161 static void message(char * title, char * text, int error) { 00162 00163 GtkWidget * window = NULL; 00164 GtkWidget * dialog = NULL; 00165 00166 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 00167 gtk_window_set_title(GTK_WINDOW(window), title); 00168 gtk_widget_show(window); 00169 00170 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); 00171 gtk_window_set_title(GTK_WINDOW(dialog), title); 00172 gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), 0); 00173 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), 0); 00174 gtk_label_set_selectable(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), 0); 00175 gtk_dialog_run(GTK_DIALOG(dialog)); 00176 gtk_widget_destroy(dialog); 00177 00178 gtk_widget_destroy(window); 00179 00180 if ( error ) 00181 exit(error); 00182 00183 } 00184 00185 int main(int argc, char * argv[]) { 00186 00187 FILE * file; 00188 struct stat st; 00189 00190 hildon_gtk_init(&argc, &argv); 00191 00192 file = fopen(EXTRACT_DIR "/extracted", "r"); 00193 00194 if ( file ) { 00195 00196 char act_version[20]; 00197 int have_version = 0; 00198 00199 if ( fgets(act_version, 20, file) ) 00200 have_version = 1; 00201 00202 fclose(file); 00203 00204 if ( have_version ) { 00205 00206 file = popen(EXTRACT_BIN " -V", "r"); 00207 00208 if ( file ) { 00209 00210 int i; 00211 char new_version[20]; 00212 have_version = 0; 00213 00214 if ( fgets(new_version, 20, file) ) 00215 have_version = 1; 00216 00217 pclose(file); 00218 00219 if ( have_version ) { 00220 00221 for ( i = 0; i < 20; ++i ) { 00222 if ( new_version[i] == '\n' ) { 00223 new_version[i] = 0; 00224 break; 00225 } 00226 } 00227 00228 if ( strcmp(act_version, new_version) == 0 ) 00229 return 0; 00230 00231 } 00232 00233 } 00234 00235 } 00236 00237 } 00238 00239 message(GAME_NAME, DATA_NEED_COPY, 0); 00240 00241 if ( stat(DATA_DIR "/" GAME_CD_FILE, &st) != 0 ) { 00242 00243 char * buf = strdup(GAME_CD_FILE); 00244 char * path = calloc(strlen(DATA_DIR) + strlen(GAME_CD_FILE) + 2, 1); 00245 char * ptr = buf; 00246 00247 while ( *ptr ) { 00248 00249 *ptr = toupper(*ptr); 00250 ++ptr; 00251 00252 } 00253 00254 sprintf(path, DATA_DIR "/%s", buf); 00255 00256 if ( stat(path, &st) != 0 ) 00257 message(GAME_NAME, DATA_NOT_FOUND, 1); 00258 00259 free(buf); 00260 free(path); 00261 00262 } 00263 00264 if ( stat("/home/user/MyDocs/stratagus", &st) != 0 ) 00265 mkdir("/home/user/MyDocs/stratagus", 0777); 00266 00267 if ( stat("/home/user/MyDocs/stratagus/" GAME, &st) != 0 ) 00268 mkdir("/home/user/MyDocs/stratagus/" GAME, 0777); 00269 00270 message(GAME_NAME, DATA_FOUND, 0); 00271 00272 int ret = system(EXTRACT_COMMAND); 00273 00274 if ( ret != 0 ) 00275 message(GAME_NAME, EXTRACT_FAILED, ret); 00276 00277 message(GAME_NAME, EXTRACT_OK, 0); 00278 return 0; 00279 00280 }