Subversion Repositories Games.Chess Giants

Rev

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

Rev 1 Rev 11
Line 1... Line 1...
1
// localizedtexts.cpp
1
// localizedtexts.cpp
2
 
2
 
3
#include "common.h"
3
#include "common.h"
4
 
4
 
5
 
5
 
6
bool LocalizedTexts_Init (const wchar_t *lngfile_pathname)
6
bool LocalizedTexts_Init (const wchar_t *fmt, ...)
7
{
7
{
8
   // this function opens and parses the INI file containing the localized texts and fills the
8
   // this function opens and parses the INI file containing the localized texts and fills the
9
   // global text_t structure.
9
   // global text_t structure.
10
 
10
 
11
   wchar_t filename[MAX_PATH];
11
   static wchar_t lngfile_pathname[MAX_PATH];
-
 
12
   va_list argptr;
12
   void *inifile;
13
   void *inifile;
13
   text_t *text;
14
   text_t *text;
14
   int text_index;
15
   int text_index;
15
   wchar_t *id_string;
16
   wchar_t *id_string;
16
   wchar_t *filter_char;
17
   wchar_t *filter_char;
-
 
18
 
-
 
19
   // concatenate all the arguments in one string
-
 
20
   va_start (argptr, fmt);
-
 
21
   wvsprintf (lngfile_pathname, fmt, argptr);
-
 
22
   va_end (argptr);
17
 
23
 
18
   // open the INI file
24
   // open the INI file
19
   swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s\\%s", app_path, lngfile_pathname);
-
 
20
   inifile = INIFile_LoadINIFile (filename);
25
   inifile = INIFile_LoadINIFile (lngfile_pathname);
21
 
26
 
22
   // consistency check
27
   // consistency check
23
   if (inifile == NULL)
28
   if (inifile == NULL)
24
   {
29
   {
25
      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);
30
      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);
Line 46... Line 51...
46
      text->localized_string = (wchar_t *) SAFE_malloc (65536, sizeof (wchar_t), false); // allocate big space for localized string...
51
      text->localized_string = (wchar_t *) SAFE_malloc (65536, sizeof (wchar_t), false); // allocate big space for localized string...
47
      wcscpy_s (text->localized_string, 65536, INIFile_ReadEntryAsString (inifile, L"texts", text->id_string, text->id_string)); // ... read it...
52
      wcscpy_s (text->localized_string, 65536, INIFile_ReadEntryAsString (inifile, L"texts", text->id_string, text->id_string)); // ... read it...
48
      text->localized_string = (wchar_t *) SAFE_realloc (text->localized_string, 65536, wcslen (text->localized_string) + 1, sizeof (wchar_t), false); // and resize correctly
53
      text->localized_string = (wchar_t *) SAFE_realloc (text->localized_string, 65536, wcslen (text->localized_string) + 1, sizeof (wchar_t), false); // and resize correctly
49
 
54
 
50
      // conventionally, all texts whose ID end in "FileFilter" are file filters. Convert them for Windows API.
55
      // conventionally, all texts whose ID end in "FileFilter" are file filters. Convert them for Windows API.
-
 
56
      // Reminder: INI file key entries are LOWERCASE.
51
      if (wcsstr (text->id_string, L"FileFilter") != NULL)
57
      if (wcsistr (text->id_string, L"FileFilter") != NULL)
52
      {
58
      {
53
         filter_char = text->localized_string; // convert vertical bars into string terminator characters
59
         filter_char = text->localized_string; // convert vertical bars into string terminator characters
54
         while (*filter_char != 0) { if (*filter_char == L'|') *filter_char = 0; filter_char++; }
60
         while (*filter_char != 0) { if (*filter_char == L'|') *filter_char = 0; filter_char++; }
55
      }
61
      }
56
   }
62
   }