143 cocoaSetupAutoreleasePool(); |
126 cocoaSetupAutoreleasePool(); |
144 /* This is passed if we are launched by double-clicking */ |
127 /* This is passed if we are launched by double-clicking */ |
145 if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { |
128 if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { |
146 argv[1] = NULL; |
129 argv[1] = NULL; |
147 argc = 1; |
130 argc = 1; |
148 cocoaSetWorkingDirectory(); |
131 } |
149 } |
|
150 #endif |
|
151 |
|
152 // change the working directory to enable doubleclicking in UIs |
|
153 #if defined(__BEOS__) || defined(__linux__) |
|
154 ChangeWorkingDirectory(argv[0]); |
|
155 #endif |
132 #endif |
156 |
133 |
157 _random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
134 _random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
158 SeedMT(_random_seeds[0][1]); |
135 SeedMT(_random_seeds[0][1]); |
159 |
136 |
164 #ifdef WITH_COCOA |
141 #ifdef WITH_COCOA |
165 cocoaReleaseAutoreleasePool(); |
142 cocoaReleaseAutoreleasePool(); |
166 #endif |
143 #endif |
167 |
144 |
168 return ret; |
145 return ret; |
169 } |
|
170 |
|
171 void DeterminePaths() |
|
172 { |
|
173 char *s; |
|
174 |
|
175 _paths.game_data_dir = MallocT<char>(MAX_PATH); |
|
176 ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
|
177 #if defined SECOND_DATA_DIR |
|
178 _paths.second_data_dir = MallocT<char>(MAX_PATH); |
|
179 ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
|
180 #endif |
|
181 |
|
182 #if defined(USE_HOMEDIR) |
|
183 { |
|
184 const char *homedir = getenv("HOME"); |
|
185 |
|
186 if (homedir == NULL) { |
|
187 const struct passwd *pw = getpwuid(getuid()); |
|
188 if (pw != NULL) homedir = pw->pw_dir; |
|
189 } |
|
190 |
|
191 _paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
|
192 } |
|
193 |
|
194 #else /* not defined(USE_HOMEDIR) */ |
|
195 |
|
196 _paths.personal_dir = MallocT<char>(MAX_PATH); |
|
197 ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); |
|
198 |
|
199 // check if absolute or relative path |
|
200 s = strchr(_paths.personal_dir, '/'); |
|
201 |
|
202 // add absolute path |
|
203 if (s == NULL || _paths.personal_dir != s) { |
|
204 getcwd(_paths.personal_dir, MAX_PATH); |
|
205 s = strchr(_paths.personal_dir, 0); |
|
206 *s++ = '/'; |
|
207 ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
|
208 } |
|
209 |
|
210 #endif /* defined(USE_HOMEDIR) */ |
|
211 |
|
212 s = strchr(_paths.personal_dir, 0); |
|
213 |
|
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 } |
146 } |
245 |
147 |
246 bool InsertTextBufferClipboard(Textbuf *tb) |
148 bool InsertTextBufferClipboard(Textbuf *tb) |
247 { |
149 { |
248 return false; |
150 return false; |