1
From 2492ef7700bb2f1fb787c24d2c54c07d18d92eb5 Mon Sep 17 00:00:00 2001
2
From: Sven Eckelmann <sven.eckelmann@gmx.de>
3
Date: Mon, 31 Aug 2009 23:29:24 +0200
4
Subject: [PATCH] Use XDG Base Directory compliant directories
6
The freedesktop standard for basedir[1] defines three different types of
7
user directories which mupen64plus uses. They are defined by environment
8
variables and in the case if they are absend by well defined standard
11
* Data directory ($XDG_DATA_HOME); default: $HOME/.local/share/
12
- save, screenshots, hires_texture, texture_dump
13
* Config directory ($XDG_CONFIG_HOME); default: $HOME/.config/
14
- mupen64plus.conf, configuration files of plugins
15
* Cache directory ($XDG_DATA_HOME); default: $HOME/.cache/
16
- rombrowser.cache and all other files which could be deleted
17
without loosing essential data
19
Specific directories for each tool should be created below that base
20
directories. libxdg-basedir can be used to find the correct paths
21
without caring much about the actual specification.
23
The current config dir has to be splitted in these three different
24
directories. That also means that plugins have to be informed about that
25
dirs. New functions SetDataDir and SetCacheDir have been specified
26
inside the API headers and implemented were the plugin would benefit
27
from it. This is the case in rice_video for texture_dump and
30
The user can also override the data and cache directories by the new
31
commandline options --datadir and --cachedir.
33
As there is no real specification for Windows available the behavior on
34
that platform was not changed.
36
[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
38
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
41
blight_input/Input_1.1.h | 22 +++++++
42
doc/Audio_1.1.h | 22 +++++++
43
doc/Audio_1.2.h | 22 +++++++
44
doc/Graphics_1.3.h | 22 +++++++
45
doc/Input_1.1.h | 22 +++++++
46
dummy_audio/Audio_1.1.h | 22 +++++++
47
dummy_input/Input_1.1.h | 22 +++++++
48
dummy_video/Graphics_1.3.h | 22 +++++++
49
glide64/Gfx1.3.h | 22 +++++++
50
jttl_audio/Audio_1.2.h | 22 +++++++
51
main/main.c | 123 ++++++++++++++++++++++++++++++++++------
53
main/plugin.c | 12 ++++-
55
main/romcache.c | 2 +-
57
rice_video/Graphics_1.3.h | 22 +++++++
58
rice_video/TextureFilters.cpp | 8 +-
59
rice_video/Video.cpp | 80 +++++++++++++++++++++++++-
60
rsp_hle/Audio_1.1.h | 22 +++++++
61
21 files changed, 474 insertions(+), 31 deletions(-)
63
diff --git a/Makefile b/Makefile
64
index be81163..dac741e 100644
67
@@ -237,8 +237,9 @@ SHARE = $(shell grep CONFIG_PATH config.h | cut -d '"' -f 2)
68
# set primary objects and libraries for all outputs
69
ALL = mupen64plus $(PLUGINS)
70
OBJECTS = $(OBJ_CORE) $(OBJ_DYNAREC) $(OBJ_OPENGL)
71
-LIBS = $(SDL_LIBS) $(LIBGL_LIBS) -lbz2
72
+LIBS = $(SDL_LIBS) $(LIBGL_LIBS) $(XDGBASEDIR_LIBS) -lbz2
74
+CFLAGS+= $(XDGBASEDIR_FLAGS)
76
# add extra objects and libraries for selected options
78
diff --git a/blight_input/Input_1.1.h b/blight_input/Input_1.1.h
79
index c2ae4a6..1a22c4b 100644
80
--- a/blight_input/Input_1.1.h
81
+++ b/blight_input/Input_1.1.h
82
@@ -251,6 +251,28 @@ EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam );
83
*******************************************************************/
84
EXPORT void CALL SetConfigDir( char *configDir );
86
+/******************************************************************
87
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
89
+ Function: SetDataDir
90
+ Purpose: To pass the location where data files should be read/
92
+ input: path to data directory
94
+*******************************************************************/
95
+EXPORT void CALL SetDataDir( char *dataDir );
97
+/******************************************************************
98
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
100
+ Function: SetCacheDir
101
+ Purpose: To pass the location where cache files should be read/
103
+ input: path to cache directory
105
+*******************************************************************/
106
+EXPORT void CALL SetCacheDir( char *cacheDir );
108
#if defined(__cplusplus)
111
diff --git a/doc/Audio_1.1.h b/doc/Audio_1.1.h
112
index ea46b2d..7a6f68b 100644
113
--- a/doc/Audio_1.1.h
114
+++ b/doc/Audio_1.1.h
115
@@ -224,6 +224,28 @@ EXPORT void CALL RomClosed (void);
116
*******************************************************************/
117
EXPORT void CALL SetConfigDir( char *configDir );
119
+/******************************************************************
120
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
122
+ Function: SetDataDir
123
+ Purpose: To pass the location where data files should be read/
125
+ input: path to data directory
127
+*******************************************************************/
128
+EXPORT void CALL SetDataDir( char *dataDir );
130
+/******************************************************************
131
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
133
+ Function: SetCacheDir
134
+ Purpose: To pass the location where cache files should be read/
136
+ input: path to cache directory
138
+*******************************************************************/
139
+EXPORT void CALL SetCacheDir( char *cacheDir );
141
#if defined(__cplusplus)
144
diff --git a/doc/Audio_1.2.h b/doc/Audio_1.2.h
145
index 0decf07..43045c2 100644
146
--- a/doc/Audio_1.2.h
147
+++ b/doc/Audio_1.2.h
148
@@ -239,6 +239,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
149
/******************************************************************
150
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
152
+ Function: SetDataDir
153
+ Purpose: To pass the location where data files should be read/
155
+ input: path to data directory
157
+*******************************************************************/
158
+EXPORT void CALL SetDataDir( char *dataDir );
160
+/******************************************************************
161
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
163
+ Function: SetCacheDir
164
+ Purpose: To pass the location where cache files should be read/
166
+ input: path to cache directory
168
+*******************************************************************/
169
+EXPORT void CALL SetCacheDir( char *cacheDir );
171
+/******************************************************************
172
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
175
Purpose: To increase the audio volume
177
diff --git a/doc/Graphics_1.3.h b/doc/Graphics_1.3.h
178
index 0f7843d..ed933b3 100644
179
--- a/doc/Graphics_1.3.h
180
+++ b/doc/Graphics_1.3.h
181
@@ -306,6 +306,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
182
/******************************************************************
183
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
185
+ Function: SetDataDir
186
+ Purpose: To pass the location where data files should be read/
188
+ input: path to data directory
190
+*******************************************************************/
191
+EXPORT void CALL SetDataDir( char *dataDir );
193
+/******************************************************************
194
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
196
+ Function: SetCacheDir
197
+ Purpose: To pass the location where cache files should be read/
199
+ input: path to cache directory
201
+*******************************************************************/
202
+EXPORT void CALL SetCacheDir( char *cacheDir );
204
+/******************************************************************
205
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
207
Function: SetRenderingCallback
208
Purpose: Allows emulator to register a callback function that will
209
be called by the graphics plugin just before the the
210
diff --git a/doc/Input_1.1.h b/doc/Input_1.1.h
211
index c2ae4a6..1a22c4b 100644
212
--- a/doc/Input_1.1.h
213
+++ b/doc/Input_1.1.h
214
@@ -251,6 +251,28 @@ EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam );
215
*******************************************************************/
216
EXPORT void CALL SetConfigDir( char *configDir );
218
+/******************************************************************
219
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
221
+ Function: SetDataDir
222
+ Purpose: To pass the location where data files should be read/
224
+ input: path to data directory
226
+*******************************************************************/
227
+EXPORT void CALL SetDataDir( char *dataDir );
229
+/******************************************************************
230
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
232
+ Function: SetCacheDir
233
+ Purpose: To pass the location where cache files should be read/
235
+ input: path to cache directory
237
+*******************************************************************/
238
+EXPORT void CALL SetCacheDir( char *cacheDir );
240
#if defined(__cplusplus)
243
diff --git a/dummy_audio/Audio_1.1.h b/dummy_audio/Audio_1.1.h
244
index ea46b2d..7a6f68b 100644
245
--- a/dummy_audio/Audio_1.1.h
246
+++ b/dummy_audio/Audio_1.1.h
247
@@ -224,6 +224,28 @@ EXPORT void CALL RomClosed (void);
248
*******************************************************************/
249
EXPORT void CALL SetConfigDir( char *configDir );
251
+/******************************************************************
252
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
254
+ Function: SetDataDir
255
+ Purpose: To pass the location where data files should be read/
257
+ input: path to data directory
259
+*******************************************************************/
260
+EXPORT void CALL SetDataDir( char *dataDir );
262
+/******************************************************************
263
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
265
+ Function: SetCacheDir
266
+ Purpose: To pass the location where cache files should be read/
268
+ input: path to cache directory
270
+*******************************************************************/
271
+EXPORT void CALL SetCacheDir( char *cacheDir );
273
#if defined(__cplusplus)
276
diff --git a/dummy_input/Input_1.1.h b/dummy_input/Input_1.1.h
277
index c2ae4a6..1a22c4b 100644
278
--- a/dummy_input/Input_1.1.h
279
+++ b/dummy_input/Input_1.1.h
280
@@ -251,6 +251,28 @@ EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam );
281
*******************************************************************/
282
EXPORT void CALL SetConfigDir( char *configDir );
284
+/******************************************************************
285
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
287
+ Function: SetDataDir
288
+ Purpose: To pass the location where data files should be read/
290
+ input: path to data directory
292
+*******************************************************************/
293
+EXPORT void CALL SetDataDir( char *dataDir );
295
+/******************************************************************
296
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
298
+ Function: SetCacheDir
299
+ Purpose: To pass the location where cache files should be read/
301
+ input: path to cache directory
303
+*******************************************************************/
304
+EXPORT void CALL SetCacheDir( char *cacheDir );
306
#if defined(__cplusplus)
309
diff --git a/dummy_video/Graphics_1.3.h b/dummy_video/Graphics_1.3.h
310
index 0f7843d..ed933b3 100644
311
--- a/dummy_video/Graphics_1.3.h
312
+++ b/dummy_video/Graphics_1.3.h
313
@@ -306,6 +306,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
314
/******************************************************************
315
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
317
+ Function: SetDataDir
318
+ Purpose: To pass the location where data files should be read/
320
+ input: path to data directory
322
+*******************************************************************/
323
+EXPORT void CALL SetDataDir( char *dataDir );
325
+/******************************************************************
326
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
328
+ Function: SetCacheDir
329
+ Purpose: To pass the location where cache files should be read/
331
+ input: path to cache directory
333
+*******************************************************************/
334
+EXPORT void CALL SetCacheDir( char *cacheDir );
336
+/******************************************************************
337
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
339
Function: SetRenderingCallback
340
Purpose: Allows emulator to register a callback function that will
341
be called by the graphics plugin just before the the
342
diff --git a/glide64/Gfx1.3.h b/glide64/Gfx1.3.h
343
index b34c1b4..91bd0e6 100644
344
--- a/glide64/Gfx1.3.h
345
+++ b/glide64/Gfx1.3.h
346
@@ -754,6 +754,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
347
/******************************************************************
348
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
350
+ Function: SetDataDir
351
+ Purpose: To pass the location where data files should be read/
353
+ input: path to data directory
355
+*******************************************************************/
356
+EXPORT void CALL SetDataDir( char *dataDir );
358
+/******************************************************************
359
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
361
+ Function: SetCacheDir
362
+ Purpose: To pass the location where cache files should be read/
364
+ input: path to cache directory
366
+*******************************************************************/
367
+EXPORT void CALL SetCacheDir( char *cacheDir );
369
+/******************************************************************
370
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
372
Function: SetRenderingCallback
373
Purpose: Allows emulator to register a callback function that will
374
be called by the graphics plugin just before the the
375
diff --git a/jttl_audio/Audio_1.2.h b/jttl_audio/Audio_1.2.h
376
index 0decf07..43045c2 100644
377
--- a/jttl_audio/Audio_1.2.h
378
+++ b/jttl_audio/Audio_1.2.h
379
@@ -239,6 +239,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
380
/******************************************************************
381
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
383
+ Function: SetDataDir
384
+ Purpose: To pass the location where data files should be read/
386
+ input: path to data directory
388
+*******************************************************************/
389
+EXPORT void CALL SetDataDir( char *dataDir );
391
+/******************************************************************
392
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
394
+ Function: SetCacheDir
395
+ Purpose: To pass the location where cache files should be read/
397
+ input: path to cache directory
399
+*******************************************************************/
400
+EXPORT void CALL SetCacheDir( char *cacheDir );
402
+/******************************************************************
403
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
406
Purpose: To increase the audio volume
408
diff --git a/main/main.c b/main/main.c
409
index d57bafd..3c88498 100644
414
# include <ucontext.h> // extra signal types (for portability)
415
# include <libgen.h> // basename, dirname
416
+# include <basedir.h> // xdg(Init|Wipe)Handle, xdg(Config|Data|Cache)Home
417
+# include <basedir_fs.h> // xdgMakePath
420
#include <sys/time.h>
421
@@ -152,6 +154,8 @@ static int l_GuiEnabled = 1; // GUI enabled?
424
static char l_ConfigDir[PATH_MAX] = {'\0'};
425
+static char l_DataDir[PATH_MAX] = {'\0'};
426
+static char l_CacheDir[PATH_MAX] = {'\0'};
427
static char l_InstallDir[PATH_MAX] = {'\0'};
429
static int l_EmuMode = 0; // emumode specified at commandline?
430
@@ -173,6 +177,16 @@ char *get_configpath()
434
+char *get_datapath()
439
+char *get_cachepath()
444
char *get_installpath()
447
@@ -181,7 +195,7 @@ char *get_installpath()
448
char *get_savespath()
450
static char path[PATH_MAX];
451
- strncpy(path, get_configpath(), PATH_MAX-5);
452
+ strncpy(path, get_datapath(), PATH_MAX-5);
453
strcat(path, "save/");
456
@@ -1075,6 +1089,8 @@ void parseCommandLine(int argc, char **argv)
465
@@ -1096,6 +1112,8 @@ void parseCommandLine(int argc, char **argv)
466
{"emumode", required_argument, NULL, OPT_EMUMODE},
467
{"sshotdir", required_argument, NULL, OPT_SSHOTDIR},
468
{"configdir", required_argument, NULL, OPT_CONFIGDIR},
469
+ {"datadir", required_argument, NULL, OPT_DATADIR},
470
+ {"cachedir", required_argument, NULL, OPT_CACHEDIR},
471
{"installdir", required_argument, NULL, OPT_INSTALLDIR},
473
{"debugger", no_argument, NULL, OPT_DEBUGGER},
474
@@ -1180,6 +1198,18 @@ void parseCommandLine(int argc, char **argv)
476
printf("***Warning: Config directory '%s' is not accessible or not a directory.\n", optarg);
480
+ strncpy(l_CacheDir, optarg, PATH_MAX);
482
+ printf("***Warning: Cache directory '%s' is not accessible or not a directory.\n", optarg);
486
+ strncpy(l_CacheDir, optarg, PATH_MAX);
488
+ printf("***Warning: Cache directory '%s' is not accessible or not a directory.\n", optarg);
492
strncpy(l_InstallDir, optarg, PATH_MAX);
493
@@ -1249,49 +1279,79 @@ void parseCommandLine(int argc, char **argv)
496
* setup paths to config/install/screenshot directories. The config dir is the dir where all
497
- * user config information is stored, e.g. mupen64plus.conf, save files, and plugin conf files.
498
+ * user config information is stored, e.g. mupen64plus.conf, and plugin conf files.
499
* The install dir is where mupen64plus looks for common files, e.g. plugins, icons, language
501
+ * The cache dir is where mupen64plus looks for rombrowser and similar caches.
502
+ * The data dir is where mupen64plus looks for savegames, hires-textures and saves screenshots.
504
static void setPaths(void)
507
strncpy(l_ConfigDir, "./", PATH_MAX);
508
+ strncpy(l_DataDir, "./", PATH_MAX);
509
+ strncpy(l_CacheDir, "./", PATH_MAX);
510
strncpy(l_InstallDir, "./", PATH_MAX);
513
char buf[PATH_MAX], buf2[PATH_MAX];
514
+ xdgHandle xdgbasedirs;
516
+ xdgInitHandle(&xdgbasedirs);
518
- // if the config dir was not specified at the commandline, look for ~/.mupen64plus dir
519
+ // if the config dir was not specified at the commandline, look for ~/.config/mupen64plus dir
520
if (strlen(l_ConfigDir) == 0)
522
- strncpy(l_ConfigDir, getenv("HOME"), PATH_MAX);
523
- strncat(l_ConfigDir, "/.mupen64plus", PATH_MAX - strlen(l_ConfigDir));
524
+ strncpy(l_ConfigDir, xdgConfigHome(&xdgbasedirs), PATH_MAX);
525
+ strncat(l_ConfigDir, "/mupen64plus", PATH_MAX - strlen(l_ConfigDir));
527
- // if ~/.mupen64plus dir is not found, create it
528
+ // if ~/.config/mupen64plus is not found, create it
529
if(!isdir(l_ConfigDir))
531
- printf("Creating %s to store user data\n", l_ConfigDir);
532
- if(mkdir(l_ConfigDir, (mode_t)0755) != 0)
533
+ printf("Creating %s to store user config\n", l_ConfigDir);
534
+ if(xdgMakePath(l_ConfigDir, (mode_t)0755) != 0)
536
printf("Error: Could not create %s: ", l_ConfigDir);
543
+ // make sure config dir has a '/' on the end.
544
+ if(l_ConfigDir[strlen(l_ConfigDir)-1] != '/')
545
+ strncat(l_ConfigDir, "/", PATH_MAX - strlen(l_ConfigDir));
547
+ // if the data dir was not specified at the commandline, look for ~/.local/share/mupen64plus dir
548
+ if (strlen(l_DataDir) == 0)
550
+ strncpy(l_DataDir, xdgDataHome(&xdgbasedirs), PATH_MAX);
551
+ strncat(l_DataDir, "/mupen64plus", PATH_MAX - strlen(l_DataDir));
553
+ // if ~/.local/share/mupen64plus dir is not found, create it
554
+ if(!isdir(l_DataDir))
556
+ printf("Creating %s to store user data\n", l_DataDir);
557
+ if(xdgMakePath(l_DataDir, (mode_t)0755) != 0)
559
+ printf("Error: Could not create %s: ", l_DataDir);
564
// create save subdir
565
- strncpy(buf, l_ConfigDir, PATH_MAX);
566
+ strncpy(buf, l_DataDir, PATH_MAX);
567
strncat(buf, "/save", PATH_MAX - strlen(buf));
568
- if(mkdir(buf, (mode_t)0755) != 0)
569
+ if(xdgMakePath(buf, (mode_t)0755) != 0)
571
// report error, but don't exit
572
printf("Warning: Could not create %s: %s", buf, strerror(errno));
575
// create screenshots subdir
576
- strncpy(buf, l_ConfigDir, PATH_MAX);
577
+ strncpy(buf, l_DataDir, PATH_MAX);
578
strncat(buf, "/screenshots", PATH_MAX - strlen(buf));
579
- if(mkdir(buf, (mode_t)0755) != 0)
580
+ if(xdgMakePath(buf, (mode_t)0755) != 0)
582
// report error, but don't exit
583
printf("Warning: Could not create %s: %s", buf, strerror(errno));
584
@@ -1299,9 +1359,34 @@ static void setPaths(void)
588
- // make sure config dir has a '/' on the end.
589
- if(l_ConfigDir[strlen(l_ConfigDir)-1] != '/')
590
- strncat(l_ConfigDir, "/", PATH_MAX - strlen(l_ConfigDir));
591
+ // make sure data dir has a '/' on the end.
592
+ if(l_DataDir[strlen(l_DataDir)-1] != '/')
593
+ strncat(l_DataDir, "/", PATH_MAX - strlen(l_DataDir));
595
+ // if the cache dir was not specified at the commandline, look for ~/.cache/mupen64plus dir
596
+ if (strlen(l_CacheDir) == 0)
598
+ strncpy(l_CacheDir, xdgCacheHome(&xdgbasedirs), PATH_MAX);
599
+ strncat(l_CacheDir, "/mupen64plus", PATH_MAX - strlen(l_CacheDir));
601
+ // if ~/.cache/mupen64plus dir is not found, create it
602
+ if(!isdir(l_CacheDir))
604
+ printf("Creating %s to store user cache\n", l_CacheDir);
605
+ if(xdgMakePath(l_CacheDir, (mode_t)0755) != 0)
607
+ printf("Error: Could not create %s: ", l_CacheDir);
614
+ // make sure cache dir has a '/' on the end.
615
+ if(l_CacheDir[strlen(l_CacheDir)-1] != '/')
616
+ strncat(l_CacheDir, "/", PATH_MAX - strlen(l_CacheDir));
618
+ xdgWipeHandle(&xdgbasedirs);
620
// if install dir was not specified at the commandline, look for it in the executable's directory
621
if (strlen(l_InstallDir) == 0)
622
@@ -1400,7 +1485,7 @@ static void setPaths(void)
623
if (!ValidScreenshotDir())
625
char chDefaultDir[PATH_MAX + 1];
626
- snprintf(chDefaultDir, PATH_MAX, "%sscreenshots/", l_ConfigDir);
627
+ snprintf(chDefaultDir, PATH_MAX, "%sscreenshots/", l_DataDir);
628
SetScreenshotDir(chDefaultDir);
630
#endif /* __WIN32__ */
631
@@ -1481,7 +1566,7 @@ int main(int argc, char *argv[])
633
// scan the plugin directory and set the config dir for the plugins
634
plugin_scan_directory(dirpath);
635
- plugin_set_dirs(l_ConfigDir, l_InstallDir);
636
+ plugin_set_dirs(l_ConfigDir, l_DataDir, l_CacheDir, l_InstallDir);
640
@@ -1500,8 +1585,8 @@ int main(int argc, char *argv[])
641
config_put_number("CurrentSaveSlot",0);
644
- main_message(1, 0, 0, 0, tr("Config Dir: %s\nInstall Dir: %s\nPlugin Dir: %s\n"), l_ConfigDir, l_InstallDir, dirpath);
645
- main_message(0, 1, 0, 0, tr("Config Dir: \"%s\", Install Dir: \"%s\", Plugin Dir: \"%s\""), l_ConfigDir, l_InstallDir, dirpath);
646
+ main_message(1, 0, 0, 0, tr("Config Dir: %s\nData Dir: %s\nCache Dir: %s\nInstall Dir: %s\nPlugin Dir: %s\n"), l_ConfigDir, l_DataDir, l_CacheDir, l_InstallDir, dirpath);
647
+ main_message(0, 1, 0, 0, tr("Config Dir: \"%s\", Data Dir: \"%s\", Cache Dir: \"%s\", Install Dir: \"%s\", Plugin Dir: \"%s\""), l_ConfigDir, l_DataDir, l_CacheDir, l_InstallDir, dirpath);
649
//The database needs to be opened regardless of GUI mode.
651
diff --git a/main/main.h b/main/main.h
652
index e597ad2..7cec0e0 100644
655
@@ -40,6 +40,8 @@ extern char* g_InputPlugin;
656
extern char* g_RspPlugin;
658
char* get_configpath(void);
659
+char* get_datapath(void);
660
+char* get_cachepath(void);
661
char* get_installpath(void);
662
char* get_savespath(void);
663
char* get_iconspath(void);
664
diff --git a/main/plugin.c b/main/plugin.c
665
index 92752be..b377ff0 100644
668
@@ -66,6 +66,8 @@ static void dummy_readController(int Control, BYTE *Command) {}
669
static void dummy_keyDown(WPARAM wParam, LPARAM lParam) {}
670
static void dummy_keyUp(WPARAM wParam, LPARAM lParam) {}
671
static void dummy_setConfigDir(char *configDir) {}
672
+static void dummy_setDataDir(char *dataDir) {}
673
+static void dummy_setCacheDir(char *cacheDir) {}
674
static void dummy_setInstallDir(char *installDir) {}
675
static unsigned int dummy;
676
static DWORD dummy_doRspCycles(DWORD Cycles) { return Cycles; };
677
@@ -115,6 +117,8 @@ void (*romOpen_input)() = dummy_void;
678
void (*keyDown)(WPARAM wParam, LPARAM lParam) = dummy_keyDown;
679
void (*keyUp)(WPARAM wParam, LPARAM lParam) = dummy_keyUp;
680
void (*setConfigDir)(char *configDir) = dummy_setConfigDir;
681
+void (*setDataDir)(char *dataDir) = dummy_setDataDir;
682
+void (*setCacheDir)(char *cacheDir) = dummy_setCacheDir;
683
void (*setInstallDir)(char *installDir) = dummy_setInstallDir;
685
void (*closeDLL_RSP)() = dummy_void;
686
@@ -271,7 +275,7 @@ void plugin_scan_directory(const char *plugindir)
687
/* plugin_set_configdir
688
* Sets config dir of all plugins that support the SetConfigDir API call to the given dir.
690
-void plugin_set_dirs(char* configdir, char* installdir)
691
+void plugin_set_dirs(char* configdir, char* datadir, char* cachedir, char* installdir)
695
@@ -286,6 +290,12 @@ void plugin_set_dirs(char* configdir, char* installdir)
696
setConfigDir = dlsym(p->handle, "SetConfigDir");
698
setConfigDir(configdir);
699
+ setDataDir = dlsym(p->handle, "SetDataDir");
701
+ setDataDir(datadir);
702
+ setCacheDir = dlsym(p->handle, "SetCacheDir");
704
+ setCacheDir(cachedir);
705
setInstallDir = dlsym(p->handle, "SetInstallDir");
707
setInstallDir(installdir);
708
diff --git a/main/plugin.h b/main/plugin.h
709
index 35f4f43..4b6264a 100644
712
@@ -38,7 +38,7 @@ extern list_t g_PluginList;
714
int plugin_scan_file(const char *filepath, WORD PluginType);
715
void plugin_scan_directory(const char *plugindir);
716
-void plugin_set_dirs(char* configdir, char* installdir);
717
+void plugin_set_dirs(char* configdir, char* datadir, char* cachedir, char* installdir);
718
void plugin_load_plugins(const char *gfx_name,
719
const char *audio_name,
720
const char *input_name,
721
diff --git a/main/romcache.c b/main/romcache.c
722
index 5f31cc8..5ec3f40 100644
723
--- a/main/romcache.c
724
+++ b/main/romcache.c
725
@@ -258,7 +258,7 @@ int rom_cache_system(void* _arg)
728
buffer = (char*)malloc(PATH_MAX*sizeof(char));
729
- snprintf(buffer, PATH_MAX, "%s%s", get_configpath(), "rombrowser.cache");
730
+ snprintf(buffer, PATH_MAX, "%s%s", get_cachepath(), "rombrowser.cache");
731
config_put_string("RomCacheFile", buffer);
734
diff --git a/pre.mk b/pre.mk
735
index d2eb261..5c7b73c 100644
738
@@ -101,6 +101,15 @@ GTK_FLAGS = $(shell pkg-config gtk+-2.0 --cflags)
739
GTK_LIBS = $(shell pkg-config gtk+-2.0 --libs)
740
GTHREAD_LIBS = $(shell pkg-config gthread-2.0 --libs)
742
+# test for presence of libxdg-basedir
743
+ifeq ("$(shell pkg-config libxdg-basedir --modversion )", "")
744
+ $(error No libxdg-basedir development libraries found!)
747
+# set libxdg-basedir flags and libraries
748
+XDGBASEDIR_FLAGS = $(shell pkg-config libxdg-basedir --cflags)
749
+XDGBASEDIR_LIBS = $(shell pkg-config libxdg-basedir --libs)
751
# set Qt flags and libraries
752
# some distros append -qt4 to the binaries so look for those first
754
diff --git a/rice_video/Graphics_1.3.h b/rice_video/Graphics_1.3.h
755
index 0f7843d..ed933b3 100644
756
--- a/rice_video/Graphics_1.3.h
757
+++ b/rice_video/Graphics_1.3.h
758
@@ -306,6 +306,28 @@ EXPORT void CALL SetConfigDir( char *configDir );
759
/******************************************************************
760
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
762
+ Function: SetDataDir
763
+ Purpose: To pass the location where data files should be read/
765
+ input: path to data directory
767
+*******************************************************************/
768
+EXPORT void CALL SetDataDir( char *dataDir );
770
+/******************************************************************
771
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
773
+ Function: SetCacheDir
774
+ Purpose: To pass the location where cache files should be read/
776
+ input: path to cache directory
778
+*******************************************************************/
779
+EXPORT void CALL SetCacheDir( char *cacheDir );
781
+/******************************************************************
782
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
784
Function: SetRenderingCallback
785
Purpose: Allows emulator to register a callback function that will
786
be called by the graphics plugin just before the the
787
diff --git a/rice_video/TextureFilters.cpp b/rice_video/TextureFilters.cpp
788
index e59f797..f8341fe 100644
789
--- a/rice_video/TextureFilters.cpp
790
+++ b/rice_video/TextureFilters.cpp
791
@@ -901,7 +901,7 @@ typedef struct {
792
CSortedList<uint64,ExtTxtrInfo> gTxtrDumpInfos;
793
CSortedList<uint64,ExtTxtrInfo> gHiresTxtrInfos;
795
-extern void GetPluginDir( char * Directory );
796
+extern void GetDataDir( char * Directory );
797
extern char * right(char * src, int nchars);
799
BOOL PathIsDirectory(char* name)
800
@@ -1238,7 +1238,7 @@ const char *subfolders[] = {
801
void FindAllDumpedTextures(void)
803
char foldername[PATH_MAX];
804
- GetPluginDir(foldername);
805
+ GetDataDir(foldername);
806
if(foldername[strlen(foldername) - 1] != '/') strcat(foldername, "/");
807
strcat(foldername,"texture_dump/");
809
@@ -1279,7 +1279,7 @@ void FindAllDumpedTextures(void)
810
void FindAllHiResTextures(void)
812
char foldername[PATH_MAX];
813
- GetPluginDir(foldername);
814
+ GetDataDir(foldername);
815
if(foldername[strlen(foldername) - 1] != '/') strcat(foldername, "/");
816
strcat(foldername,"hires_texture/");
817
CheckAndCreateFolder(foldername);
818
@@ -1448,7 +1448,7 @@ void DumpCachedTexture( TxtrCacheEntry &entry )
819
char filename2[PATH_MAX];
820
char filename3[PATH_MAX];
821
char gamefolder[PATH_MAX];
822
- GetPluginDir(gamefolder);
823
+ GetDataDir(gamefolder);
825
strcat(gamefolder,"texture_dump/");
826
strcat(gamefolder,(const char*)g_curRomInfo.szGameName);
827
diff --git a/rice_video/Video.cpp b/rice_video/Video.cpp
828
index 3f3cc05..75e3ad8 100644
829
--- a/rice_video/Video.cpp
830
+++ b/rice_video/Video.cpp
831
@@ -41,6 +41,8 @@ unsigned char *g_pRDRAMu8 = NULL;
833
static char g_ConfigDir[PATH_MAX] = {0};
835
+static char g_DataDir[PATH_MAX] = {0};
837
CCritSect g_CritialSection;
839
///#define USING_THREAD
840
@@ -68,7 +70,7 @@ std::vector<uint32> frameWriteRecord;
842
//---------------------------------------------------------------------------------------
844
-void GetPluginDir( char * Directory )
845
+void GetPluginDir( char * Directory )
847
if(strlen(g_ConfigDir) > 0)
849
@@ -86,7 +88,7 @@ void GetPluginDir( char * Directory )
851
char path2[PATH_MAX];
857
for (i=strlen(path2)-1; i>0; i--)
858
@@ -99,7 +101,63 @@ void GetPluginDir( char * Directory )
860
struct dirent *entry;
865
+ dir = opendir(path2);
866
+ while((entry = readdir(dir)) != NULL)
868
+ if(!strcmp(entry->d_name, "plugins"))
872
+ if(!gooddir) strcpy(path, "./");
876
+ for(i=strlen(path)-1; i>0; i--)
878
+ if(path[i] == '/') break;
881
+ strcat(path, "plugins/");
882
+ strcpy(Directory, path);
886
+//---------------------------------------------------------------------------------------
888
+void GetDataDir( char * Directory )
890
+ if(strlen(g_DataDir) > 0)
892
+ strncpy(Directory, g_DataDir, PATH_MAX);
893
+ // make sure there's a trailing '/'
894
+ if(Directory[strlen(Directory)-1] != '/')
895
+ strncat(Directory, "/", PATH_MAX - strlen(Directory));
899
+ char path[PATH_MAX];
900
+ int n = readlink("/proc/self/exe", path, PATH_MAX);
901
+ if(n == -1) strcpy(path, "./");
904
+ char path2[PATH_MAX];
908
+ strcpy(path2, path);
909
+ for (i=strlen(path2)-1; i>0; i--)
911
+ if(path2[i] == '/') break;
913
+ if(i == 0) strcpy(path, "./");
917
+ struct dirent *entry;
921
dir = opendir(path2);
922
while((entry = readdir(dir)) != NULL)
923
@@ -1084,7 +1142,7 @@ EXPORT void CALL ReadScreen(void **dest, int *width, int *height)
924
GL_RGB, GL_UNSIGNED_BYTE, *dest );
925
glReadBuffer( oldMode );
929
/******************************************************************
930
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
932
@@ -1102,6 +1160,20 @@ EXPORT void CALL SetConfigDir(char *configDir)
933
/******************************************************************
934
NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
936
+ Function: SetDataDir
937
+ Purpose: To pass the location where data files should be read/
939
+ input: path to data directory
941
+*******************************************************************/
942
+EXPORT void CALL SetDataDir(char *dataDir)
944
+ strncpy(g_DataDir, dataDir, PATH_MAX);
947
+/******************************************************************
948
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
950
Function: SetRenderingCallback
951
Purpose: Allows emulator to register a callback function that will
952
be called by the graphics plugin just before the the
953
diff --git a/rsp_hle/Audio_1.1.h b/rsp_hle/Audio_1.1.h
954
index ea46b2d..7a6f68b 100644
955
--- a/rsp_hle/Audio_1.1.h
956
+++ b/rsp_hle/Audio_1.1.h
957
@@ -224,6 +224,28 @@ EXPORT void CALL RomClosed (void);
958
*******************************************************************/
959
EXPORT void CALL SetConfigDir( char *configDir );
961
+/******************************************************************
962
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
964
+ Function: SetDataDir
965
+ Purpose: To pass the location where data files should be read/
967
+ input: path to data directory
969
+*******************************************************************/
970
+EXPORT void CALL SetDataDir( char *dataDir );
972
+/******************************************************************
973
+ NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
975
+ Function: SetCacheDir
976
+ Purpose: To pass the location where cache files should be read/
978
+ input: path to cache directory
980
+*******************************************************************/
981
+EXPORT void CALL SetCacheDir( char *cacheDir );
983
#if defined(__cplusplus)