46 #if defined(WITH_SDL) |
46 #if defined(WITH_SDL) |
47 //the mac implementation needs this file included in the same file as main() |
47 //the mac implementation needs this file included in the same file as main() |
48 #include <SDL.h> |
48 #include <SDL.h> |
49 #endif |
49 #endif |
50 #endif |
50 #endif |
51 static char *_fios_path; |
51 extern char *_fios_path; |
52 static char *_fios_save_path; |
52 static char *_fios_save_path; |
53 static char *_fios_scn_path; |
53 static char *_fios_scn_path; |
54 static FiosItem *_fios_items; |
54 extern FiosItem *_fios_items; |
55 static int _fios_count, _fios_alloc; |
55 extern int _fios_count, _fios_alloc; |
56 |
|
57 static FiosItem *FiosAlloc(void) |
|
58 { |
|
59 if (_fios_count == _fios_alloc) { |
|
60 _fios_alloc += 256; |
|
61 _fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
62 } |
|
63 return &_fios_items[_fios_count++]; |
|
64 } |
|
65 |
|
66 int compare_FiosItems(const void *a, const void *b) |
|
67 { |
|
68 const FiosItem *da = (const FiosItem *)a; |
|
69 const FiosItem *db = (const FiosItem *)b; |
|
70 int r; |
|
71 |
|
72 if (_savegame_sort_order & SORT_BY_NAME) { |
|
73 r = strcasecmp(da->title, db->title); |
|
74 } else { |
|
75 r = da->mtime < db->mtime ? -1 : 1; |
|
76 } |
|
77 |
|
78 if (_savegame_sort_order & SORT_DESCENDING) r = -r; |
|
79 return r; |
|
80 } |
|
81 |
56 |
82 #if !defined(__MORPHOS__) && !defined(__AMIGAOS__) |
57 #if !defined(__MORPHOS__) && !defined(__AMIGAOS__) |
83 #define ISROOT(__p) (__p[1] == '\0') |
58 #define ISROOT(__p) (__p[1] == '\0') |
84 #define PATHTEMPLATE "%s/%s" |
59 #define PATHTEMPLATE "%s/%s" |
85 #else |
60 #else |
293 } |
268 } |
294 |
269 |
295 qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
270 qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
296 *num = _fios_count; |
271 *num = _fios_count; |
297 return _fios_items; |
272 return _fios_items; |
298 } |
|
299 |
|
300 |
|
301 // Free the list of savegames |
|
302 void FiosFreeSavegameList(void) |
|
303 { |
|
304 free(_fios_items); |
|
305 _fios_items = NULL; |
|
306 _fios_alloc = _fios_count = 0; |
|
307 } |
273 } |
308 |
274 |
309 // Browse to |
275 // Browse to |
310 char *FiosBrowseTo(const FiosItem *item) |
276 char *FiosBrowseTo(const FiosItem *item) |
311 { |
277 { |
385 #endif |
351 #endif |
386 if (tot != NULL) *tot = free; |
352 if (tot != NULL) *tot = free; |
387 return STR_4005_BYTES_FREE; |
353 return STR_4005_BYTES_FREE; |
388 } |
354 } |
389 |
355 |
390 void FiosMakeSavegameName(char *buf, const char *name, size_t size) |
|
391 { |
|
392 const char* extension; |
|
393 const char* period; |
|
394 |
|
395 extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav"); |
|
396 |
|
397 // Don't append the extension, if it is already there |
|
398 period = strrchr(name, '.'); |
|
399 if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; |
|
400 |
|
401 snprintf(buf, size, "%s/%s%s", _fios_path, name, extension); |
|
402 } |
|
403 |
|
404 bool FiosDelete(const char *name) |
|
405 { |
|
406 char path[512]; |
|
407 |
|
408 FiosMakeSavegameName(path, name, sizeof(path)); |
|
409 return unlink(path) == 0; |
|
410 } |
|
411 |
|
412 bool FileExists(const char *filename) |
|
413 { |
|
414 return access(filename, 0) == 0; |
|
415 } |
|
416 |
|
417 #if defined(__BEOS__) || defined(__linux__) |
356 #if defined(__BEOS__) || defined(__linux__) |
418 static void ChangeWorkingDirectory(char *exe) |
357 static void ChangeWorkingDirectory(char *exe) |
419 { |
358 { |
420 char *s = strrchr(exe, '/'); |
359 char *s = strrchr(exe, '/'); |
421 if (s != NULL) { |
360 if (s != NULL) { |