Subversion Repositories Games.Chess Giants

Rev

Rev 83 | Rev 124 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83 Rev 119
Line 18... Line 18...
18
   // WARNING: it does also build the smilies list !
18
   // WARNING: it does also build the smilies list !
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 language_name[64];
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
   int language_index;
26
   int language_index;
-
 
27
   int program_index;
27
   int smiley_index;
28
   int smiley_index;
28
   int file_length;
29
   int file_length;
29
   FILE *fp;
30
   FILE *fp;
30
 
31
 
31
   // open the INI file
32
   // open the INI file
Line 48... Line 49...
48
   options.want_sepiafilter = (INIFile_ReadEntryAsBool (inifile, L"options", L"use sepia filter for past moves", true) > 0);
49
   options.want_sepiafilter = (INIFile_ReadEntryAsBool (inifile, L"options", L"use sepia filter for past moves", true) > 0);
49
   options.want_autorotateon1vs1 = (INIFile_ReadEntryAsBool (inifile, L"options", L"auto-rotate board",true) > 0);
50
   options.want_autorotateon1vs1 = (INIFile_ReadEntryAsBool (inifile, L"options", L"auto-rotate board",true) > 0);
50
   options.rotate_speed = INIFile_ReadEntryAsLong (inifile, L"options", L"rotation speed", 5);
51
   options.rotate_speed = INIFile_ReadEntryAsLong (inifile, L"options", L"rotation speed", 5);
51
 
52
 
52
   // [display]
53
   // [display]
53
   READ_WIDESTRING (language_name, inifile, L"display", L"language", L"auto"); // first, try to read the language from the config file
54
   READ_WIDESTRING (temp_string, inifile, L"display", L"language", L"auto"); // first, try to read the language from the config file
54
   for (language_index = 0; language_index < language_count; language_index++)
55
   for (language_index = 0; language_index < language_count; language_index++)
55
      if (_wcsicmp (languages[language_index].name, language_name) == 0)
56
      if (_wcsicmp (languages[language_index].name, temp_string) == 0)
56
      {
57
      {
57
         language_id = language_index; // identify the claimed language's ID among the list of known languages
58
         language_id = language_index; // identify the claimed language's ID among the list of known languages
58
         break; // stop searching as soon as we find it
59
         break; // stop searching as soon as we find it
59
      }
60
      }
60
   if (language_index == language_count)
61
   if (language_index == language_count)
61
   {
62
   {
62
      GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, language_name, WCHAR_SIZEOF (language_name)); // if unspecified, query the OS locale
63
      GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, temp_string, WCHAR_SIZEOF (temp_string)); // if unspecified, query the OS locale
63
      for (language_index = 0; language_index < language_count; language_index++)
64
      for (language_index = 0; language_index < language_count; language_index++)
64
         if (_wcsicmp (languages[language_index].name, language_name) == 0)
65
         if (_wcsicmp (languages[language_index].name, temp_string) == 0)
65
         {
66
         {
66
            language_id = language_index; // identify the claimed language's ID among the list of known languages
67
            language_id = language_index; // identify the claimed language's ID among the list of known languages
67
            break; // stop searching as soon as we find it
68
            break; // stop searching as soon as we find it
68
         }
69
         }
69
   }
70
   }
Line 95... Line 96...
95
   want_flaticons = (INIFile_ReadEntryAsBool (inifile, L"theme", L"flat icons instead", false) > 0);
96
   want_flaticons = (INIFile_ReadEntryAsBool (inifile, L"theme", L"flat icons instead", false) > 0);
96
   want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0);
97
   want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0);
97
   READ_WIDESTRING (custombackground_pathname, inifile, L"theme", L"custom background picture", L"");
98
   READ_WIDESTRING (custombackground_pathname, inifile, L"theme", L"custom background picture", L"");
98
 
99
 
99
   // [engine]
100
   // [engine]
-
 
101
   Config_LoadEngines (); // discover all engine parameters from the engines folder
-
 
102
   for (program_index = 0; program_index < options.engine.program_count; program_index++)
-
 
103
   {
100
   READ_WIDESTRING (options.engine.program, inifile, L"engine", L"program", L"Crafty");
104
      READ_WIDESTRING (temp_string, inifile, L"engine", L"program", L"Stockfish");
-
 
105
      if (_wcsicmp (temp_string, options.engine.programs[program_index].folder) == 0)
-
 
106
         break; // identify the preferred engine, break as soon as we find it
-
 
107
   }
-
 
108
   options.engine.selected_program = (program_index < options.engine.program_count ? program_index : 0); // consistency check
101
   options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4);
109
   options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4);
102
   options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100);
110
   options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100);
103
   options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0);
111
   options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0);
104
   options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0);
112
   options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0);
105
   options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0);
113
   options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0);
Line 184... Line 192...
184
   INIFile_FreeINIFile (inifile);
192
   INIFile_FreeINIFile (inifile);
185
   return; // finished loading config
193
   return; // finished loading config
186
}
194
}
187
 
195
 
188
 
196
 
189
void Config_LoadEngine (const wchar_t *engine_name)
197
void Config_LoadEngines ()
190
{
198
{
191
   // this function loads the engine-specific parameters. The best place to call it is at the beginning
199
   // this function loads the engine-specific parameters. The best place to call it is at the beginning
192
   // of a game versus the computer, just before the engine executable process is started.
200
   // of a game versus the computer, just before the engine executable process is started.
193
 
201
 
-
 
202
   wchar_t temp_string[MAX_PATH];
-
 
203
   engineprogram_t *engineprogram;
194
   void *engine_inifile;
204
   void *engine_inifile;
-
 
205
   WIN32_FIND_DATA wfd;
-
 
206
   HANDLE hFind;
195
   wchar_t *ptr;
207
   wchar_t *ptr;
196
 
208
 
197
   // reset values first
209
   options.engine.programs = NULL;
198
   memset (&options.engine.program_options, 0, sizeof (options.engine.program_options));
210
   options.engine.program_count = 0;
199
 
211
 
200
   // given the selected engine program, load and interpret the right engine config file
212
   swprintf_s (temp_string, sizeof (temp_string), L"%s\\engines\\*.*", app_path); // build the search pattern string out of the path
201
   swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, engine_name);
213
   hFind = FindFirstFile (temp_string, &wfd); // initiate search from that point
202
   engine_inifile = INIFile_LoadINIFile (filename);
214
   if (hFind != INVALID_HANDLE_VALUE)
-
 
215
   {
203
   if (engine_inifile == NULL)
216
      // start examining search results...
-
 
217
      do
-
 
218
      {
-
 
219
         if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (wfd.cFileName[0] == L'.'))
204
      return; // engine file not found
220
            continue; // skip everything that is NOT a directory, and every directories that begin with a dot
205
 
221
 
206
   // basic program information
222
         // reallocate space for one more engine program, and clean up the allocated slot
207
   READ_WIDESTRING (options.engine.program_options.name, engine_inifile, L"program", L"name", L"Crafty v24.0");
223
         options.engine.programs = (engineprogram_t *) SAFE_realloc (options.engine.programs, options.engine.program_count, options.engine.program_count + 1, sizeof (engineprogram_t), true);
208
   READ_WIDESTRING (options.engine.program_options.cmdline, engine_inifile, L"program", L"executable", L"crafty.exe");
224
         engineprogram = &options.engine.programs[options.engine.program_count]; // quick access to engine
209
 
225
 
-
 
226
         // given the selected engine program, load and interpret the right engine config file
-
 
227
         wcscpy_s (engineprogram->folder, sizeof (engineprogram->folder), wfd.cFileName); // save engine program's folder name
-
 
228
         swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, engineprogram->folder);
-
 
229
         engine_inifile = INIFile_LoadINIFile (filename); // see if an ini file exists for this engine
210
   // reply string patterns
230
         if (engine_inifile == NULL)
211
   READ_WIDESTRING (options.engine.program_options.replystring_move, engine_inifile, L"reply strings", L"move", L"): ");
231
            continue; // engine .ini file not found, skip this one
212
 
232
 
-
 
233
         // basic program information
-
 
234
         READ_WIDESTRING (engineprogram->name, engine_inifile, L"program", L"name", L"Crafty v24.0");
-
 
235
         READ_WIDESTRING (engineprogram->cmdline, engine_inifile, L"program", L"executable", L"crafty.exe");
-
 
236
 
-
 
237
         // reply string patterns
-
 
238
         READ_WIDESTRING (engineprogram->replystring_move, engine_inifile, L"reply strings", L"move", L"): ");
-
 
239
 
213
   // engine commands
240
         // engine commands
214
   READ_WIDESTRING (options.engine.program_options.command_new, engine_inifile, L"commands", L"new game", L"new");
241
         READ_WIDESTRING (engineprogram->command_new, engine_inifile, L"commands", L"new game", L"new");
215
   for (ptr = options.engine.program_options.command_new; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
242
         for (ptr = engineprogram->command_new; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
216
   READ_WIDESTRING (options.engine.program_options.command_setboard, engine_inifile, L"commands", L"setup table from FEN", L"setboard %s");
243
         READ_WIDESTRING (engineprogram->command_setboard, engine_inifile, L"commands", L"setup table from FEN", L"setboard %s");
217
   for (ptr = options.engine.program_options.command_setboard; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
244
         for (ptr = engineprogram->command_setboard; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
218
   READ_WIDESTRING (options.engine.program_options.command_sd, engine_inifile, L"commands", L"search depth set", L"sd %d");
245
         READ_WIDESTRING (engineprogram->command_sd, engine_inifile, L"commands", L"search depth set", L"sd %d");
219
   for (ptr = options.engine.program_options.command_sd; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
246
         for (ptr = engineprogram->command_sd; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
220
   READ_WIDESTRING (options.engine.program_options.command_go, engine_inifile, L"commands", L"play", L"go");
247
         READ_WIDESTRING (engineprogram->command_go, engine_inifile, L"commands", L"play", L"go");
221
   for (ptr = options.engine.program_options.command_go; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
248
         for (ptr = engineprogram->command_go; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
222
   READ_WIDESTRING (options.engine.program_options.command_move, engine_inifile, L"commands", L"move", L"%s");
249
         READ_WIDESTRING (engineprogram->command_move, engine_inifile, L"commands", L"move", L"%s");
223
   for (ptr = options.engine.program_options.command_move; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
250
         for (ptr = engineprogram->command_move; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
224
   READ_WIDESTRING (options.engine.program_options.command_force, engine_inifile, L"commands", L"force move", L"force %s");
251
         READ_WIDESTRING (engineprogram->command_force, engine_inifile, L"commands", L"force move", L"force %s");
225
   for (ptr = options.engine.program_options.command_force; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
252
         for (ptr = engineprogram->command_force; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
226
   READ_WIDESTRING (options.engine.program_options.command_quit, engine_inifile, L"commands", L"quit", L"quit");
253
         READ_WIDESTRING (engineprogram->command_quit, engine_inifile, L"commands", L"quit", L"quit");
227
   for (ptr = options.engine.program_options.command_quit; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
254
         for (ptr = engineprogram->command_quit; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
255
 
-
 
256
         INIFile_FreeINIFile (engine_inifile); // close the engine config file
-
 
257
 
-
 
258
         options.engine.program_count++; // we've identified one engine more
-
 
259
      } while (FindNextFile (hFind, &wfd)); // ...and don't stop as long as there are directory entries to go
-
 
260
      FindClose (hFind); // close the search handle
-
 
261
   }
228
 
262
 
229
   INIFile_FreeINIFile (engine_inifile); // close the engine config file
-
 
230
   return; // engine parameters loaded successfully
263
   return; // engine parameters loaded successfully
231
}
264
}
232
 
265
 
233
 
266
 
234
void Config_Save (void)
267
void Config_Save (void)
Line 279... Line 312...
279
   INIFile_WriteEntryAsBool (inifile, L"theme", L"flat icons instead", want_flaticons);
312
   INIFile_WriteEntryAsBool (inifile, L"theme", L"flat icons instead", want_flaticons);
280
   INIFile_WriteEntryAsBool (inifile, L"theme", L"use custom background", want_custombackground);
313
   INIFile_WriteEntryAsBool (inifile, L"theme", L"use custom background", want_custombackground);
281
   WRITE_WIDESTRING (L"theme", L"custom background picture", custombackground_pathname);
314
   WRITE_WIDESTRING (L"theme", L"custom background picture", custombackground_pathname);
282
 
315
 
283
   // [engine]
316
   // [engine]
284
   WRITE_WIDESTRING (L"engine", L"program", options.engine.program);
317
   WRITE_WIDESTRING (L"engine", L"program", options.engine.programs[options.engine.selected_program].folder);
285
   INIFile_WriteEntryAsLong (inifile, L"engine", L"allowed depth", options.engine.depth);
318
   INIFile_WriteEntryAsLong (inifile, L"engine", L"allowed depth", options.engine.depth);
286
   INIFile_WriteEntryAsLong (inifile, L"engine", L"maximum depth", options.engine.max_depth);
319
   INIFile_WriteEntryAsLong (inifile, L"engine", L"maximum depth", options.engine.max_depth);
287
   INIFile_WriteEntryAsLong (inifile, L"engine", L"blunder chances", options.engine.blunder_chances);
320
   INIFile_WriteEntryAsLong (inifile, L"engine", L"blunder chances", options.engine.blunder_chances);
288
   INIFile_WriteEntryAsLong (inifile, L"engine", L"obstinacy", options.engine.obstinacy_level);
321
   INIFile_WriteEntryAsLong (inifile, L"engine", L"obstinacy", options.engine.obstinacy_level);
289
   INIFile_WriteEntryAsBool (inifile, L"engine", L"expert mode", options.engine.is_expert_mode);
322
   INIFile_WriteEntryAsBool (inifile, L"engine", L"expert mode", options.engine.is_expert_mode);