Translator.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Installer *
  23. * *
  24. * $Archive:: /Commando/Code/Installer/Translator.cpp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 12/13/01 5:31p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "Translator.h"
  37. #include "Resource.h"
  38. #include "Win.h"
  39. #include <stdio.h>
  40. // Defines.
  41. #define RESOURCE_NOT_FOUND_STRING "[Resource %d not found]"
  42. #define WIDE_RESOURCE_NOT_FOUND_STRING L"[Resource %d not found]"
  43. /***********************************************************************************************
  44. * RxStringClass::RxStringClass -- *
  45. * *
  46. * INPUT: *
  47. * *
  48. * OUTPUT: *
  49. * *
  50. * WARNINGS: *
  51. * *
  52. * HISTORY: *
  53. * 08/22/01 IML : Created. *
  54. *=============================================================================================*/
  55. RxStringClass::RxStringClass (int resourceid)
  56. : StringClass()
  57. {
  58. int charactercount;
  59. TCHAR stringbuffer [1024];
  60. charactercount = LoadString (ProgramInstance, resourceid, stringbuffer, sizeof (stringbuffer) / sizeof (TCHAR));
  61. if (charactercount == 0) {
  62. Format (RESOURCE_NOT_FOUND_STRING, resourceid);
  63. } else {
  64. *((StringClass*) this) = stringbuffer;
  65. }
  66. }
  67. /***********************************************************************************************
  68. * RxWideStringClass::RxWideStringClass -- *
  69. * *
  70. * INPUT: *
  71. * *
  72. * OUTPUT: *
  73. * *
  74. * WARNINGS: *
  75. * *
  76. * HISTORY: *
  77. * 08/22/01 IML : Created. *
  78. *=============================================================================================*/
  79. RxWideStringClass::RxWideStringClass (int resourceid)
  80. : WideStringClass()
  81. {
  82. int charactercount;
  83. TCHAR stringbuffer [1024];
  84. charactercount = LoadString (ProgramInstance, resourceid, stringbuffer, sizeof (stringbuffer) / sizeof (TCHAR));
  85. if (charactercount == 0) {
  86. Format (WIDE_RESOURCE_NOT_FOUND_STRING, resourceid);
  87. } else {
  88. *((WideStringClass*) this) = stringbuffer;
  89. }
  90. }
  91. /***********************************************************************************************
  92. * TxWideStringClass::TxWideStringClass -- *
  93. * *
  94. * INPUT: *
  95. * *
  96. * OUTPUT: *
  97. * *
  98. * WARNINGS: *
  99. * *
  100. * HISTORY: *
  101. * 08/22/01 IML : Created. *
  102. *=============================================================================================*/
  103. TxWideStringClass::TxWideStringClass (int databaseid, int resourceid)
  104. : WideStringClass()
  105. {
  106. // In the event that the translation database has not been loaded see if there is a substitute in the resource.
  107. if (!TranslateDBClass::Is_Loaded()) {
  108. switch (databaseid) {
  109. case IDS_APPLICATION_ERROR:
  110. *((WideStringClass*) this) = RxStringClass (IDS_RESOURCE_APPLICATION_ERROR);
  111. break;
  112. default:
  113. *((WideStringClass*) this) = TRANSLATE (databaseid);
  114. break;
  115. }
  116. } else {
  117. if (resourceid != -1) {
  118. StringClass multibytestring;
  119. // If the translation cannot be converted to multi-byte format then substitute the resource.
  120. *((WideStringClass*) this) = TRANSLATE (databaseid);
  121. if (!multibytestring.Copy_Wide (*this)) {
  122. *((WideStringClass*) this) = RxStringClass (resourceid);
  123. }
  124. } else {
  125. *((WideStringClass*) this) = TRANSLATE (databaseid);
  126. }
  127. }
  128. }