176 _random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
176 _random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
177 |
177 |
178 return ttd_main(argc, argv); |
178 return ttd_main(argc, argv); |
179 } |
179 } |
180 |
180 |
181 void DeterminePaths() |
181 void DetermineBasePaths() |
182 { |
182 { |
183 char *s; |
183 _paths.game_data_dir = MallocT<char>(MAX_PATH); |
184 |
|
185 _paths.game_data_dir = (char *)malloc(MAX_PATH); |
|
186 ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
184 ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
187 #if defined SECOND_DATA_DIR |
185 #if defined(SECOND_DATA_DIR) |
188 _paths.second_data_dir = malloc(MAX_PATH); |
186 _paths.second_data_dir = MallocT<char>(MAX_PATH); |
189 ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
187 ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
190 #endif |
188 #endif |
191 |
189 |
192 #if defined(USE_HOMEDIR) |
190 #if defined(USE_HOMEDIR) |
193 { |
191 const char *homedir = getenv("HOME"); |
194 const char *homedir = getenv("HOME"); |
192 |
195 |
193 if (homedir == NULL) { |
196 if (homedir == NULL) { |
194 const struct passwd *pw = getpwuid(getuid()); |
197 const struct passwd *pw = getpwuid(getuid()); |
195 if (pw != NULL) homedir = pw->pw_dir; |
198 if (pw != NULL) homedir = pw->pw_dir; |
196 } |
199 } |
197 |
200 |
198 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
201 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
|
202 } |
|
203 |
|
204 #else /* not defined(USE_HOMEDIR) */ |
199 #else /* not defined(USE_HOMEDIR) */ |
205 |
200 _paths.personal_dir = MallocT<char>(MAX_PATH); |
206 _paths.personal_dir = (char *)malloc(MAX_PATH); |
|
207 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
201 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
208 |
202 |
209 // check if absolute or relative path |
203 /* check if absolute or relative path */ |
210 s = strchr(_paths.personal_dir, PATHSEPCHAR); |
204 const char *s = strchr(_paths.personal_dir, PATHSEPCHAR); |
211 |
205 |
212 // add absolute path |
206 /* add absolute path */ |
213 if (s == NULL || _paths.personal_dir != s) { |
207 if (s == NULL || _paths.personal_dir != s) { |
214 getcwd(_paths.personal_dir, MAX_PATH); |
208 getcwd(_paths.personal_dir, MAX_PATH); |
215 s = strchr(_paths.personal_dir, 0); |
209 AppendPathSeparator(_paths.personal_dir, MAX_PATH); |
216 *s++ = PATHSEPCHAR; |
210 ttd_strlcat(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
217 ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
211 } |
218 } |
|
219 |
|
220 #endif /* defined(USE_HOMEDIR) */ |
212 #endif /* defined(USE_HOMEDIR) */ |
221 |
213 |
222 s = strchr(_paths.personal_dir, 0); |
214 AppendPathSeparator(_paths.personal_dir, MAX_PATH); |
223 |
215 AppendPathSeparator(_paths.game_data_dir, MAX_PATH); |
224 // append a / ? |
|
225 if (s[-1] != PATHSEPCHAR) strcpy(s, PATHSEP); |
|
226 |
|
227 _paths.save_dir = str_fmt("%ssave", _paths.personal_dir); |
|
228 _paths.autosave_dir = str_fmt("%s" PATHSEP "autosave", _paths.save_dir); |
|
229 _paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir); |
|
230 _paths.heightmap_dir = str_fmt("%sscenario" PATHSEP "heightmap", _paths.personal_dir); |
|
231 _paths.gm_dir = str_fmt("%sgm" PATHSEP, _paths.game_data_dir); |
|
232 _paths.data_dir = str_fmt("%sdata" PATHSEP, _paths.game_data_dir); |
|
233 |
|
234 if (_config_file == NULL) |
|
235 _config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir); |
|
236 |
|
237 _highscore_file = str_fmt("%shs.dat", _paths.personal_dir); |
|
238 _log_file = str_fmt("%sopenttd.log", _paths.personal_dir); |
|
239 |
|
240 #if defined CUSTOM_LANG_DIR |
|
241 // sets the search path for lng files to the custom one |
|
242 _paths.lang_dir = malloc( MAX_PATH ); |
|
243 ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
|
244 #else |
|
245 _paths.lang_dir = str_fmt("%slang" PATHSEP, _paths.game_data_dir); |
|
246 #endif |
|
247 |
|
248 // create necessary folders |
|
249 #ifndef __INNOTEK_LIBC__ |
|
250 mkdir(_paths.personal_dir); |
|
251 mkdir(_paths.save_dir); |
|
252 mkdir(_paths.autosave_dir); |
|
253 mkdir(_paths.scenario_dir); |
|
254 mkdir(_paths.heightmap_dir); |
|
255 #else |
|
256 mkdir(_paths.personal_dir, 0755); |
|
257 mkdir(_paths.save_dir, 0755); |
|
258 mkdir(_paths.autosave_dir, 0755); |
|
259 mkdir(_paths.scenario_dir, 0755); |
|
260 mkdir(_paths.heightmap_dir, 0755); |
|
261 #endif |
|
262 } |
216 } |
263 |
217 |
264 /** |
218 /** |
265 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
219 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
266 * and append this up to the maximum length (either absolute or screenlength). If maxlength |
220 * and append this up to the maximum length (either absolute or screenlength). If maxlength |