Subversion Repositories Games.Chess Giants

Rev

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

Rev 175 Rev 179
Line 32... Line 32...
32
   char *endptr;
32
   char *endptr;
33
   wchar_t app_pathname[MAX_PATH];
33
   wchar_t app_pathname[MAX_PATH];
34
   wchar_t font_pathname[MAX_PATH];
34
   wchar_t font_pathname[MAX_PATH];
35
   wchar_t temp_string[MAX_PATH];
35
   wchar_t temp_string[MAX_PATH];
36
   DWORD ascii_buffersize;
36
   DWORD ascii_buffersize;
-
 
37
   WSADATA wsa_data;
37
 
38
 
38
   // does an InstallerPath registry key exist? if so, it means we've just been installed
39
   // does an InstallerPath registry key exist? if so, it means we've just been installed
39
   ascii_buffersize = sizeof (temp_string);
40
   ascii_buffersize = sizeof (temp_string);
40
   if ((RegOpenKeyEx (HKEY_CURRENT_USER, L"SOFTWARE\\Chess Giants", 0, KEY_READ | KEY_SET_VALUE, &hRegistryKey) == 0)
41
   if ((RegOpenKeyEx (HKEY_CURRENT_USER, L"SOFTWARE\\Chess Giants", 0, KEY_READ | KEY_SET_VALUE, &hRegistryKey) == 0)
41
       && (RegQueryValueEx (hRegistryKey, L"InstallerPath", 0, NULL, (BYTE *) temp_string, &ascii_buffersize) == 0))
42
       && (RegQueryValueEx (hRegistryKey, L"InstallerPath", 0, NULL, (BYTE *) temp_string, &ascii_buffersize) == 0))
Line 115... Line 116...
115
   LocalizedTexts_Init ();
116
   LocalizedTexts_Init ();
116
   if (language_count < 1)
117
   if (language_count < 1)
117
   {
118
   {
118
      MessageBox (NULL, L"Chess Giants was unable to load its data files.\nThe game cannot start.\n\nPlease reinstall this program to fix the problem.", L"Chess Giants", MB_ICONERROR | MB_OK);
119
      MessageBox (NULL, L"Chess Giants was unable to load its data files.\nThe game cannot start.\n\nPlease reinstall this program to fix the problem.", L"Chess Giants", MB_ICONERROR | MB_OK);
119
      return (-1); // bomb out on error
120
      return (-1); // bomb out on error
-
 
121
   }
-
 
122
 
-
 
123
   // initialize WinSock. God knows why it's necessary.
-
 
124
   if (WSAStartup (MAKEWORD (2, 2), &wsa_data) != 0)
-
 
125
   {
-
 
126
      MessageBox (NULL, LOCALIZE (L"Error_NetworkInitializationFailed"), LOCALIZE (L"ImportantMessage"), MB_ICONERROR | MB_OK);
-
 
127
      return (-1); // bomb out if network couldn't be initialized
120
   }
128
   }
121
 
129
 
122
   // read configuration data
130
   // read configuration data
123
   Config_Load ();
131
   Config_Load ();
124
 
132
 
Line 134... Line 142...
134
         options.registration.user_email[ascii_buffersize / sizeof (wchar_t)] = 0; // terminate the string ourselves (strings in the registry MAY have no null terminator)
142
         options.registration.user_email[ascii_buffersize / sizeof (wchar_t)] = 0; // terminate the string ourselves (strings in the registry MAY have no null terminator)
135
      ascii_buffersize = sizeof (options.registration.activation_code); // in bytes
143
      ascii_buffersize = sizeof (options.registration.activation_code); // in bytes
136
      if (RegQueryValueEx (hRegistryKey, L"ActivationCode", 0, NULL, (BYTE *) &options.registration.activation_code, &ascii_buffersize) != 0)
144
      if (RegQueryValueEx (hRegistryKey, L"ActivationCode", 0, NULL, (BYTE *) &options.registration.activation_code, &ascii_buffersize) != 0)
137
         options.registration.activation_code = 0; // if we can't read the activation code DWORD properly, reset it
145
         options.registration.activation_code = 0; // if we can't read the activation code DWORD properly, reset it
138
      RegCloseKey (hRegistryKey); // once we've read the data we were interested in, close the registry key
146
      RegCloseKey (hRegistryKey); // once we've read the data we were interested in, close the registry key
139
 
147
 
140
      // now check again if we're registered
148
      // now check again if we're registered
141
      is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code);
149
      is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code);
142
   }
150
   }
143
#endif // !NO_REGISTRATION
151
#endif // !NO_REGISTRATION
144
 
152
 
Line 163... Line 171...
163
   swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title
171
   swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title
164
   if (options.want_fullscreen)
172
   if (options.want_fullscreen)
165
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title
173
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title
166
                                 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), NULL, NULL, hAppInstance, NULL);
174
                                 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), NULL, NULL, hAppInstance, NULL);
167
   else
175
   else
168
   {
176
   {
169
      // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum
177
      // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum
170
      if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK))
178
      if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK))
171
         options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect
179
         options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect
172
      if (options.window_height > GetSystemMetrics (SM_CYMAXTRACK))
180
      if (options.window_height > GetSystemMetrics (SM_CYMAXTRACK))
173
         options.window_height = GetSystemMetrics (SM_CYMAXTRACK);
181
         options.window_height = GetSystemMetrics (SM_CYMAXTRACK);
Line 297... Line 305...
297
      else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL))
305
      else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL))
298
      {
306
      {
299
         *endptr = 0; // break the string at the separator between user email and activation code
307
         *endptr = 0; // break the string at the separator between user email and activation code
300
         ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email
308
         ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email
301
         is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not
309
         is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not
302
      }
310
      }
303
#endif // !NO_REGISTRATION
311
#endif // !NO_REGISTRATION
304
   }
312
   }
305
 
313
 
306
   // TODO: this + offline statistics
314
   // TODO: this + offline statistics
307
 
315
 
308
   // enter the main loop
316
   // enter the main loop
309
   while (!terminate_everything)
317
   while (!terminate_everything)
310
   {
318
   {
311
      // see what time it is
319
      // see what time it is
Line 486... Line 494...
486
   // save configuration data
494
   // save configuration data
487
   Config_Save ();
495
   Config_Save ();
488
 
496
 
489
   // unload localized texts
497
   // unload localized texts
490
   LocalizedTexts_Shutdown ();
498
   LocalizedTexts_Shutdown ();
-
 
499
 
-
 
500
   // shutdown WinSock
-
 
501
   WSACleanup ();
491
 
502
 
492
   ExitProcess (0); // it looks like this is needed to terminate reluctant Chess Giants instances...
503
   ExitProcess (0); // it looks like this is needed to terminate reluctant Chess Giants instances...
493
   return (0); // and return to Windows.
504
   return (0); // and return to Windows.
494
}
505
}
495
 
506