Package: visualboyadvance / 1.8.0.dfsg-4

01_use_dot_dir.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Author: Jose Carlos Medeiros <debian@psabs.com.br>
Description: Use a .vba dir to store all screen captures, save states and batteries.
--- a/src/sdl/SDL.cpp
+++ b/src/sdl/SDL.cpp
@@ -177,6 +177,10 @@
 char captureDir[2048];
 char saveDir[2048];
 char batteryDir[2048];
+char* homeDir = NULL;
+
+/* Directory within homedir to use for default save location. */
+#define DOT_DIR ".vba"
 
 static char *rewindMemory = NULL;
 static int rewindPos = 0;
@@ -888,11 +892,10 @@
     return f;
   }
 
-  char *home = getenv("HOME");
-
-  if(home != NULL) {
-    fprintf(stderr, "Searching home directory: %s\n", home);
-    sprintf(path, "%s%c%s", home, FILE_SEP, name);
+  if(homeDir) {
+    fprintf(stderr, "Searching home directory: %s%c%s\n", homeDir, FILE_SEP,
+        DOT_DIR);
+    sprintf(path, "%s%c%s%c%s", homeDir, FILE_SEP, DOT_DIR, FILE_SEP, name);
     f = fopen(path, "r");
     if(f != NULL)
       return f;
@@ -1356,6 +1359,8 @@
   if(saveDir[0])
     sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename),
             num+1);
+  else if (homeDir)
+    sprintf(stateName, "%s/%s/%s%d.sgm", homeDir, DOT_DIR, sdlGetFilename(filename), num + 1);
   else
     sprintf(stateName,"%s%d.sgm", filename, num+1);
   
@@ -1375,6 +1380,8 @@
   if(saveDir[0])
     sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename),
             num+1);
+  else if (homeDir)
+    sprintf(stateName, "%s/%s/%s%d.sgm", homeDir, DOT_DIR, sdlGetFilename(filename), num + 1);
   else
     sprintf(stateName,"%s%d.sgm", filename, num+1);
 
@@ -1393,6 +1400,8 @@
 
   if(batteryDir[0])
     sprintf(buffer, "%s/%s.sav", batteryDir, sdlGetFilename(filename));
+  else if (homeDir)
+    sprintf(buffer, "%s/%s/%s.sav", homeDir, DOT_DIR, sdlGetFilename(filename));
   else  
     sprintf(buffer, "%s.sav", filename);
 
@@ -1407,6 +1416,8 @@
   
   if(batteryDir[0])
     sprintf(buffer, "%s/%s.sav", batteryDir, sdlGetFilename(filename));
+  else if (homeDir)
+    sprintf(buffer, "%s/%s/%s.sav", homeDir, DOT_DIR, sdlGetFilename(filename));
   else 
     sprintf(buffer, "%s.sav", filename);
   
@@ -1947,6 +1958,7 @@
 
 int main(int argc, char **argv)
 {
+  char buf[1024];
   fprintf(stderr, "VisualBoyAdvance version %s [SDL]\n", VERSION);
 
   arg0 = argv[0];
@@ -1957,12 +1969,19 @@
   ipsname[0] = 0;
   
   int op = -1;
+  struct stat s;
 
   frameSkip = 2;
   gbBorderOn = 0;
 
   parseDebug = true;
 
+  homeDir = getenv("HOME");
+  snprintf(buf, 1024, "%s/%s", homeDir, DOT_DIR);
+  /* Make dot dir if not existent */
+  if (stat(buf, &s) == -1 || !S_ISDIR(s.st_mode))
+    mkdir(buf, 0755);
+
   sdlReadPreferences();
 
   sdlPrintUsage = 0;
@@ -2907,6 +2926,8 @@
   if(captureFormat) {
     if(captureDir[0])
       sprintf(buffer, "%s/%s%02d.bmp", captureDir, sdlGetFilename(filename), a);
+    else if (homeDir)
+      sprintf(buffer, "%s/%s/%s%02d.bmp", homeDir, DOT_DIR, sdlGetFilename(filename), a);
     else
       sprintf(buffer, "%s%02d.bmp", filename, a);
 
@@ -2914,6 +2935,8 @@
   } else {
     if(captureDir[0])
       sprintf(buffer, "%s/%s%02d.png", captureDir, sdlGetFilename(filename), a);
+    else if (homeDir)
+      sprintf(buffer, "%s/%s/%s%02d.png", homeDir, DOT_DIR, sdlGetFilename(filename), a);
     else
       sprintf(buffer, "%s%02d.png", filename, a);
     emulator.emuWritePNG(buffer);