_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

stratagus-maemo-extract.h
Go to the documentation of this file.
1 /*
2  _________ __ __
3  / _____// |_____________ _/ |______ ____ __ __ ______
4  \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
5  / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
6  /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
7  \/ \/ \//_____/ \/
8  ______________________ ______________________
9  T H E W A R B E G I N S
10  Stratagus - A free fantasy real time strategy game engine
11 
12  stratagus-maemo-extract.h - Stratagus Game data extractor for Maemo
13  Copyright (C) 2010-2011 Pali Rohár <pali.rohar@gmail.com>
14 
15  This program is free software: you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 2 of the License, or
18  (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program. If not, see <http://www.gnu.org/licenses/>.
27 
28 */
29 
119 /* Fake definitions for Doxygen */
120 #ifdef DOXYGEN
121 #define GAME_NAME
122 #define GAME_CD
123 #define GAME_CD_DIR
124 #define GAME_CD_FILE
125 #define GAME
126 #define EXTRACT_BIN
127 #endif
128 
129 #if ! defined (GAME_NAME) || ! defined (GAME_CD) || ! defined (GAME_CD_DIR) || ! defined (GAME_CD_FILE) || ! defined (GAME) || ! defined (EXTRACT_BIN)
130 #error You need to define all Game macros, see stratagus-maemo-extract.h
131 #endif
132 
133 #include <stdio.h>
134 #include <stdlib.h>
135 #include <string.h>
136 
137 #include <unistd.h>
138 #include <sys/stat.h>
139 #include <sys/types.h>
140 
141 #include <gtk/gtk.h>
142 #include <hildon/hildon.h>
143 
144 #define DATA_DIR "/home/user/" GAME_CD_DIR
145 #define EXTRACT_DIR "/home/user/MyDocs/stratagus/" GAME
146 
147 #ifndef EXTRACT_COMMAND
148 #define EXTRACT_COMMAND EXTRACT_BIN " " DATA_DIR " " EXTRACT_DIR
149 #endif
150 
151 #ifndef EXTRACT_INFO
152 #define EXTRACT_INFO ""
153 #endif
154 
155 #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
156 #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."
157 #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
158 #define EXTRACT_OK GAME_CD " data files was successfull extracted."
159 #define EXTRACT_FAILED "Error: Cannot extract " GAME_CD " data files\nextract program crashed."
160 
161 static void message(char * title, char * text, int error) {
162 
163  GtkWidget * window = NULL;
164  GtkWidget * dialog = NULL;
165 
166  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
167  gtk_window_set_title(GTK_WINDOW(window), title);
168  gtk_widget_show(window);
169 
170  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);
171  gtk_window_set_title(GTK_WINDOW(dialog), title);
172  gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), 0);
173  gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), 0);
174  gtk_label_set_selectable(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), 0);
175  gtk_dialog_run(GTK_DIALOG(dialog));
176  gtk_widget_destroy(dialog);
177 
178  gtk_widget_destroy(window);
179 
180  if ( error )
181  exit(error);
182 
183 }
184 
185 int main(int argc, char * argv[]) {
186 
187  FILE * file;
188  struct stat st;
189 
190  hildon_gtk_init(&argc, &argv);
191 
192  file = fopen(EXTRACT_DIR "/extracted", "r");
193 
194  if ( file ) {
195 
196  char act_version[20];
197  int have_version = 0;
198 
199  if ( fgets(act_version, 20, file) )
200  have_version = 1;
201 
202  fclose(file);
203 
204  if ( have_version ) {
205 
206  file = popen(EXTRACT_BIN " -V", "r");
207 
208  if ( file ) {
209 
210  int i;
211  char new_version[20];
212  have_version = 0;
213 
214  if ( fgets(new_version, 20, file) )
215  have_version = 1;
216 
217  pclose(file);
218 
219  if ( have_version ) {
220 
221  for ( i = 0; i < 20; ++i ) {
222  if ( new_version[i] == '\n' ) {
223  new_version[i] = 0;
224  break;
225  }
226  }
227 
228  if ( strcmp(act_version, new_version) == 0 )
229  return 0;
230 
231  }
232 
233  }
234 
235  }
236 
237  }
238 
240 
241  if ( stat(DATA_DIR "/" GAME_CD_FILE, &st) != 0 ) {
242 
243  char * buf = strdup(GAME_CD_FILE);
244  char * path = calloc(strlen(DATA_DIR) + strlen(GAME_CD_FILE) + 2, 1);
245  char * ptr = buf;
246 
247  while ( *ptr ) {
248 
249  *ptr = toupper(*ptr);
250  ++ptr;
251 
252  }
253 
254  sprintf(path, DATA_DIR "/%s", buf);
255 
256  if ( stat(path, &st) != 0 )
258 
259  free(buf);
260  free(path);
261 
262  }
263 
264  if ( stat("/home/user/MyDocs/stratagus", &st) != 0 )
265  mkdir("/home/user/MyDocs/stratagus", 0777);
266 
267  if ( stat("/home/user/MyDocs/stratagus/" GAME, &st) != 0 )
268  mkdir("/home/user/MyDocs/stratagus/" GAME, 0777);
269 
271 
272  int ret = system(EXTRACT_COMMAND);
273 
274  if ( ret != 0 )
276 
278  return 0;
279 
280 }
#define EXTRACT_OK
Definition: stratagus-maemo-extract.h:158
#define DATA_NEED_COPY
Definition: stratagus-maemo-extract.h:155
#define GAME_CD_FILE
Definition: stratagus-maemo-extract.h:124
#define EXTRACT_FAILED
Definition: stratagus-maemo-extract.h:159
#define EXTRACT_COMMAND
Definition: stratagus-maemo-extract.h:148
static void message(char *title, char *text, int error)
Definition: stratagus-maemo-extract.h:161
#define DATA_DIR
Definition: stratagus-maemo-extract.h:144
#define GAME_NAME
Definition: stratagus-maemo-extract.h:121
#define EXTRACT_DIR
Definition: stratagus-maemo-extract.h:145
int main(int argc, char *argv[])
Definition: stratagus-maemo-extract.h:185
#define DATA_NOT_FOUND
Definition: stratagus-maemo-extract.h:157
#define EXTRACT_BIN
Definition: stratagus-maemo-extract.h:126
#define GAME
Definition: stratagus-maemo-extract.h:125
#define DATA_FOUND
Definition: stratagus-maemo-extract.h:156
static void error(char *title, char *text)
Definition: stratagus-game-launcher.h:186
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.