| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : LevelEdit *
- * *
- * $Archive:: /Commando/Code/Tools/LevelEdit/ConversationEditorMgr.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/23/02 1:12p $*
- * *
- * $Revision:: 4 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "stdafx.h"
- #include "conversationeditormgr.h"
- #include "filelocations.h"
- #include "filemgr.h"
- #include "assetdatabase.h"
- #include "chunkio.h"
- #include "rawfile.h"
- #include "saveload.h"
- #include "translatedb.h"
- #include "conversationmgr.h"
- #include "conversationpage.h"
- #include "utils.h"
- /////////////////////////////////////////////////////////////////////////
- //
- // Create_Database_If_Necessary
- //
- /////////////////////////////////////////////////////////////////////////
- void
- ConversationEditorMgrClass::Create_Database_If_Necessary (void)
- {
- FileMgrClass *file_mgr = ::Get_File_Mgr ();
- AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
-
- //
- // Determine where the file should exist locally
- //
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
- //
- // Check to see if the file exists in VSS
- //
- if (asset_db.Does_File_Exist (filename) == false) {
-
- //
- // Save a copy of the database to disk and add it to VSS
- //
- Save_Global_Database ();
- asset_db.Add_File (filename);
- } else {
-
- //
- // The file exists in VSS, so update our local copy
- //
- Get_Latest_Version ();
- }
-
- return ;
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Save_Global_Database
- //
- /////////////////////////////////////////////////////////////////////////
- void
- ConversationEditorMgrClass::Save_Global_Database (void)
- {
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
- //
- // Create the file
- //
- HANDLE file = ::CreateFile (filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
- 0L, NULL);
- ASSERT (file != INVALID_HANDLE_VALUE);
- if (file != INVALID_HANDLE_VALUE) {
- RawFileClass file_obj;
- file_obj.Attach (file);
- ChunkSaveClass chunk_save (&file_obj);
- //
- // Save the conversation database subsystem
- //
- _ConversationMgrSaveLoad.Set_Category_To_Save (ConversationMgrClass::CATEGORY_GLOBAL);
- SaveLoadSystemClass::Save (chunk_save, _ConversationMgrSaveLoad);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Load_Global_Database
- //
- /////////////////////////////////////////////////////////////////////////
- void
- ConversationEditorMgrClass::Load_Global_Database (void)
- {
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
- //
- // Open the file
- //
- HANDLE file = ::CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, 0L, NULL);
- ASSERT (file != INVALID_HANDLE_VALUE);
- if (file != INVALID_HANDLE_VALUE) {
- RawFileClass file_obj;
- file_obj.Attach (file);
- ChunkLoadClass chunk_load (&file_obj);
- //
- // Let the save/load system handle the laod
- //
- SaveLoadSystemClass::Load (chunk_load);
- //
- // Update the UI
- //
- ConversationPageClass *conversation_form = ::Get_Conversation_Form ();
- if (conversation_form) {
- conversation_form->Reload_Data ();
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Get_Latest_Version
- //
- /////////////////////////////////////////////////////////////////////////
- bool
- ConversationEditorMgrClass::Get_Latest_Version (void)
- {
- FileMgrClass *file_mgr = ::Get_File_Mgr ();
- AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
-
- //
- // Determine where the file should exist locally
- //
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
-
- //
- // Ask VSS to get the latest version of the file for us
- //
- return asset_db.Get (filename);
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Check_Out
- //
- /////////////////////////////////////////////////////////////////////////
- bool
- ConversationEditorMgrClass::Check_Out (void)
- {
- FileMgrClass *file_mgr = ::Get_File_Mgr ();
- AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
-
- //
- // Determine where the file should exist locally
- //
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
-
- bool retval = true;
- if (asset_db.Does_File_Exist (filename)) {
-
- //
- // Ask VSS to check out the file to us
- //
- retval = asset_db.Check_Out_Ex (filename, ::AfxGetMainWnd ()->m_hWnd);
- }
-
- return retval;
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Check_In
- //
- /////////////////////////////////////////////////////////////////////////
- bool
- ConversationEditorMgrClass::Check_In (void)
- {
- FileMgrClass *file_mgr = ::Get_File_Mgr ();
- AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
-
- //
- // Determine where the file should exist locally
- //
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
-
- //
- // Ask VSS to check in the file for us
- //
- return asset_db.Check_In_Ex (filename, ::AfxGetMainWnd ()->m_hWnd);
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Undo_Check_Out
- //
- /////////////////////////////////////////////////////////////////////////
- bool
- ConversationEditorMgrClass::Undo_Check_Out (void)
- {
- FileMgrClass *file_mgr = ::Get_File_Mgr ();
- AssetDatabaseClass &asset_db = file_mgr->Get_Database_Interface ();
- bool retval = false;
- //
- // Determine where the file should exist locally
- //
- CString filename = ::Get_File_Mgr ()->Make_Full_Path (CONV_DB_PATH);
- //
- // We only undo the checkout if its checked out to us
- //
- if (asset_db.Get_File_Status (filename) == AssetDatabaseClass::CHECKED_OUT_TO_ME) {
- retval = asset_db.Undo_Check_Out (filename);
- }
- return retval;
- }
|