Rev 29 | Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 32 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | #include "common.h" |
3 | #include "common.h" |
4 | 4 | ||
5 | 5 | ||
6 | // useful macros |
6 | // useful macros |
7 | #define READ_WIDESTRING( |
7 | #define READ_WIDESTRING(dest,inifile,section,key,default_value) wcscpy_s ((dest), sizeof (dest) / sizeof (wchar_t), INIFile_ReadEntryAsString ((inifile), (section), (key), (default_value))) |
8 | #define WRITE_WIDESTRING(section,key,value) INIFile_WriteEntryAsString (inifile, (section), (key), (value)) |
8 | #define WRITE_WIDESTRING(section,key,value) INIFile_WriteEntryAsString (inifile, (section), (key), (value)) |
9 | 9 | ||
10 | 10 | ||
11 | void Config_Load (void) |
11 | void Config_Load (void) |
12 | { |
12 | { |
13 | // this function opens and parses the INI configuration file for the program |
13 | // this function opens and parses the INI configuration file for the program |
14 | // WARNING: it does also build the smilies list ! |
14 | // WARNING: it does also build the smilies list ! |
15 | 15 | ||
16 | wchar_t filename[MAX_PATH]; |
16 | wchar_t filename[MAX_PATH]; |
17 | void *inifile; |
17 | void *inifile; |
- | 18 | void *engine_inifile; |
|
18 | smiley_t *smiley; |
19 | smiley_t *smiley; |
19 | char *file_buffer; |
20 | char *file_buffer; |
20 | wchar_t smiley_pathname[MAX_PATH]; |
21 | wchar_t smiley_pathname[MAX_PATH]; |
21 | wchar_t *smiley_name; |
22 | wchar_t *smiley_name; |
22 | int smiley_index; |
23 | int smiley_index; |
Line 55... | Line 56... | ||
55 | 56 | ||
56 | // [sound] |
57 | // [sound] |
57 | options.want_sounds = (INIFile_ReadEntryAsBool (inifile, L"sound", L"play sounds", true) > 0); |
58 | options.want_sounds = (INIFile_ReadEntryAsBool (inifile, L"sound", L"play sounds", true) > 0); |
58 | 59 | ||
59 | // [theme] |
60 | // [theme] |
60 | READ_WIDESTRING (wantedtheme_name, L"theme", L"theme name", L"Marble"); |
61 | READ_WIDESTRING (wantedtheme_name, inifile, L"theme", L"theme name", L"Marble"); |
61 | want_grid = (INIFile_ReadEntryAsBool (inifile, L"theme", L"show grid", false) > 0); |
62 | want_grid = (INIFile_ReadEntryAsBool (inifile, L"theme", L"show grid", false) > 0); |
62 | want_flaticons = (INIFile_ReadEntryAsBool (inifile, L"theme", L"flat icons instead", false) > 0); |
63 | want_flaticons = (INIFile_ReadEntryAsBool (inifile, L"theme", L"flat icons instead", false) > 0); |
63 | want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0); |
64 | want_custombackground = (INIFile_ReadEntryAsBool (inifile, L"theme", L"use custom background", false) > 0); |
64 | READ_WIDESTRING (custombackground_pathname, L"theme", L"custom background picture", L""); |
65 | READ_WIDESTRING (custombackground_pathname, inifile, L"theme", L"custom background picture", L""); |
65 | 66 | ||
66 | // [engine] |
67 | // [engine] |
67 | READ_WIDESTRING (options.engine. |
68 | READ_WIDESTRING (options.engine.program, inifile, L"engine", L"program", L"Crafty"); |
68 | READ_WIDESTRING (options.engine.cmdline, L"engine", L"command line", L"crafty.exe"); |
- | |
69 | READ_WIDESTRING (options.engine.init_file, L"engine", L"initialization file", L"init.txt"); |
- | |
70 | options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4); |
69 | options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4); |
71 | options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100); |
70 | options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100); |
72 | options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0); |
71 | options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0); |
73 | options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0); |
72 | options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0); |
74 | options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0); |
73 | options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0); |
75 | READ_WIDESTRING (options.engine.replystring_move, L"engine", L"move string", L"): "); |
- | |
76 | READ_WIDESTRING (options.engine.replystring_hint, L"engine", L"hint string", L"Hint: "); |
- | |
77 | 74 | ||
- | 75 | // given the selected engine program, load and interpret the right engine config file |
|
- | 76 | swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, options.engine.program); |
|
- | 77 | engine_inifile = INIFile_LoadINIFile (filename); |
|
- | 78 | if (engine_inifile != NULL) |
|
- | 79 | { |
|
- | 80 | READ_WIDESTRING (options.engine.name, engine_inifile, L"engine", L"name", L"Crafty v24.0"); |
|
- | 81 | READ_WIDESTRING (options.engine.cmdline, engine_inifile, L"engine", L"command line", L"crafty.exe"); |
|
- | 82 | READ_WIDESTRING (options.engine.replystring_move, engine_inifile, L"engine", L"move string", L"): "); |
|
- | 83 | READ_WIDESTRING (options.engine.replystring_hint, engine_inifile, L"engine", L"hint string", L"Hint: "); |
|
78 | READ_WIDESTRING (options.engine.command_new, L"engine", L"new game command", L"new"); |
84 | READ_WIDESTRING (options.engine.command_new, engine_inifile, L"engine", L"new game command", L"new"); |
79 | READ_WIDESTRING (options.engine.command_setboard, L"engine", L"setup table from FEN command", L"setboard"); |
85 | READ_WIDESTRING (options.engine.command_setboard, engine_inifile, L"engine", L"setup table from FEN command", L"setboard"); |
80 | READ_WIDESTRING (options.engine.command_sd, L"engine", L"search depth set command", L"sd"); |
86 | READ_WIDESTRING (options.engine.command_sd, engine_inifile, L"engine", L"search depth set command", L"sd"); |
81 | READ_WIDESTRING (options.engine.command_go, L"engine", L"play command", L"go"); |
87 | READ_WIDESTRING (options.engine.command_go, engine_inifile, L"engine", L"play command", L"go"); |
82 | READ_WIDESTRING (options.engine.command_hint, L"engine", L"hint command", L"hint"); |
88 | READ_WIDESTRING (options.engine.command_hint, engine_inifile, L"engine", L"hint command", L"hint"); |
83 | READ_WIDESTRING (options.engine.command_force, L"engine", L"force move command", L"force"); |
89 | READ_WIDESTRING (options.engine.command_force, engine_inifile, L"engine", L"force move command", L"force"); |
84 | READ_WIDESTRING (options.engine.command_quit, L"engine", L"quit command", L"quit"); |
90 | READ_WIDESTRING (options.engine.command_quit, engine_inifile, L"engine", L"quit command", L"quit"); |
- | 91 | ||
- | 92 | INIFile_FreeINIFile (engine_inifile); // close the engine config file |
|
- | 93 | } |
|
85 | 94 | ||
86 | // [network] |
95 | // [network] |
87 | READ_WIDESTRING (options.network.server_address, L"network", L"server address", L"freechess.org"); |
96 | READ_WIDESTRING (options.network.server_address, inifile, L"network", L"server address", L"freechess.org"); |
88 | options.network.server_port = INIFile_ReadEntryAsLong (inifile, L"network", L"server port", 5000); |
97 | options.network.server_port = INIFile_ReadEntryAsLong (inifile, L"network", L"server port", 5000); |
89 | READ_WIDESTRING (options.network.login, L"network", L"login", L"guest"); |
98 | READ_WIDESTRING (options.network.login, inifile, L"network", L"login", L"guest"); |
90 | READ_WIDESTRING (options.network.password, L"network", L"password", L""); |
99 | READ_WIDESTRING (options.network.password, inifile, L"network", L"password", L""); |
91 | options.network.want_servermessages = (INIFile_ReadEntryAsBool (inifile, L"network", L"show server messages", true) > 0); |
100 | options.network.want_servermessages = (INIFile_ReadEntryAsBool (inifile, L"network", L"show server messages", true) > 0); |
92 | options.network.want_publicchat = (INIFile_ReadEntryAsBool (inifile, L"network", L"show public chat", true) > 0); |
101 | options.network.want_publicchat = (INIFile_ReadEntryAsBool (inifile, L"network", L"show public chat", true) > 0); |
93 | options.network.want_motdonconnect = (INIFile_ReadEntryAsBool (inifile, L"network", L"show MOTD on connect", true) > 0); |
102 | options.network.want_motdonconnect = (INIFile_ReadEntryAsBool (inifile, L"network", L"show MOTD on connect", true) > 0); |
94 | 103 | ||
95 | // [registration] |
104 | // [registration] |
96 | READ_WIDESTRING (options.registration.user_email, L"registration", L"user email", L""); |
105 | READ_WIDESTRING (options.registration.user_email, inifile, L"registration", L"user email", L""); |
97 | options.registration.activation_code = INIFile_ReadEntryAsLong (inifile, L"registration", L"activation code", 0); |
106 | options.registration.activation_code = INIFile_ReadEntryAsLong (inifile, L"registration", L"activation code", 0); |
98 | 107 | ||
99 | // [smilies] |
108 | // [smilies] |
100 | smilies = NULL; |
109 | smilies = NULL; |
101 | smiley_count = 0; |
110 | smiley_count = 0; |
Line 110... | Line 119... | ||
110 | wcscpy_s (smiley->name, WCHAR_SIZEOF (smiley->name), smiley_name); |
119 | wcscpy_s (smiley->name, WCHAR_SIZEOF (smiley->name), smiley_name); |
111 | smiley->name[0] = L' '; // convert leading quote to a space |
120 | smiley->name[0] = L' '; // convert leading quote to a space |
112 | smiley->name[wcslen (smiley->name) - 1] = L' '; // convert ending quote to a space |
121 | smiley->name[wcslen (smiley->name) - 1] = L' '; // convert ending quote to a space |
113 | 122 | ||
114 | // now read the smiley's corresponding picture file |
123 | // now read the smiley's corresponding picture file |
115 | READ_WIDESTRING (smiley->filename, L"smilies", smiley_name, L"smile.wmf"); |
124 | READ_WIDESTRING (smiley->filename, inifile, L"smilies", smiley_name, L"smile.wmf"); |
116 | 125 | ||
117 | // is this filename the same as another smiley we know already ? |
126 | // is this filename the same as another smiley we know already ? |
118 | for (smiley_index = 0; smiley_index < smiley_count; smiley_index++) |
127 | for (smiley_index = 0; smiley_index < smiley_count; smiley_index++) |
119 | if (wcscmp (smilies[smiley_index].filename, smiley->filename) == 0) |
128 | if (wcscmp (smilies[smiley_index].filename, smiley->filename) == 0) |
120 | break; // break as soon as we find a match |
129 | break; // break as soon as we find a match |
Line 213... | Line 222... | ||
213 | INIFile_WriteEntryAsBool (inifile, L"theme", L"flat icons instead", want_flaticons); |
222 | INIFile_WriteEntryAsBool (inifile, L"theme", L"flat icons instead", want_flaticons); |
214 | INIFile_WriteEntryAsBool (inifile, L"theme", L"use custom background", want_custombackground); |
223 | INIFile_WriteEntryAsBool (inifile, L"theme", L"use custom background", want_custombackground); |
215 | WRITE_WIDESTRING (L"theme", L"custom background picture", custombackground_pathname); |
224 | WRITE_WIDESTRING (L"theme", L"custom background picture", custombackground_pathname); |
216 | 225 | ||
217 | // [engine] |
226 | // [engine] |
218 | WRITE_WIDESTRING (L"engine", L" |
227 | WRITE_WIDESTRING (L"engine", L"program", options.engine.program); |
219 | WRITE_WIDESTRING (L"engine", L"command line", options.engine.cmdline); |
- | |
220 | WRITE_WIDESTRING (L"engine", L"initialization file", options.engine.init_file); |
- | |
221 | INIFile_WriteEntryAsLong (inifile, L"engine", L"allowed depth", options.engine.depth); |
228 | INIFile_WriteEntryAsLong (inifile, L"engine", L"allowed depth", options.engine.depth); |
222 | INIFile_WriteEntryAsLong (inifile, L"engine", L"maximum depth", options.engine.max_depth); |
229 | INIFile_WriteEntryAsLong (inifile, L"engine", L"maximum depth", options.engine.max_depth); |
223 | INIFile_WriteEntryAsLong (inifile, L"engine", L"blunder chances", options.engine.blunder_chances); |
230 | INIFile_WriteEntryAsLong (inifile, L"engine", L"blunder chances", options.engine.blunder_chances); |
224 | INIFile_WriteEntryAsLong (inifile, L"engine", L"obstinacy", options.engine.obstinacy_level); |
231 | INIFile_WriteEntryAsLong (inifile, L"engine", L"obstinacy", options.engine.obstinacy_level); |
225 | INIFile_WriteEntryAsBool (inifile, L"engine", L"expert mode", options.engine.is_expert_mode); |
232 | INIFile_WriteEntryAsBool (inifile, L"engine", L"expert mode", options.engine.is_expert_mode); |
226 | WRITE_WIDESTRING (L"engine", L"move string", options.engine.replystring_move); |
- | |
227 | WRITE_WIDESTRING (L"engine", L"hint string", options.engine.replystring_hint); |
- | |
228 | WRITE_WIDESTRING (L"engine", L"new game command", options.engine.command_new); |
- | |
229 | WRITE_WIDESTRING (L"engine", L"setup table from FEN command", options.engine.command_setboard); |
- | |
230 | WRITE_WIDESTRING (L"engine", L"search depth set command", options.engine.command_sd); |
- | |
231 | WRITE_WIDESTRING (L"engine", L"play command", options.engine.command_go); |
- | |
232 | WRITE_WIDESTRING (L"engine", L"hint command", options.engine.command_hint); |
- | |
233 | WRITE_WIDESTRING (L"engine", L"force move command", options.engine.command_force); |
- | |
234 | WRITE_WIDESTRING (L"engine", L"quit command", options.engine.command_quit); |
- | |
235 | 233 | ||
236 | // [network] |
234 | // [network] |
237 | WRITE_WIDESTRING (L"network", L"server address", options.network.server_address); |
235 | WRITE_WIDESTRING (L"network", L"server address", options.network.server_address); |
238 | INIFile_WriteEntryAsLong (inifile, L"network", L"server port", options.network.server_port); |
236 | INIFile_WriteEntryAsLong (inifile, L"network", L"server port", options.network.server_port); |
239 | WRITE_WIDESTRING (L"network", L"login", options.network.login); |
237 | WRITE_WIDESTRING (L"network", L"login", options.network.login); |