Mercurial > repos > blastem
annotate paths.c @ 2279:3b5fef896475
Fix edge case in m68k_invalidate_code_range that caused problems when loading save states
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 Jan 2023 14:20:43 -0800 |
parents | bc68560b4a04 |
children | 2972a8e16ed2 |
rev | line source |
---|---|
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "blastem.h" |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "util.h" |
2262
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
5 #ifdef _WIN32 |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
6 #include <windows.h> |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
7 #else |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
8 #include <unistd.h> |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
9 #include <errno.h> |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
10 #endif |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 static char **current_path; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 static void persist_path(void) |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 { |
1673
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1524
diff
changeset
|
16 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 FILE *f = fopen(pathfname, "wb"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 if (f) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 if (fwrite(*current_path, 1, strlen(*current_path), f) != strlen(*current_path)) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 warning("Failed to save menu path"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 fclose(f); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 } else { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 warning("Failed to save menu path: Could not open %s for writing\n", pathfname); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 free(pathfname); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #ifdef __ANDROID__ |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #include <SDL.h> |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 #include <jni.h> |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 static char *get_external_storage_path() |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 static char *ret; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 if (ret) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 return ret; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 JNIEnv *env = SDL_AndroidGetJNIEnv(); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 if ((*env)->PushLocalFrame(env, 8) < 0) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 return NULL; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 jclass Environment = (*env)->FindClass(env, "android/os/Environment"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 jmethodID getExternalStorageDirectory = |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 (*env)->GetStaticMethodID(env, Environment, "getExternalStorageDirectory", "()Ljava/io/File;"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 jobject file = (*env)->CallStaticObjectMethod(env, Environment, getExternalStorageDirectory); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 if (!file) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 goto cleanup; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 jmethodID getAbsolutePath = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, file), |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 "getAbsolutePath", "()Ljava/lang/String;"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 jstring path = (*env)->CallObjectMethod(env, file, getAbsolutePath); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 char const *tmp = (*env)->GetStringUTFChars(env, path, NULL); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 ret = strdup(tmp); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 (*env)->ReleaseStringUTFChars(env, path, tmp); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 cleanup: |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 (*env)->PopLocalFrame(env, NULL); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 return ret; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 #endif |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 void get_initial_browse_path(char **dst) |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 { |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
68 char *base = NULL; |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 if (!remember_path || !strcmp("on", remember_path)) { |
1673
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1524
diff
changeset
|
71 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 FILE *f = fopen(pathfname, "rb"); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 if (f) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 long pathsize = file_size(f); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 if (pathsize > 0) { |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
76 base = malloc(pathsize + 1); |
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
77 if (fread(base, 1, pathsize, f) != pathsize) { |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 warning("Error restoring saved file browser path"); |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
79 free(base); |
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
80 base = NULL; |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } else { |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
82 base[pathsize] = 0; |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 fclose(f); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 free(pathfname); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 if (!current_path) { |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 atexit(persist_path); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 current_path = dst; |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 } |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
93 if (!base) { |
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
94 base = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
96 if (!base){ |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 #ifdef __ANDROID__ |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
98 base = get_external_storage_path(); |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 #else |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
100 base = "$HOME"; |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 #endif |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 } |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
1858
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
105 *dst = replace_vars(base, vars, 1); |
dda7479f3bbb
Fix a couple of small memory leaks
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
106 free(base); |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 tern_free(vars); |
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 } |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
109 |
1489
637fbc3b5063
Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
110 char *path_append(const char *base, const char *suffix) |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
111 { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
112 if (!strcmp(suffix, "..")) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
113 #ifdef _WIN32 |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
114 //handle transition from root of a drive to virtual root |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
115 if (base[1] == ':' && !base[2]) { |
1524
b96f9fae757f
Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
1489
diff
changeset
|
116 return strdup(PATH_SEP); |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
117 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
118 #endif |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
119 size_t len = strlen(base); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
120 while (len > 0) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
121 --len; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
122 if (is_path_sep(base[len])) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
123 if (!len) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
124 //special handling for / |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
125 len++; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
126 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
127 char *ret = malloc(len+1); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
128 memcpy(ret, base, len); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
129 ret[len] = 0; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
130 return ret; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
131 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
132 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
133 return strdup(PATH_SEP); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
134 } else { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
135 #ifdef _WIN32 |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
136 if (base[0] == PATH_SEP[0] && !base[1]) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
137 //handle transition from virtual root to root of a drive |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
138 return strdup(suffix); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
139 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
140 #endif |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
141 if (is_path_sep(base[strlen(base) - 1])) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
142 return alloc_concat(base, suffix); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
143 } else { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
144 char const *pieces[] = {base, PATH_SEP, suffix}; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
145 return alloc_concat_m(3, pieces); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
146 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
147 } |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
148 } |
2262
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
149 |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
150 char *path_current_dir(void) |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
151 { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
152 size_t size = 128; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
153 char *res = malloc(size); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
154 for (;;) { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
155 #ifdef _WIN32 |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
156 DWORD actual = GetCurrentDirectoryA(size, res); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
157 if (actual > size) { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
158 res = realloc(res, actual); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
159 size = actual; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
160 } else { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
161 return res; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
162 } |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
163 #else |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
164 errno = 0; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
165 char *tmp = getcwd(res, size); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
166 if (!tmp) { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
167 if (errno == ERANGE) { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
168 size *= 2; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
169 res = realloc(res, size); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
170 } else { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
171 free(res); |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
172 return NULL; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
173 } |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
174 } else { |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
175 return res; |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
176 } |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
177 #endif |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
178 } |
bc68560b4a04
Fix bug when loading cue sheet without leading path
Michael Pavone <pavone@retrodev.com>
parents:
1858
diff
changeset
|
179 } |