1 /*
2
3 Copyright (C) 2017 and beyond by Jeremiah Morris
4 and the "Aleph One" developers.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 This license is contained in the file "COPYING",
17 which is included with this source code; it is available online at
18 http://www.gnu.org/licenses/gpl.html
19
20 */
21
22 #include "cstypes.h"
23 #include "cspaths.h"
24 #include "alephversion.h"
25 #ifdef HAVE_CONFIG_H
26 #include "confpaths.h"
27 #endif
28
29 #if defined(__APPLE__) && defined(__MACH__)
30
get_path_list_separator()31 char get_path_list_separator()
32 {
33 return ':';
34 }
35
36 // other functions handled in cspaths.mm
37
38 #elif defined(__WIN32__)
39
40 #include <windows.h>
41 #include <shlobj.h>
42
get_path_list_separator()43 char get_path_list_separator()
44 {
45 return ';';
46 }
47
_get_local_data_path()48 static std::string _get_local_data_path()
49 {
50 static std::string local_dir = "";
51 if (local_dir.empty())
52 {
53 char file_name[MAX_PATH];
54 SHGetFolderPath(NULL,
55 CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
56 NULL,
57 0,
58 file_name);
59 local_dir = std::string(file_name) + "\\AlephOne";
60 }
61 return local_dir;
62 }
63
_get_default_data_path()64 static std::string _get_default_data_path()
65 {
66 static std::string default_dir = "";
67 if (default_dir.empty())
68 {
69 char file_name[MAX_PATH];
70 GetModuleFileName(NULL, file_name, sizeof(file_name));
71 char *sep = strrchr(file_name, '\\');
72 *sep = '\0';
73 default_dir = file_name;
74 }
75 return default_dir;
76 }
77
_get_prefs_path()78 static std::string _get_prefs_path()
79 {
80 static std::string prefs_dir = "";
81 if (prefs_dir.empty())
82 {
83 char file_name[MAX_PATH];
84 SHGetFolderPath(NULL,
85 CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE,
86 NULL,
87 0,
88 file_name);
89 prefs_dir = std::string(file_name) + "\\AlephOne";
90 }
91 return prefs_dir;
92 }
93
_get_login_name()94 static std::string _get_login_name()
95 {
96 static std::string login_name = "";
97 if (login_name.empty())
98 {
99 char login[17];
100 DWORD len = 17;
101
102 bool hasName = (GetUserName((LPSTR) login, &len) == TRUE);
103 if (!hasName || strpbrk(login, "\\/:*?\"<>|") != NULL)
104 strcpy(login, "Bob User");
105 login_name = login;
106 }
107 return login_name;
108 }
109
get_data_path(CSPathType type)110 std::string get_data_path(CSPathType type)
111 {
112 std::string path = "";
113
114 switch (type) {
115 case kPathLocalData:
116 case kPathLogs:
117 path = _get_local_data_path();
118 break;
119 case kPathDefaultData:
120 path = _get_default_data_path();
121 break;
122 case kPathBundleData:
123 // not applicable
124 break;
125 case kPathPreferences:
126 path = _get_prefs_path();
127 break;
128 case kPathLegacyData:
129 case kPathLegacyPreferences:
130 path = _get_default_data_path() + "\\Prefs\\" + _get_login_name();
131 break;
132 case kPathScreenshots:
133 path = _get_local_data_path() + "\\Screenshots";
134 break;
135 case kPathSavedGames:
136 path = _get_local_data_path() + "\\Saved Games";
137 break;
138 case kPathQuickSaves:
139 path = _get_local_data_path() + "\\Quick Saves";
140 break;
141 case kPathImageCache:
142 path = _get_local_data_path() + "\\Image Cache";
143 break;
144 case kPathRecordings:
145 path = _get_local_data_path() + "\\Recordings";
146 break;
147 }
148 return path;
149 }
150
get_application_name()151 std::string get_application_name()
152 {
153 return std::string(A1_DISPLAY_NAME);
154 }
155
get_application_identifier()156 std::string get_application_identifier()
157 {
158 return std::string("org.bungie.source.AlephOne");
159 }
160
161 #else
162
163 // Linux and compatible
164
get_path_list_separator()165 char get_path_list_separator()
166 {
167 return ':';
168 }
169
_get_local_data_path()170 static std::string _get_local_data_path()
171 {
172 static std::string local_dir = "";
173 if (local_dir.empty())
174 {
175 const char *home = getenv("HOME");
176 if (home)
177 local_dir = std::string(home) + "/.alephone";
178 }
179 return local_dir;
180 }
181
get_data_path(CSPathType type)182 std::string get_data_path(CSPathType type)
183 {
184 std::string path = "";
185
186 switch (type) {
187 case kPathLocalData:
188 case kPathLogs:
189 case kPathPreferences:
190 path = _get_local_data_path();
191 break;
192 case kPathDefaultData:
193 #ifdef PKGDATADIR
194 path = PKGDATADIR;
195 #endif
196 break;
197 case kPathLegacyData:
198 case kPathBundleData:
199 case kPathLegacyPreferences:
200 // not applicable
201 break;
202 case kPathScreenshots:
203 path = _get_local_data_path() + "/Screenshots";
204 break;
205 case kPathSavedGames:
206 path = _get_local_data_path() + "/Saved Games";
207 break;
208 case kPathQuickSaves:
209 path = _get_local_data_path() + "/Quick Saves";
210 break;
211 case kPathImageCache:
212 path = _get_local_data_path() + "/Image Cache";
213 break;
214 case kPathRecordings:
215 path = _get_local_data_path() + "/Recordings";
216 break;
217 }
218 return path;
219 }
220
get_application_name()221 std::string get_application_name()
222 {
223 return std::string(A1_DISPLAY_NAME);
224 }
225
get_application_identifier()226 std::string get_application_identifier()
227 {
228 return std::string("org.bungie.source.AlephOne");
229 }
230
231
232 #endif
233
234