148 if (homedir == NULL) { |
148 if (homedir == NULL) { |
149 const struct passwd *pw = getpwuid(getuid()); |
149 const struct passwd *pw = getpwuid(getuid()); |
150 if (pw != NULL) homedir = pw->pw_dir; |
150 if (pw != NULL) homedir = pw->pw_dir; |
151 } |
151 } |
152 |
152 |
153 _path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
153 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
154 } |
154 } |
155 |
155 |
156 #else /* not defined(USE_HOMEDIR) */ |
156 #else /* not defined(USE_HOMEDIR) */ |
157 |
157 |
158 _path.personal_dir = malloc(MAX_PATH); |
158 _paths.personal_dir = malloc(MAX_PATH); |
159 ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH); |
159 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
160 |
160 |
161 // check if absolute or relative path |
161 // check if absolute or relative path |
162 s = strchr(_path.personal_dir, '\\'); |
162 s = strchr(_paths.personal_dir, '\\'); |
163 |
163 |
164 // add absolute path |
164 // add absolute path |
165 if (s == NULL || _path.personal_dir != s) { |
165 if (s == NULL || _paths.personal_dir != s) { |
166 getcwd(_path.personal_dir, MAX_PATH); |
166 getcwd(_paths.personal_dir, MAX_PATH); |
167 s = strchr(_path.personal_dir, 0); |
167 s = strchr(_paths.personal_dir, 0); |
168 *s++ = '\\'; |
168 *s++ = '\\'; |
169 ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
169 ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
170 } |
170 } |
171 |
171 |
172 #endif /* defined(USE_HOMEDIR) */ |
172 #endif /* defined(USE_HOMEDIR) */ |
173 |
173 |
174 s = strchr(_path.personal_dir, 0); |
174 s = strchr(_paths.personal_dir, 0); |
175 |
175 |
176 // append a / ? |
176 // append a / ? |
177 if (s[-1] != '\\') strcpy(s, "\\"); |
177 if (s[-1] != '\\') strcpy(s, "\\"); |
178 |
178 |
179 _path.save_dir = str_fmt("%ssave", _path.personal_dir); |
179 _paths.save_dir = str_fmt("%ssave", _paths.personal_dir); |
180 _path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir); |
180 _paths.autosave_dir = str_fmt("%s\\autosave", _paths.save_dir); |
181 _path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
181 _paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir); |
182 _path.heightmap_dir = str_fmt("%sscenario\\heightmap", _path.personal_dir); |
182 _paths.heightmap_dir = str_fmt("%sscenario\\heightmap", _paths.personal_dir); |
183 _path.gm_dir = str_fmt("%sgm\\", _path.game_data_dir); |
183 _paths.gm_dir = str_fmt("%sgm\\", _paths.game_data_dir); |
184 _path.data_dir = str_fmt("%sdata\\", _path.game_data_dir); |
184 _paths.data_dir = str_fmt("%sdata\\", _paths.game_data_dir); |
185 |
185 |
186 if (_config_file == NULL) |
186 if (_config_file == NULL) |
187 _config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); |
187 _config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir); |
188 |
188 |
189 _highscore_file = str_fmt("%shs.dat", _path.personal_dir); |
189 _highscore_file = str_fmt("%shs.dat", _paths.personal_dir); |
190 _log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
190 _log_file = str_fmt("%sopenttd.log", _paths.personal_dir); |
191 |
191 |
192 #if defined CUSTOM_LANG_DIR |
192 #if defined CUSTOM_LANG_DIR |
193 // sets the search path for lng files to the custom one |
193 // sets the search path for lng files to the custom one |
194 _path.lang_dir = malloc( MAX_PATH ); |
194 _paths.lang_dir = malloc( MAX_PATH ); |
195 ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
195 ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
196 #else |
196 #else |
197 _path.lang_dir = str_fmt("%slang\\", _path.game_data_dir); |
197 _paths.lang_dir = str_fmt("%slang\\", _paths.game_data_dir); |
198 #endif |
198 #endif |
199 |
199 |
200 // create necessary folders |
200 // create necessary folders |
201 mkdir(_path.personal_dir); |
201 mkdir(_paths.personal_dir); |
202 mkdir(_path.save_dir); |
202 mkdir(_paths.save_dir); |
203 mkdir(_path.autosave_dir); |
203 mkdir(_paths.autosave_dir); |
204 mkdir(_path.scenario_dir); |
204 mkdir(_paths.scenario_dir); |
205 mkdir(_path.heightmap_dir); |
205 mkdir(_paths.heightmap_dir); |
206 } |
206 } |
207 |
207 |
208 /** |
208 /** |
209 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
209 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
210 * and append this up to the maximum length (either absolute or screenlength). If maxlength |
210 * and append this up to the maximum length (either absolute or screenlength). If maxlength |