Rev 185 | Rev 193 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 185 | Rev 192 | ||
|---|---|---|---|
| Line 21... | Line 21... | ||
| 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 | // wchar_t smiley_pathname[MAX_PATH]; |
24 | // wchar_t smiley_pathname[MAX_PATH]; |
| 25 | wchar_t *smiley_name; |
25 | wchar_t *smiley_name; |
| - | 26 | size_t smiley_namelen; |
|
| 26 | int candidate_index; |
27 | int candidate_index; |
| 27 | int language_index; |
28 | int language_index; |
| 28 | int program_index; |
29 | int program_index; |
| 29 | int smiley_index; |
30 | int smiley_index; |
| 30 | int file_length; |
31 | int file_length; |
| Line 101... | Line 102... | ||
| 101 | want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0); |
102 | want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0); |
| 102 | READ_WIDESTRING (custombackground_pathname, inifile, L"theme", L"custom background picture", L""); |
103 | READ_WIDESTRING (custombackground_pathname, inifile, L"theme", L"custom background picture", L""); |
| 103 | 104 | ||
| 104 | // [engine] |
105 | // [engine] |
| 105 | Config_LoadEngines (); // discover all engine parameters from the engines folder |
106 | Config_LoadEngines (); // discover all engine parameters from the engines folder |
| - | 107 | READ_WIDESTRING (temp_string, inifile, L"engine", L"program", L"Stockfish"); |
|
| 106 | for (program_index = 0; program_index < options.engine.program_count; program_index++) |
108 | for (program_index = 0; program_index < options.engine.program_count; program_index++) |
| 107 | { |
- | |
| 108 | READ_WIDESTRING (temp_string, inifile, L"engine", L"program", L"Stockfish"); |
- | |
| 109 | if (_wcsicmp (temp_string, options.engine.programs[program_index].folder) == 0) |
109 | if (_wcsicmp (temp_string, options.engine.programs[program_index].folder) == 0) |
| - | 110 | break; // identify the preferred engine by its folder name, break as soon as we find it |
|
| - | 111 | if (program_index == options.engine.program_count) |
|
| - | 112 | program_index = 0; // if the preferred engine isn't available, fallback on the first one |
|
| - | 113 | if (kernel32_version < options.engine.programs[program_index].kernel32_minver) |
|
| - | 114 | { |
|
| - | 115 | // if we can't select this engine because we're running an outdated Windows version, fallback on the first suitable one |
|
| - | 116 | for (program_index = 0; program_index < options.engine.program_count; program_index++) |
|
| - | 117 | if (kernel32_version >= options.engine.programs[program_index].kernel32_minver) |
|
| 110 | break; // identify |
118 | break; // identify a suitable engine, break as soon as we find it |
| - | 119 | if (program_index == options.engine.program_count) |
|
| - | 120 | program_index = 0; // if NO engine is available, fallback on the first one |
|
| 111 | } |
121 | } |
| 112 | options.engine.selected_program = |
122 | options.engine.selected_program = program_index; |
| 113 | options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 10); |
123 | options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 10); |
| 114 | options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 20); |
124 | options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 20); |
| 115 | options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 5); |
125 | options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 5); |
| 116 | options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", -1); |
126 | options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", -1); |
| 117 | options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0); |
127 | options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0); |
| Line 185... | Line 195... | ||
| 185 | candidate_index = 0; |
195 | candidate_index = 0; |
| 186 | while ((smiley_name = INIFile_GetEntryName (inifile, L"smilies", candidate_index)) != NULL) |
196 | while ((smiley_name = INIFile_GetEntryName (inifile, L"smilies", candidate_index)) != NULL) |
| 187 | { |
197 | { |
| 188 | candidate_index++; // advance in the smiley entries list |
198 | candidate_index++; // advance in the smiley entries list |
| 189 | 199 | ||
| 190 | if ((smiley_name == NULL) || (smiley_name[0] == 0)) |
200 | if ((smiley_name == NULL) || (smiley_name[0] == 0) || ((smiley_name[0] == L'"') && (smiley_name[1] == L'"'))) |
| 191 | continue; // discard bogus smilies |
201 | continue; // discard bogus smilies |
| 192 | 202 | ||
| 193 | // for each smiley we can read, reallocate smilies array to hold one smiley more |
203 | // for each smiley we can read, reallocate smilies array to hold one smiley more |
| 194 | smilies = (smiley_t *) SAFE_realloc (smilies, smiley_count, smiley_count + 1, sizeof (smiley_t), false); |
204 | smilies = (smiley_t *) SAFE_realloc (smilies, smiley_count, smiley_count + 1, sizeof (smiley_t), false); |
| 195 | 205 | ||
| 196 | smiley = &smilies[smiley_count]; // quick access to smiley |
206 | smiley = &smilies[smiley_count]; // quick access to smiley |
| 197 | 207 | ||
| 198 | // read the smiley name |
208 | // read the smiley's corresponding picture file *BEFORE* we clean the smiley name from its possible quotes (thus altering the key name) |
| 199 | swprintf_s (smiley->name, WCHAR_SIZEOF (smiley->name), L" %s ", smiley_name); |
- | |
| 200 | - | ||
| 201 | // now read the smiley's corresponding picture file |
- | |
| 202 | READ_WIDESTRING (smiley->filename, inifile, L"smilies", smiley_name, L"smile.txt"); |
209 | READ_WIDESTRING (smiley->filename, inifile, L"smilies", smiley_name, L"smile.txt"); |
| - | 210 | ||
| - | 211 | // now clean the smiley name and make sure it is enclosed between a leading and trailing space |
|
| - | 212 | wcscpy_s (smiley->name, WCHAR_SIZEOF (smiley->name), smiley_name); // save cleaned up smiley name |
|
| - | 213 | smiley_namelen = wcslen (smiley->name); |
|
| - | 214 | if ((smiley->name[0] == L'"') && (smiley->name[smiley_namelen - 1] == L'"')) |
|
| - | 215 | { |
|
| - | 216 | smiley->name[0] = L' '; // if it's enclosed by quotes, convert these to spaces |
|
| - | 217 | smiley->name[smiley_namelen - 1] = L' '; |
|
| - | 218 | } |
|
| - | 219 | if (smiley->name[0] != L' ') |
|
| - | 220 | { |
|
| - | 221 | memmove (&smiley->name[1], smiley->name, (smiley_namelen + 1) * sizeof (wchar_t)); // if it doesn't begin with a space, insert one |
|
| - | 222 | smiley->name[0] = L' '; |
|
| - | 223 | smiley_namelen++; |
|
| - | 224 | } |
|
| - | 225 | if (smiley->name[smiley_namelen - 1] != L' ') |
|
| - | 226 | { |
|
| - | 227 | smiley->name[smiley_namelen] = L' '; // if it doesn't end with a space, append one |
|
| - | 228 | smiley->name[smiley_namelen + 1] = 0; |
|
| - | 229 | smiley_namelen++; |
|
| - | 230 | } |
|
| 203 | 231 | ||
| 204 | // is this filename the same as another smiley we know already ? |
232 | // is this filename the same as another smiley we know already ? |
| 205 | for (smiley_index = 0; smiley_index < smiley_count; smiley_index++) |
233 | for (smiley_index = 0; smiley_index < smiley_count; smiley_index++) |
| 206 | if (wcscmp (smilies[smiley_index].filename, smiley->filename) == 0) |
234 | if (wcscmp (smilies[smiley_index].filename, smiley->filename) == 0) |
| 207 | break; // break as soon as we find a match |
235 | break; // break as soon as we find a match |
| Line 257... | Line 285... | ||
| 257 | // this function loads the engine-specific parameters. The best place to call it is at the beginning |
285 | // this function loads the engine-specific parameters. The best place to call it is at the beginning |
| 258 | // of a game versus the computer, just before the engine executable process is started. |
286 | // of a game versus the computer, just before the engine executable process is started. |
| 259 | 287 | ||
| 260 | wchar_t temp_string[MAX_PATH]; |
288 | wchar_t temp_string[MAX_PATH]; |
| 261 | engineprogram_t *engineprogram; |
289 | engineprogram_t *engineprogram; |
| - | 290 | int version_numbers[4]; |
|
| 262 | void *engine_inifile; |
291 | void *engine_inifile; |
| 263 | WIN32_FIND_DATA wfd; |
292 | WIN32_FIND_DATA wfd; |
| 264 | HANDLE hFind; |
293 | HANDLE hFind; |
| 265 | wchar_t *ptr; |
294 | wchar_t *ptr; |
| 266 | 295 | ||
| Line 291... | Line 320... | ||
| 291 | // basic program information |
320 | // basic program information |
| 292 | wcscpy_s (engineprogram->folder, sizeof (engineprogram->folder), wfd.cFileName); // save engine program's folder name |
321 | wcscpy_s (engineprogram->folder, sizeof (engineprogram->folder), wfd.cFileName); // save engine program's folder name |
| 293 | READ_WIDESTRING (engineprogram->friendly_name, engine_inifile, L"program", L"name", L"Crafty v24.0"); |
322 | READ_WIDESTRING (engineprogram->friendly_name, engine_inifile, L"program", L"name", L"Crafty v24.0"); |
| 294 | READ_WIDESTRING (engineprogram->executable_name, engine_inifile, L"program", L"executable", L"crafty.exe"); |
323 | READ_WIDESTRING (engineprogram->executable_name, engine_inifile, L"program", L"executable", L"crafty.exe"); |
| 295 | READ_WIDESTRING (engineprogram->executable_arguments, engine_inifile, L"program", L"arguments", L""); |
324 | READ_WIDESTRING (engineprogram->executable_arguments, engine_inifile, L"program", L"arguments", L""); |
| - | 325 | READ_WIDESTRING (temp_string, engine_inifile, L"program", L"winver", L"5.1"); |
|
| - | 326 | if (iswdigit (temp_string[0])) wcscat_s (temp_string, WCHAR_SIZEOF (temp_string), L"."); // make sure version string has enough numbers |
|
| - | 327 | wcscat_s (temp_string, WCHAR_SIZEOF (temp_string), L"0.0.0.0"); // make sure version string has enough numbers |
|
| - | 328 | swscanf_s (temp_string, L"%d.%d.%d.%d", &version_numbers[0], &version_numbers[1], &version_numbers[2], &version_numbers[3]); |
|
| - | 329 | engineprogram->kernel32_minver = (((uint64_t) version_numbers[0]) << 48) | (((uint64_t) version_numbers[1]) << 32) | (((uint64_t) version_numbers[2]) << 16) | (((uint64_t) version_numbers[3]) << 0); |
|
| 296 | 330 | ||
| 297 | // reply string patterns |
331 | // reply string patterns |
| 298 | READ_WIDESTRING (engineprogram->replystring_move, engine_inifile, L"reply strings", L"move", L"): "); |
332 | READ_WIDESTRING (engineprogram->replystring_move, engine_inifile, L"reply strings", L"move", L"): "); |
| 299 | 333 | ||
| 300 | // engine commands |
334 | // engine commands |