21 #include <os2me.h> |
23 #include <os2me.h> |
22 |
24 |
23 #if defined(WITH_SDL) |
25 #if defined(WITH_SDL) |
24 #include <SDL.h> |
26 #include <SDL.h> |
25 #endif |
27 #endif |
26 |
|
27 static inline int strcasecmp(const char* s1, const char* s2) |
|
28 { |
|
29 return stricmp(s1, s2); |
|
30 } |
|
31 |
28 |
32 static char *_fios_path; |
29 static char *_fios_path; |
33 static char *_fios_save_path; |
30 static char *_fios_save_path; |
34 static char *_fios_scn_path; |
31 static char *_fios_scn_path; |
35 static FiosItem *_fios_items; |
32 static FiosItem *_fios_items; |
51 int r; |
48 int r; |
52 |
49 |
53 if (_savegame_sort_order < 2) // sort by date |
50 if (_savegame_sort_order < 2) // sort by date |
54 r = da->mtime < db->mtime ? -1 : 1; |
51 r = da->mtime < db->mtime ? -1 : 1; |
55 else |
52 else |
56 r = strcasecmp( |
53 r = stricmp( |
57 da->title[0] != '\0' ? da->title : da->name, |
54 da->title[0] != '\0' ? da->title : da->name, |
58 db->title[0] != '\0' ? db->title : db->name |
55 db->title[0] != '\0' ? db->title : db->name |
59 ); |
56 ); |
60 |
57 |
61 if (_savegame_sort_order & 1) r = -r; |
58 if (_savegame_sort_order & 1) r = -r; |
151 |
148 |
152 append_path(filename, _fios_path, dirent->d_name); |
149 append_path(filename, _fios_path, dirent->d_name); |
153 if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
150 if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
154 |
151 |
155 t = strrchr(dirent->d_name, '.'); |
152 t = strrchr(dirent->d_name, '.'); |
156 if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD |
153 if (t != NULL && stricmp(t, ".sav") == 0) { // OpenTTD |
157 fios = FiosAlloc(); |
154 fios = FiosAlloc(); |
158 fios->type = FIOS_TYPE_FILE; |
155 fios->type = FIOS_TYPE_FILE; |
159 fios->mtime = sb.st_mtime; |
156 fios->mtime = sb.st_mtime; |
160 fios->title[0] = '\0'; |
157 fios->title[0] = '\0'; |
161 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
158 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
162 } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
159 } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
163 if (t != NULL && ( |
160 if (t != NULL && ( |
164 strcasecmp(t, ".ss1") == 0 || |
161 stricmp(t, ".ss1") == 0 || |
165 strcasecmp(t, ".sv1") == 0 || |
162 stricmp(t, ".sv1") == 0 || |
166 strcasecmp(t, ".sv2") == 0 |
163 stricmp(t, ".sv2") == 0 |
167 )) { // TTDLX(Patch) |
164 )) { // TTDLX(Patch) |
168 fios = FiosAlloc(); |
165 fios = FiosAlloc(); |
169 fios->type = FIOS_TYPE_OLDFILE; |
166 fios->type = FIOS_TYPE_OLDFILE; |
170 fios->mtime = sb.st_mtime; |
167 fios->mtime = sb.st_mtime; |
171 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
168 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
271 |
268 |
272 append_path(filename, _fios_path, dirent->d_name); |
269 append_path(filename, _fios_path, dirent->d_name); |
273 if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
270 if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
274 |
271 |
275 t = strrchr(dirent->d_name, '.'); |
272 t = strrchr(dirent->d_name, '.'); |
276 if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD |
273 if (t != NULL && stricmp(t, ".scn") == 0) { // OpenTTD |
277 fios = FiosAlloc(); |
274 fios = FiosAlloc(); |
278 fios->type = FIOS_TYPE_SCENARIO; |
275 fios->type = FIOS_TYPE_SCENARIO; |
279 fios->mtime = sb.st_mtime; |
276 fios->mtime = sb.st_mtime; |
280 fios->title[0] = '\0'; |
277 fios->title[0] = '\0'; |
281 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
278 ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
282 } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
279 } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
283 mode == SLD_NEW_GAME) { |
280 mode == SLD_NEW_GAME) { |
284 if (t != NULL && ( |
281 if (t != NULL && ( |
285 strcasecmp(t, ".sv0") == 0 || |
282 stricmp(t, ".sv0") == 0 || |
286 strcasecmp(t, ".ss0") == 0 |
283 stricmp(t, ".ss0") == 0 |
287 )) { // TTDLX(Patch) |
284 )) { // TTDLX(Patch) |
288 fios = FiosAlloc(); |
285 fios = FiosAlloc(); |
289 fios->type = FIOS_TYPE_OLD_SCENARIO; |
286 fios->type = FIOS_TYPE_OLD_SCENARIO; |
290 fios->mtime = sb.st_mtime; |
287 fios->mtime = sb.st_mtime; |
291 GetOldScenarioGameName(fios->title, filename); |
288 GetOldScenarioGameName(fios->title, filename); |
408 else |
405 else |
409 extension = ".sav"; |
406 extension = ".sav"; |
410 |
407 |
411 // Don't append the extension, if it is already there |
408 // Don't append the extension, if it is already there |
412 period = strrchr(name, '.'); |
409 period = strrchr(name, '.'); |
413 if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; |
410 if (period != NULL && stricmp(period, extension) == 0) extension = ""; |
414 |
411 |
415 sprintf(buf, "%s\\%s%s", _fios_path, name, extension); |
412 sprintf(buf, "%s\\%s%s", _fios_path, name, extension); |
416 } |
413 } |
417 |
414 |
418 void FiosDelete(const char *name) |
415 void FiosDelete(const char *name) |
711 // text is now in pszLocalText, do something with it! |
708 // text is now in pszLocalText, do something with it! |
712 #endif |
709 #endif |
713 // TODO |
710 // TODO |
714 return false; |
711 return false; |
715 } |
712 } |
|
713 |
|
714 static TID thread1 = 0; |
|
715 |
|
716 // The thread function must be declared and compiled using _Optlink linkage, apparently |
|
717 // It seems to work, though :) |
|
718 |
|
719 bool CreateOTTDThread(void *func, void *param) |
|
720 { |
|
721 thread1 = _beginthread(func, NULL, 32768, param); |
|
722 fprintf(stderr, "beginthread returns: %d\n", thread1); // |
|
723 |
|
724 if (thread1 == -1) |
|
725 return(false); |
|
726 |
|
727 return(true); |
|
728 } |
|
729 |
|
730 void CloseOTTDThread(void) |
|
731 { |
|
732 _endthread(); |
|
733 return; |
|
734 } |
|
735 |
|
736 void JoinOTTDThread(void) |
|
737 { |
|
738 if (thread1 == 0) |
|
739 return; |
|
740 |
|
741 DosWaitThread(&thread1, DCWW_WAIT); |
|
742 } |