EditorINI.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/EditorINI.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/04/99 3:26p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "StdAfx.H"
  36. #include "EditorINI.H"
  37. #include "b64pipe.h"
  38. #include "b64straw.h"
  39. #include "xstraw.h"
  40. #include "xpipe.h"
  41. #include "xstraw.h"
  42. #include "INISup.h"
  43. ///////////////////////////////////////////////////////////////////
  44. //
  45. // Get_Vector3
  46. //
  47. Vector3
  48. EditorINIClass::Get_Vector3
  49. (
  50. LPCTSTR section,
  51. LPCTSTR entry,
  52. const Vector3 &defvalue
  53. ) const
  54. {
  55. if (section != NULL && entry != NULL) {
  56. INIEntry * entryptr = Find_Entry(section, entry);
  57. if (entryptr && entryptr->Value != NULL) {
  58. Vector3 ret;
  59. if ( sscanf( entryptr->Value, "%f,%f,%f", &ret[0], &ret[1], &ret[2] ) == 3 ) {
  60. return ret;
  61. }
  62. }
  63. }
  64. return defvalue;
  65. }
  66. ///////////////////////////////////////////////////////////////////
  67. //
  68. // Get_Vector4
  69. //
  70. Vector4
  71. EditorINIClass::Get_Vector4
  72. (
  73. LPCTSTR section,
  74. LPCTSTR entry,
  75. const Vector4 &defvalue
  76. ) const
  77. {
  78. if (section != NULL && entry != NULL) {
  79. INIEntry * entryptr = Find_Entry(section, entry);
  80. if (entryptr && entryptr->Value != NULL) {
  81. Vector4 ret;
  82. if ( sscanf( entryptr->Value, "%f,%f,%f,%f", &ret[0], &ret[1], &ret[2], &ret[3] ) == 4 ) {
  83. return ret;
  84. }
  85. }
  86. }
  87. return defvalue;
  88. }
  89. ///////////////////////////////////////////////////////////////////
  90. //
  91. // Get_CString
  92. //
  93. CString
  94. EditorINIClass::Get_CString
  95. (
  96. LPCTSTR section,
  97. LPCTSTR entry,
  98. LPCTSTR defvalue
  99. ) const
  100. {
  101. // Read the string from the INI file
  102. TCHAR temp_string[128];
  103. Get_String (section, entry, defvalue, temp_string, sizeof (temp_string));
  104. // Convert the string to a CString object and return it to the caller
  105. return CString (temp_string);
  106. }
  107. ///////////////////////////////////////////////////////////////////
  108. //
  109. // Get_Matrix3D
  110. //
  111. Matrix3D
  112. EditorINIClass::Get_Matrix3D
  113. (
  114. LPCTSTR section,
  115. LPCTSTR entry,
  116. Matrix3D &defvalue
  117. ) const
  118. {
  119. // check input parameters
  120. if ( section == NULL || entry == NULL ) {
  121. return false;
  122. }
  123. // read UU string
  124. char buffer[128];
  125. int length = Get_String(section, entry, "", buffer, sizeof(buffer));
  126. Matrix3D tm(1);
  127. if (buffer[0] != 0) {
  128. ASSERT( strlen( buffer ) == 4*4*4 );
  129. // convert UU string to Matrix3D
  130. ASSERT( sizeof( Matrix3D ) == 3*4*4 );
  131. Base64Pipe b64pipe(Base64Pipe::DECODE);
  132. BufferPipe bpipe((void*)&tm, sizeof( Matrix3D ) );
  133. b64pipe.Put_To(&bpipe);
  134. int outcount = b64pipe.Put(buffer, length);
  135. outcount += b64pipe.End();
  136. ASSERT( outcount == sizeof( Matrix3D ) );
  137. }
  138. // Pass the matrix back to the caller
  139. return tm;
  140. }
  141. ///////////////////////////////////////////////////////////////////
  142. //
  143. // Put_Matrix3D
  144. //
  145. bool
  146. EditorINIClass::Put_Matrix3D
  147. (
  148. LPCTSTR section,
  149. LPCTSTR entry,
  150. const Matrix3D &value
  151. )
  152. {
  153. // check input parameters
  154. if ( section == NULL || entry == NULL ) {
  155. return false;
  156. }
  157. // convert Matrix3D to UU string
  158. ASSERT( sizeof( Matrix3D ) == 3*4*4 );
  159. BufferStraw straw( (void*)&value, sizeof( Matrix3D ) );
  160. Base64Straw bstraw(Base64Straw::ENCODE);
  161. bstraw.Get_From(straw);
  162. static char mat_str[4*4*4 + 1];
  163. int length = bstraw.Get(mat_str, sizeof(mat_str)-1);
  164. ASSERT( length == 4*4*4 );
  165. mat_str[length] = '\0';
  166. // save the UU string
  167. Put_String(section, entry, mat_str);
  168. // Return the true result code
  169. return true;
  170. }
  171. ///////////////////////////////////////////////////////////////////
  172. //
  173. // Put_Vector3
  174. //
  175. bool
  176. EditorINIClass::Put_Vector3
  177. (
  178. LPCTSTR section,
  179. LPCTSTR entry,
  180. const Vector3 &value
  181. )
  182. {
  183. // Assume failure
  184. bool retval = false;
  185. // Convert the vector to a string and write the string to the INI
  186. CString string_value;
  187. string_value.Format ("%f, %f, %f", value.X, value.Y, value.Z);
  188. retval = Put_String (section, entry, (LPCTSTR)string_value);
  189. // Return the true/false result code
  190. return retval;
  191. }
  192. ///////////////////////////////////////////////////////////////////
  193. //
  194. // Put_Vector4
  195. //
  196. bool
  197. EditorINIClass::Put_Vector4
  198. (
  199. LPCTSTR section,
  200. LPCTSTR entry,
  201. const Vector4 &value
  202. )
  203. {
  204. // Assume failure
  205. bool retval = false;
  206. // Convert the vector to a string and write the string to the INI
  207. CString string_value;
  208. string_value.Format ("%f, %f, %f, %f", value.X, value.Y, value.Z, value.W);
  209. retval = Put_String (section, entry, (LPCTSTR)string_value);
  210. // Return the true/false result code
  211. return retval;
  212. }