ConversationEditorMgr.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/ConversationEditorMgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/23/02 1:12p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "conversationeditormgr.h"
  37. #include "filelocations.h"
  38. #include "filemgr.h"
  39. #include "assetdatabase.h"
  40. #include "chunkio.h"
  41. #include "rawfile.h"
  42. #include "saveload.h"
  43. #include "translatedb.h"
  44. #include "conversationmgr.h"
  45. #include "conversationpage.h"
  46. #include "utils.h"
  47. /////////////////////////////////////////////////////////////////////////
  48. //
  49. // Create_Database_If_Necessary
  50. //
  51. /////////////////////////////////////////////////////////////////////////
  52. void
  53. ConversationEditorMgrClass::Create_Database_If_Necessary (void)
  54. {
  55. FileMgrClass *file_mgr = ::Get_File_Mgr ();
  56. AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
  57. //
  58. // Determine where the file should exist locally
  59. //
  60. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  61. //
  62. // Check to see if the file exists in VSS
  63. //
  64. if (asset_db.Does_File_Exist (filename) == false) {
  65. //
  66. // Save a copy of the database to disk and add it to VSS
  67. //
  68. Save_Global_Database ();
  69. asset_db.Add_File (filename);
  70. } else {
  71. //
  72. // The file exists in VSS, so update our local copy
  73. //
  74. Get_Latest_Version ();
  75. }
  76. return ;
  77. }
  78. /////////////////////////////////////////////////////////////////////////
  79. //
  80. // Save_Global_Database
  81. //
  82. /////////////////////////////////////////////////////////////////////////
  83. void
  84. ConversationEditorMgrClass::Save_Global_Database (void)
  85. {
  86. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  87. //
  88. // Create the file
  89. //
  90. HANDLE file = ::CreateFile (filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
  91. 0L, NULL);
  92. ASSERT (file != INVALID_HANDLE_VALUE);
  93. if (file != INVALID_HANDLE_VALUE) {
  94. RawFileClass file_obj;
  95. file_obj.Attach (file);
  96. ChunkSaveClass chunk_save (&file_obj);
  97. //
  98. // Save the conversation database subsystem
  99. //
  100. _ConversationMgrSaveLoad.Set_Category_To_Save (ConversationMgrClass::CATEGORY_GLOBAL);
  101. SaveLoadSystemClass::Save (chunk_save, _ConversationMgrSaveLoad);
  102. }
  103. return ;
  104. }
  105. /////////////////////////////////////////////////////////////////////////
  106. //
  107. // Load_Global_Database
  108. //
  109. /////////////////////////////////////////////////////////////////////////
  110. void
  111. ConversationEditorMgrClass::Load_Global_Database (void)
  112. {
  113. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  114. //
  115. // Open the file
  116. //
  117. HANDLE file = ::CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
  118. OPEN_EXISTING, 0L, NULL);
  119. ASSERT (file != INVALID_HANDLE_VALUE);
  120. if (file != INVALID_HANDLE_VALUE) {
  121. RawFileClass file_obj;
  122. file_obj.Attach (file);
  123. ChunkLoadClass chunk_load (&file_obj);
  124. //
  125. // Let the save/load system handle the laod
  126. //
  127. SaveLoadSystemClass::Load (chunk_load);
  128. //
  129. // Update the UI
  130. //
  131. ConversationPageClass *conversation_form = ::Get_Conversation_Form ();
  132. if (conversation_form) {
  133. conversation_form->Reload_Data ();
  134. }
  135. }
  136. return ;
  137. }
  138. /////////////////////////////////////////////////////////////////////////
  139. //
  140. // Get_Latest_Version
  141. //
  142. /////////////////////////////////////////////////////////////////////////
  143. bool
  144. ConversationEditorMgrClass::Get_Latest_Version (void)
  145. {
  146. FileMgrClass *file_mgr = ::Get_File_Mgr ();
  147. AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
  148. //
  149. // Determine where the file should exist locally
  150. //
  151. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  152. //
  153. // Ask VSS to get the latest version of the file for us
  154. //
  155. return asset_db.Get (filename);
  156. }
  157. /////////////////////////////////////////////////////////////////////////
  158. //
  159. // Check_Out
  160. //
  161. /////////////////////////////////////////////////////////////////////////
  162. bool
  163. ConversationEditorMgrClass::Check_Out (void)
  164. {
  165. FileMgrClass *file_mgr = ::Get_File_Mgr ();
  166. AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
  167. //
  168. // Determine where the file should exist locally
  169. //
  170. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  171. bool retval = true;
  172. if (asset_db.Does_File_Exist (filename)) {
  173. //
  174. // Ask VSS to check out the file to us
  175. //
  176. retval = asset_db.Check_Out_Ex (filename, ::AfxGetMainWnd ()->m_hWnd);
  177. }
  178. return retval;
  179. }
  180. /////////////////////////////////////////////////////////////////////////
  181. //
  182. // Check_In
  183. //
  184. /////////////////////////////////////////////////////////////////////////
  185. bool
  186. ConversationEditorMgrClass::Check_In (void)
  187. {
  188. FileMgrClass *file_mgr = ::Get_File_Mgr ();
  189. AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
  190. //
  191. // Determine where the file should exist locally
  192. //
  193. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  194. //
  195. // Ask VSS to check in the file for us
  196. //
  197. return asset_db.Check_In_Ex (filename, ::AfxGetMainWnd ()->m_hWnd);
  198. }
  199. /////////////////////////////////////////////////////////////////////////
  200. //
  201. // Undo_Check_Out
  202. //
  203. /////////////////////////////////////////////////////////////////////////
  204. bool
  205. ConversationEditorMgrClass::Undo_Check_Out (void)
  206. {
  207. FileMgrClass *file_mgr = ::Get_File_Mgr ();
  208. AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
  209. bool retval = false;
  210. //
  211. // Determine where the file should exist locally
  212. //
  213. CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
  214. //
  215. // We only undo the checkout if its checked out to us
  216. //
  217. if (asset_db.Get_File_Status (filename) == AssetDatabaseClass::CHECKED_OUT_TO_ME) {
  218. retval = asset_db.Undo_Check_Out (filename);
  219. }
  220. return retval;
  221. }