Mercurial > repos > blastem
annotate util.c @ 1137:9e0f2ea4a0fc
Fix slot tracking screwup
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 01 Jan 2017 23:00:28 -0800 |
parents | 22e87b739ad6 |
children | 160e3f597cec |
rev | line source |
---|---|
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stdio.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <ctype.h> |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
5 #include <stdint.h> |
805 | 6 #include <stdarg.h> |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
8 #include <sys/types.h> |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
9 #include <sys/stat.h> |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
10 #include <unistd.h> |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
11 #include <errno.h> |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
12 |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
13 #ifdef __ANDROID__ |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
14 #include <android/log.h> |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
15 #define info_puts(msg) __android_log_write(ANDROID_LOG_INFO, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
16 #define warning_puts(msg) __android_log_write(ANDROID_LOG_WARN, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
17 #define fatal_puts(msg) __android_log_write(ANDROID_LOG_FATAL, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
18 |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
19 #define info_printf(msg, args) __android_log_vprint(ANDROID_LOG_INFO, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
20 #define warning_printf(msg, args) __android_log_vprint(ANDROID_LOG_WARN, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
21 #define fatal_printf(msg, args) __android_log_vprint(ANDROID_LOG_FATAL, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
22 #else |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
23 #define info_puts(msg) fputs(msg, stdout); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
24 #define warning_puts(msg) fputs(msg, stderr); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
25 #define fatal_puts(msg) fputs(msg, stderr); |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
26 |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
27 #define info_printf(msg, args) vprintf(msg, args) |
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
28 #define warning_printf(msg, args) vfprintf(stderr, msg, args) |
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
29 #define fatal_printf(msg, args) vfprintf(stderr, msg, args) |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
30 #endif |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
31 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
32 #include "blastem.h" //for headless global |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
33 #include "render.h" //for render_errorbox |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
34 #include "util.h" |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
35 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
36 char * alloc_concat(char const * first, char const * second) |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 int flen = strlen(first); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 int slen = strlen(second); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 char * ret = malloc(flen + slen + 1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 memcpy(ret, first, flen); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 memcpy(ret+flen, second, slen+1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
46 char * alloc_concat_m(int num_parts, char const ** parts) |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 int total = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 for (int i = 0; i < num_parts; i++) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 total += strlen(parts[i]); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 char * ret = malloc(total + 1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 *ret = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 for (int i = 0; i < num_parts; i++) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 strcat(ret, parts[i]); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
60 void byteswap_rom(int filesize, uint16_t *cart) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
61 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
62 for(uint16_t *cur = cart; cur - cart < filesize/2; ++cur) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
63 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
64 *cur = (*cur >> 8) | (*cur << 8); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
65 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
66 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
67 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
68 |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 long file_size(FILE * f) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 fseek(f, 0, SEEK_END); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 long fsize = ftell(f); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 fseek(f, 0, SEEK_SET); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 return fsize; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 char * strip_ws(char * text) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 while (*text && (!isprint(*text) || isblank(*text))) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 text++; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 char * ret = text; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 text = ret + strlen(ret) - 1; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 while (text > ret && (!isprint(*text) || isblank(*text))) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 *text = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 text--; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 char * split_keyval(char * text) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 while (*text && !isblank(*text)) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 text++; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 if (!*text) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 return text; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 *text = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 return text+1; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
105 |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
106 char is_path_sep(char c) |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
107 { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
108 #ifdef _WIN32 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
109 if (c == '\\') { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
110 return 1; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
111 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
112 #endif |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
113 return c == '/'; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
114 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
115 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
116 char is_absolute_path(char *path) |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
117 { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
118 #ifdef _WIN32 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
119 if (path[1] == ':' && is_path_sep(path[2]) && isalpha(path[0])) { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
120 return 1; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
121 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
122 #endif |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
123 return is_path_sep(path[0]); |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
124 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
125 |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
126 char * basename_no_extension(char *path) |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
127 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
128 char *lastdot = NULL; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
129 char *lastslash = NULL; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
130 char *cur; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
131 for (cur = path; *cur; cur++) |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
132 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
133 if (*cur == '.') { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
134 lastdot = cur; |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
135 } else if (is_path_sep(*cur)) { |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
136 lastslash = cur + 1; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
137 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
138 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
139 if (!lastdot) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
140 lastdot = cur; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
141 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
142 if (!lastslash) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
143 lastslash = path; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
144 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
145 char *barename = malloc(lastdot-lastslash+1); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
146 memcpy(barename, lastslash, lastdot-lastslash); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
147 barename[lastdot-lastslash] = 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
148 |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
149 return barename; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
150 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
151 |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
152 uint32_t nearest_pow2(uint32_t val) |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
153 { |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
154 uint32_t ret = 1; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
155 while (ret < val) |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
156 { |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
157 ret = ret << 1; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
158 } |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
159 return ret; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
160 } |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
161 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
162 static char * exe_str; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
163 |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
164 void set_exe_str(char * str) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
165 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
166 exe_str = str; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
167 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
168 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
169 void fatal_error(char *format, ...) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
170 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
171 va_list args; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
172 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
173 if (!headless) { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
174 //take a guess at the final size |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
175 size_t size = strlen(format) * 2; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
176 char *buf = malloc(size); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
177 size_t actual = vsnprintf(buf, size, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
178 if (actual >= size) { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
179 actual++; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
180 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
181 buf = malloc(actual); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
182 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
183 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
184 vsnprintf(buf, actual, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
185 } |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
186 fatal_puts(buf); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
187 render_errorbox("Fatal Error", buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
188 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
189 } else { |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
190 fatal_printf(format, args); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
191 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
192 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
193 exit(1); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
194 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
195 |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
196 void warning(char *format, ...) |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
197 { |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
198 va_list args; |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
199 va_start(args, format); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
200 #ifndef _WIN32 |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
201 if (headless || (isatty(STDERR_FILENO) && isatty(STDIN_FILENO))) { |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
202 warning_printf(format, args); |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
203 } else { |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
204 #endif |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
205 size_t size = strlen(format) * 2; |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
206 char *buf = malloc(size); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
207 size_t actual = vsnprintf(buf, size, format, args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
208 if (actual >= size) { |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
209 actual++; |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
210 free(buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
211 buf = malloc(actual); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
212 va_end(args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
213 va_start(args, format); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
214 vsnprintf(buf, actual, format, args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
215 } |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
216 warning_puts(buf); |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
217 render_infobox("BlastEm Info", buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
218 free(buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
219 #ifndef _WIN32 |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
220 } |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
221 #endif |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
222 va_end(args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
223 } |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
224 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
225 void info_message(char *format, ...) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
226 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
227 va_list args; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
228 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
229 #ifndef _WIN32 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
230 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) { |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
231 info_printf(format, args); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
232 } else { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
233 #endif |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
234 size_t size = strlen(format) * 2; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
235 char *buf = malloc(size); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
236 size_t actual = vsnprintf(buf, size, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
237 if (actual >= size) { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
238 actual++; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
239 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
240 buf = malloc(actual); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
241 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
242 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
243 vsnprintf(buf, actual, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
244 } |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
245 info_puts(buf); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
246 render_infobox("BlastEm Info", buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
247 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
248 #ifndef _WIN32 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
249 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
250 #endif |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
251 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
252 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
253 |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
254 #ifdef _WIN32 |
795
bce97fc0bb8a
Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
773
diff
changeset
|
255 #include <windows.h> |
bce97fc0bb8a
Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
773
diff
changeset
|
256 #include <shlobj.h> |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
257 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
258 char * get_home_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
259 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
260 static char path[MAX_PATH]; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
261 SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
262 return path; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
263 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
264 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
265 char * get_exe_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
266 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
267 static char path[MAX_PATH]; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
268 HMODULE module = GetModuleHandleA(NULL); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
269 GetModuleFileNameA(module, path, MAX_PATH); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
270 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
271 int pathsize = strlen(path); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
272 for(char * cur = path + pathsize - 1; cur != path; cur--) |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
273 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
274 if (*cur == '\\') { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
275 *cur = 0; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
276 break; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
277 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
278 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
279 return path; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
280 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
281 |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
282 dir_entry *get_dir_list(char *path, size_t *numret) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
283 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
284 HANDLE dir; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
285 WIN32_FIND_DATA file; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
286 char *pattern = alloc_concat(path, "/*.*"); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
287 dir = FindFirstFile(pattern, &file); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
288 free(pattern); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
289 if (dir == INVALID_HANDLE_VALUE) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
290 if (numret) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
291 *numret = 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
292 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
293 return NULL; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
294 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
295 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
296 size_t storage = 64; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
297 dir_entry *ret = malloc(sizeof(dir_entry) * storage); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
298 size_t pos = 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
299 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
300 do { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
301 if (pos == storage) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
302 storage = storage * 2; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
303 ret = realloc(ret, sizeof(dir_entry) * storage); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
304 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
305 ret[pos].name = strdup(file.cFileName); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
306 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
307 } while (FindNextFile(dir, &file)); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
308 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
309 FindClose(dir); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
310 if (numret) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
311 *numret = pos; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
312 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
313 return ret; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
314 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
315 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
316 time_t get_modification_time(char *path) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
317 { |
974
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
318 HANDLE results; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
319 WIN32_FIND_DATA file; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
320 results = FindFirstFile(path, &file); |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
321 if (results == INVALID_HANDLE_VALUE) { |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
322 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
323 } |
974
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
324 FindClose(results); |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
325 uint64_t wintime = ((uint64_t)file.ftLastWriteTime.dwHighDateTime) << 32 | file.ftLastWriteTime.dwLowDateTime; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
326 //convert to seconds |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
327 wintime /= 10000000; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
328 //adjust for difference between Windows and Unix Epoch |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
329 wintime -= 11644473600LL; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
330 return (time_t)wintime; |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
331 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
332 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
333 int ensure_dir_exists(char *path) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
334 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
335 if (CreateDirectory(path, NULL)) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
336 return 1; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
337 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
338 if (GetLastError() == ERROR_ALREADY_EXISTS) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
339 return 1; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
340 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
341 if (GetLastError() != ERROR_PATH_NOT_FOUND) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
342 warning("CreateDirectory failed with unexpected error code %X\n", GetLastError()); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
343 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
344 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
345 char *parent = strdup(path); |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
346 //Windows technically supports both native and Unix-style path separators |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
347 //so search for both |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
348 char *sep = strrchr(parent, '\\'); |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
349 char *osep = strrchr(parent, '/'); |
1039
86ed81bb574f
Fix bug in ensure_dir_exists that would cause it to fail when mixed path separators were used
Michael Pavone <pavone@retrodev.com>
parents:
1021
diff
changeset
|
350 if (osep && (!sep || osep > sep)) { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
351 sep = osep; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
352 } |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
353 if (!sep || sep == parent) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
354 //relative path, but for some reason we failed |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
355 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
356 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
357 *sep = 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
358 if (!ensure_dir_exists(parent)) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
359 free(parent); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
360 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
361 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
362 free(parent); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
363 return CreateDirectory(path, NULL); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
364 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
365 |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
366 #else |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
367 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
368 char * get_home_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
369 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
370 return getenv("HOME"); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
371 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
372 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
373 char * readlink_alloc(char * path) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
374 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
375 char * linktext = NULL; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
376 ssize_t linksize = 512; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
377 ssize_t cursize = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
378 do { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
379 if (linksize > cursize) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
380 cursize = linksize; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
381 if (linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
382 free(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
383 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
384 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
385 linktext = malloc(cursize); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
386 linksize = readlink(path, linktext, cursize-1); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
387 if (linksize == -1) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
388 perror("readlink"); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
389 free(linktext); |
559
6b248602ab84
blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents:
549
diff
changeset
|
390 return NULL; |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
391 } |
549
32da1e0d5e55
Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
392 } while ((linksize+1) > cursize); |
32da1e0d5e55
Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
393 linktext[linksize] = 0; |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
394 return linktext; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
395 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
396 |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
397 char * get_exe_dir() |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
398 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
399 static char * exe_dir; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
400 if (!exe_dir) { |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
401 char * cur; |
763
2a25ea5d94f7
Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
402 #ifdef HAS_PROC |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
403 char * linktext = readlink_alloc("/proc/self/exe"); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
404 if (!linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
405 goto fallback; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
406 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
407 int linksize = strlen(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
408 for(cur = linktext + linksize - 1; cur != linktext; cur--) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
409 { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
410 if (is_path_sep(*cur)) { |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
411 *cur = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
412 break; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
413 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
414 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
415 if (cur == linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
416 free(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
417 fallback: |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
418 #endif |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
419 if (!exe_str) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
420 fputs("/proc/self/exe is not available and set_exe_str was not called!", stderr); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
421 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
422 int pathsize = strlen(exe_str); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
423 for(cur = exe_str + pathsize - 1; cur != exe_str; cur--) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
424 { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
425 if (is_path_sep(*cur)) { |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
426 exe_dir = malloc(cur-exe_str+1); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
427 memcpy(exe_dir, exe_str, cur-exe_str); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
428 exe_dir[cur-exe_str] = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
429 break; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
430 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
431 } |
763
2a25ea5d94f7
Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
432 #ifdef HAS_PROC |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
433 } else { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
434 exe_dir = linktext; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
435 } |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
436 #endif |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
437 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
438 return exe_dir; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
439 } |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
440 #include <dirent.h> |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
441 |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
442 dir_entry *get_dir_list(char *path, size_t *numret) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
443 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
444 DIR *d = opendir(path); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
445 if (!d) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
446 if (numret) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
447 *numret = 0; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
448 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
449 return NULL; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
450 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
451 size_t storage = 64; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
452 dir_entry *ret = malloc(sizeof(dir_entry) * storage); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
453 size_t pos = 0; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
454 struct dirent* entry; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
455 while (entry = readdir(d)) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
456 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
457 if (entry->d_type != DT_REG && entry->d_type != DT_LNK && entry->d_type != DT_DIR) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
458 continue; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
459 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
460 if (pos == storage) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
461 storage = storage * 2; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
462 ret = realloc(ret, sizeof(dir_entry) * storage); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
463 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
464 ret[pos].name = strdup(entry->d_name); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
465 ret[pos++].is_dir = entry->d_type == DT_DIR; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
466 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
467 if (numret) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
468 *numret = pos; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
469 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
470 return ret; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
471 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
472 |
957 | 473 time_t get_modification_time(char *path) |
474 { | |
475 struct stat st; | |
476 if (stat(path, &st)) { | |
477 return 0; | |
478 } | |
1021 | 479 #ifdef __APPLE__ |
480 return st.st_mtimespec.tv_sec; | |
481 #else | |
957 | 482 return st.st_mtim.tv_sec; |
1021 | 483 #endif |
957 | 484 } |
485 | |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
486 int ensure_dir_exists(char *path) |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
487 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
488 struct stat st; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
489 if (stat(path, &st)) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
490 if (errno == ENOENT) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
491 char *parent = strdup(path); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
492 char *sep = strrchr(parent, '/'); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
493 if (sep && sep != parent) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
494 *sep = 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
495 if (!ensure_dir_exists(parent)) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
496 free(parent); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
497 return 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
498 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
499 free(parent); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
500 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
501 return mkdir(path, 0777) == 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
502 } else { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
503 char buf[80]; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
504 strerror_r(errno, buf, sizeof(buf)); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
505 warning("stat failed with error: %s", buf); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
506 return 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
507 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
508 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
509 return S_ISDIR(st.st_mode); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
510 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
511 |
741
80a67be1770b
Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents:
549
diff
changeset
|
512 #endif |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
513 |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
514 void free_dir_list(dir_entry *list, size_t numentries) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
515 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
516 for (size_t i = 0; i < numentries; i++) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
517 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
518 free(list[i].name); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
519 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
520 free(list); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
521 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
522 |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
523 #ifdef __ANDROID__ |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
524 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
525 #include <SDL.h> |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
526 char *read_bundled_file(char *name, long *sizeret) |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
527 { |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
528 SDL_RWops *rw = SDL_RWFromFile(name, "rb"); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
529 if (!rw) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
530 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
531 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
532 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
533 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
534 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
535 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
536 long fsize = rw->size(rw); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
537 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
538 *sizeret = fsize; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
539 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
540 char *ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
541 if (fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
542 ret = malloc(fsize); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
543 if (SDL_RWread(rw, ret, 1, fsize) != fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
544 free(ret); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
545 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
546 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
547 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
548 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
549 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
550 SDL_RWclose(rw); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
551 return ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
552 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
553 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
554 char const *get_config_dir() |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
555 { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
556 return SDL_AndroidGetInternalStoragePath(); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
557 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
558 |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
559 char const *get_save_dir() |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
560 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
561 return SDL_AndroidGetInternalStoragePath(); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
562 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
563 |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
564 #else |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
565 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
566 char *read_bundled_file(char *name, long *sizeret) |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
567 { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
568 char *exe_dir = get_exe_dir(); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
569 if (!exe_dir) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
570 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
571 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
572 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
573 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
574 } |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
575 char const *pieces[] = {exe_dir, PATH_SEP, name}; |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
576 char *path = alloc_concat_m(3, pieces); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
577 FILE *f = fopen(path, "rb"); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
578 free(path); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
579 if (!f) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
580 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
581 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
582 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
583 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
584 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
585 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
586 long fsize = file_size(f); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
587 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
588 *sizeret = fsize; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
589 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
590 char *ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
591 if (fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
592 //reserve an extra byte in case caller wants |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
593 //to null terminate the data |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
594 ret = malloc(fsize+1); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
595 if (fread(ret, 1, fsize, f) != fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
596 free(ret); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
597 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
598 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
599 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
600 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
601 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
602 return ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
603 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
604 |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
605 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
606 #ifdef _WIN32 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
607 char const *get_save_base_dir() |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
608 { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
609 static char path[MAX_PATH]; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
610 if (S_OK == SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)) |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
611 { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
612 return path; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
613 } |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
614 return NULL; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
615 } |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
616 #define CONFIG_PREFIX "" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
617 #define SAVE_PREFIX "" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
618 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
619 #else |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
620 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
621 #define get_save_base_dir get_home_dir |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
622 #define CONFIG_PREFIX "/.config" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
623 #define SAVE_PREFIX "/.local/share" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
624 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
625 #endif |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
626 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
627 char const *get_config_dir() |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
628 { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
629 static char* confdir; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
630 if (!confdir) { |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
631 char const *base = get_save_base_dir(); |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
632 if (base) { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
633 confdir = alloc_concat(base, CONFIG_PREFIX PATH_SEP "blastem"); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
634 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
635 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
636 return confdir; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
637 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
638 |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
639 char const *get_save_dir() |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
640 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
641 static char* savedir; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
642 if (!savedir) { |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
643 char const *base = get_save_base_dir(); |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
644 if (base) { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
645 savedir = alloc_concat(base, SAVE_PREFIX PATH_SEP "blastem"); |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
646 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
647 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
648 return savedir; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
649 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
650 |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
651 #endif |