Rev 133 | Rev 145 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 133 | Rev 136 | ||
|---|---|---|---|
| Line 19... | Line 19... | ||
| 19 | 19 | ||
| 20 | void *inifile; |
20 | void *inifile; |
| 21 | smiley_t *smiley; |
21 | smiley_t *smiley; |
| 22 | char *file_buffer; |
22 | char *file_buffer; |
| 23 | wchar_t temp_string[MAX_PATH]; |
23 | wchar_t temp_string[MAX_PATH]; |
| 24 |
|
24 | // wchar_t smiley_pathname[MAX_PATH]; |
| 25 | wchar_t *smiley_name; |
25 | wchar_t *smiley_name; |
| 26 | int language_index; |
26 | int language_index; |
| 27 | int program_index; |
27 | int program_index; |
| 28 | int smiley_index; |
28 | int smiley_index; |
| 29 | int file_length; |
29 | int file_length; |
| Line 161... | Line 161... | ||
| 161 | 161 | ||
| 162 | // else we found no match, we have to read the file ourselves |
162 | // else we found no match, we have to read the file ourselves |
| 163 | else |
163 | else |
| 164 | { |
164 | { |
| 165 | // build the smiley picture's file pathname and read that smiley's data as a hex string |
165 | // build the smiley picture's file pathname and read that smiley's data as a hex string |
| 166 | swprintf_s ( |
166 | swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), L"%s/data/smilies/%s", app_path, smiley->filename); |
| 167 | _wfopen_s (&fp, |
167 | _wfopen_s (&fp, temp_string, L"rb"); |
| 168 | if (fp == NULL) |
168 | if (fp == NULL) |
| 169 | continue; // if this smiley picture file can't be opened, ignore this smiley |
169 | continue; // if this smiley picture file can't be opened, ignore this smiley |
| 170 | 170 | ||
| 171 | // get the file length |
171 | // get the file length |
| 172 | fseek (fp, 0, SEEK_END); |
172 | fseek (fp, 0, SEEK_END); |
| Line 195... | Line 195... | ||
| 195 | INIFile_FreeINIFile (inifile); |
195 | INIFile_FreeINIFile (inifile); |
| 196 | return; // finished loading config |
196 | return; // finished loading config |
| 197 | } |
197 | } |
| 198 | 198 | ||
| 199 | 199 | ||
| 200 | void Config_LoadEngines () |
200 | void Config_LoadEngines (void) |
| 201 | { |
201 | { |
| 202 | // this function loads the engine-specific parameters. The best place to call it is at the beginning |
202 | // this function loads the engine-specific parameters. The best place to call it is at the beginning |
| 203 | // of a game versus the computer, just before the engine executable process is started. |
203 | // of a game versus the computer, just before the engine executable process is started. |
| 204 | 204 | ||
| 205 | wchar_t temp_string[MAX_PATH]; |
205 | wchar_t temp_string[MAX_PATH]; |
| Line 210... | Line 210... | ||
| 210 | wchar_t *ptr; |
210 | wchar_t *ptr; |
| 211 | 211 | ||
| 212 | options.engine.programs = NULL; |
212 | options.engine.programs = NULL; |
| 213 | options.engine.program_count = 0; |
213 | options.engine.program_count = 0; |
| 214 | 214 | ||
| 215 | swprintf_s (temp_string, |
215 | swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), L"%s\\engines\\*.*", app_path); // build the search pattern string out of the path |
| 216 | hFind = FindFirstFile (temp_string, &wfd); // initiate search from that point |
216 | hFind = FindFirstFile (temp_string, &wfd); // initiate search from that point |
| 217 | if (hFind |
217 | if (hFind == INVALID_HANDLE_VALUE) |
| - | 218 | return; // no engines available (FIXME: error message ?) |
|
| - | 219 | ||
| - | 220 | // start examining search results... |
|
| - | 221 | do |
|
| 218 | { |
222 | { |
| 219 | // start examining search results... |
- | |
| 220 | do |
- | |
| 221 | { |
- | |
| 222 |
|
223 | if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (wfd.cFileName[0] == L'.')) |
| 223 |
|
224 | continue; // skip everything that is NOT a directory, and every directories that begin with a dot |
| 224 | 225 | ||
| 225 |
|
226 | // given the selected engine program, load and interpret the right engine config file |
| 226 |
|
227 | swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, wfd.cFileName); |
| 227 |
|
228 | engine_inifile = INIFile_LoadINIFile (filename); // see if an ini file exists for this engine |
| - | 229 | if (engine_inifile == NULL) |
|
| - | 230 | continue; // engine .ini file not found, skip this one |
|
| 228 | 231 | ||
| 229 |
|
232 | // reallocate space for one more engine program, and clean up the allocated slot |
| 230 |
|
233 | options.engine.programs = (engineprogram_t *) SAFE_realloc (options.engine.programs, options.engine.program_count, options.engine.program_count + 1, sizeof (engineprogram_t), true); |
| 231 | swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, engineprogram->folder); |
- | |
| 232 |
|
234 | engineprogram = &options.engine.programs[options.engine.program_count]; // quick access to engine |
| 233 | if (engine_inifile == NULL) |
- | |
| 234 | continue; // engine .ini file not found, skip this one |
- | |
| 235 | 235 | ||
| 236 |
|
236 | // basic program information |
| - | 237 | wcscpy_s (engineprogram->folder, sizeof (engineprogram->folder), wfd.cFileName); // save engine program's folder name |
|
| 237 |
|
238 | READ_WIDESTRING (engineprogram->name, engine_inifile, L"program", L"name", L"Crafty v24.0"); |
| 238 |
|
239 | READ_WIDESTRING (engineprogram->cmdline, engine_inifile, L"program", L"executable", L"crafty.exe"); |
| 239 | 240 | ||
| 240 |
|
241 | // reply string patterns |
| 241 |
|
242 | READ_WIDESTRING (engineprogram->replystring_move, engine_inifile, L"reply strings", L"move", L"): "); |
| 242 | 243 | ||
| 243 |
|
244 | // engine commands |
| 244 |
|
245 | READ_WIDESTRING (engineprogram->command_new, engine_inifile, L"commands", L"new game", L"new"); |
| 245 |
|
246 | for (ptr = engineprogram->command_new; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 246 |
|
247 | READ_WIDESTRING (engineprogram->command_setboard, engine_inifile, L"commands", L"setup table from FEN", L"setboard %s"); |
| 247 |
|
248 | for (ptr = engineprogram->command_setboard; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 248 |
|
249 | READ_WIDESTRING (engineprogram->command_sd, engine_inifile, L"commands", L"search depth set", L"sd %d"); |
| 249 |
|
250 | for (ptr = engineprogram->command_sd; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 250 |
|
251 | READ_WIDESTRING (engineprogram->command_go, engine_inifile, L"commands", L"play", L"go"); |
| 251 |
|
252 | for (ptr = engineprogram->command_go; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 252 |
|
253 | READ_WIDESTRING (engineprogram->command_move, engine_inifile, L"commands", L"move", L"%s"); |
| 253 |
|
254 | for (ptr = engineprogram->command_move; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 254 |
|
255 | READ_WIDESTRING (engineprogram->command_force, engine_inifile, L"commands", L"force move", L"force %s"); |
| 255 |
|
256 | for (ptr = engineprogram->command_force; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 256 |
|
257 | READ_WIDESTRING (engineprogram->command_quit, engine_inifile, L"commands", L"quit", L"quit"); |
| 257 |
|
258 | for (ptr = engineprogram->command_quit; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n'; |
| 258 | 259 | ||
| 259 |
|
260 | INIFile_FreeINIFile (engine_inifile); // close the engine config file |
| 260 | 261 | ||
| 261 |
|
262 | options.engine.program_count++; // we've identified one engine more |
| 262 |
|
263 | } while (FindNextFile (hFind, &wfd)); // ...and don't stop as long as there are directory entries to go |
| 263 | FindClose (hFind); // close the search handle |
- | |
| 264 | } |
- | |
| 265 | 264 | ||
| - | 265 | FindClose (hFind); // close the search handle |
|
| 266 | return; // engine parameters loaded successfully |
266 | return; // engine parameters loaded successfully |
| 267 | } |
267 | } |
| 268 | 268 | ||
| 269 | 269 | ||
| 270 | void Config_Save (void) |
270 | void Config_Save (void) |