166 #endif |
167 #endif |
167 |
168 |
168 return ret; |
169 return ret; |
169 } |
170 } |
170 |
171 |
171 void DeterminePaths() |
172 void DetermineBasePaths() |
172 { |
173 { |
173 char *s; |
|
174 |
|
175 _paths.game_data_dir = MallocT<char>(MAX_PATH); |
174 _paths.game_data_dir = MallocT<char>(MAX_PATH); |
176 ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
175 ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
177 #if defined SECOND_DATA_DIR |
176 #if defined(SECOND_DATA_DIR) |
178 _paths.second_data_dir = MallocT<char>(MAX_PATH); |
177 _paths.second_data_dir = MallocT<char>(MAX_PATH); |
179 ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
178 ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
180 #endif |
179 #endif |
181 |
180 |
182 #if defined(USE_HOMEDIR) |
181 #if defined(USE_HOMEDIR) |
183 { |
182 const char *homedir = getenv("HOME"); |
184 const char *homedir = getenv("HOME"); |
183 |
185 |
184 if (homedir == NULL) { |
186 if (homedir == NULL) { |
185 const struct passwd *pw = getpwuid(getuid()); |
187 const struct passwd *pw = getpwuid(getuid()); |
186 if (pw != NULL) homedir = pw->pw_dir; |
188 if (pw != NULL) homedir = pw->pw_dir; |
187 } |
189 } |
188 |
190 |
189 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
191 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
|
192 } |
|
193 |
|
194 #else /* not defined(USE_HOMEDIR) */ |
190 #else /* not defined(USE_HOMEDIR) */ |
195 |
|
196 _paths.personal_dir = MallocT<char>(MAX_PATH); |
191 _paths.personal_dir = MallocT<char>(MAX_PATH); |
197 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
192 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
198 |
193 |
199 // check if absolute or relative path |
194 /* check if absolute or relative path */ |
200 s = strchr(_paths.personal_dir, '/'); |
195 const char *s = strchr(_paths.personal_dir, PATHSEPCHAR); |
201 |
196 |
202 // add absolute path |
197 /* add absolute path */ |
203 if (s == NULL || _paths.personal_dir != s) { |
198 if (s == NULL || _paths.personal_dir != s) { |
204 getcwd(_paths.personal_dir, MAX_PATH); |
199 getcwd(_paths.personal_dir, MAX_PATH); |
205 s = strchr(_paths.personal_dir, 0); |
200 AppendPathSeparator(_paths.personal_dir, MAX_PATH); |
206 *s++ = '/'; |
201 ttd_strlcat(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
207 ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
202 } |
208 } |
|
209 |
|
210 #endif /* defined(USE_HOMEDIR) */ |
203 #endif /* defined(USE_HOMEDIR) */ |
211 |
204 |
212 s = strchr(_paths.personal_dir, 0); |
205 AppendPathSeparator(_paths.personal_dir, MAX_PATH); |
213 |
206 AppendPathSeparator(_paths.game_data_dir, MAX_PATH); |
214 // append a / ? |
|
215 if (s[-1] != '/') strcpy(s, "/"); |
|
216 |
|
217 _paths.save_dir = str_fmt("%ssave", _paths.personal_dir); |
|
218 _paths.autosave_dir = str_fmt("%s/autosave", _paths.save_dir); |
|
219 _paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir); |
|
220 _paths.heightmap_dir = str_fmt("%sscenario/heightmap", _paths.personal_dir); |
|
221 _paths.gm_dir = str_fmt("%sgm/", _paths.game_data_dir); |
|
222 _paths.data_dir = str_fmt("%sdata/", _paths.game_data_dir); |
|
223 |
|
224 if (_config_file == NULL) |
|
225 _config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir); |
|
226 |
|
227 _highscore_file = str_fmt("%shs.dat", _paths.personal_dir); |
|
228 _log_file = str_fmt("%sopenttd.log", _paths.personal_dir); |
|
229 |
|
230 #if defined CUSTOM_LANG_DIR |
|
231 // sets the search path for lng files to the custom one |
|
232 _paths.lang_dir = MallocT<char>(MAX_PATH); |
|
233 ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
|
234 #else |
|
235 _paths.lang_dir = str_fmt("%slang/", _paths.game_data_dir); |
|
236 #endif |
|
237 |
|
238 // create necessary folders |
|
239 mkdir(_paths.personal_dir, 0755); |
|
240 mkdir(_paths.save_dir, 0755); |
|
241 mkdir(_paths.autosave_dir, 0755); |
|
242 mkdir(_paths.scenario_dir, 0755); |
|
243 mkdir(_paths.heightmap_dir, 0755); |
|
244 } |
207 } |
245 |
208 |
246 bool InsertTextBufferClipboard(Textbuf *tb) |
209 bool InsertTextBufferClipboard(Textbuf *tb) |
247 { |
210 { |
248 return false; |
211 return false; |