diff --git a/contrib/prtview/LoadPortalFileDialog.cpp b/contrib/prtview/LoadPortalFileDialog.cpp index 1f6f97fd..690e1e59 100644 --- a/contrib/prtview/LoadPortalFileDialog.cpp +++ b/contrib/prtview/LoadPortalFileDialog.cpp @@ -23,7 +23,6 @@ #include "LoadPortalFileDialog.h" #include "stream/stringstream.h" -#include "convert.h" #include "os/path.h" #include "qerplugin.h" diff --git a/libs/xml/xmlparser.h b/libs/xml/xmlparser.h index b25ca60a..eea3d003 100644 --- a/libs/xml/xmlparser.h +++ b/libs/xml/xmlparser.h @@ -25,7 +25,7 @@ #include #include "ixml.h" #include "libxml/parser.h" -#include "convert.h" +#include "stream/textstream.h" class TextInputStream; diff --git a/libs/xml/xmlwriter.h b/libs/xml/xmlwriter.h index 15e11637..e699e417 100644 --- a/libs/xml/xmlwriter.h +++ b/libs/xml/xmlwriter.h @@ -21,9 +21,9 @@ #pragma once -#include "convert.h" #include #include "xml/ixml.h" +#include "stream/textstream.h" class XMLEntityOutputStream { diff --git a/radiant/build.cpp b/radiant/build.cpp index 22cc7af8..c3a575b9 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -468,7 +468,7 @@ void project_verify( Project& project, Tools& tools ){ #endif } -void build_run( size_t buildIdx, CommandListener& listener ){ +std::vector build_construct_commands( size_t buildIdx ){ for ( const auto& [ name, tool ] : g_build_tools ) { StringBuffer output; @@ -476,6 +476,8 @@ void build_run( size_t buildIdx, CommandListener& listener ){ build_set_variable( name.c_str(), output.c_str() ); } + std::vector commands; + if ( const auto buildIt = Project_find( g_build_project, buildIdx ); buildIt != g_build_project.end() ) { g_lastExecutedBuild = buildIt; @@ -484,13 +486,15 @@ void build_run( size_t buildIdx, CommandListener& listener ){ StringBuffer output; command.evaluate( output ); if ( !output.empty() ) - listener.execute( output.c_str() ); + commands.emplace_back( output.c_str() ); } } else { globalErrorStream() << "build #" << buildIdx << " not defined"; } + + return commands; } diff --git a/radiant/build.h b/radiant/build.h index 805eb034..4220dfee 100644 --- a/radiant/build.h +++ b/radiant/build.h @@ -21,16 +21,13 @@ #pragma once #include +#include +#include "string/string.h" void build_set_variable( const char* name, const char* value ); void build_clear_variables(); -class CommandListener -{ -public: - virtual void execute( const char* command ) = 0; -}; -void build_run( size_t buildIdx, CommandListener& listener ); +std::vector build_construct_commands( size_t buildIdx ); void DoBuildMenu(); diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index 57f8e9ee..7ee3c075 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -36,7 +36,6 @@ #include #include "stream/stringstream.h" -#include "convert.h" #include "gtkutil/dialog.h" #include "gtkutil/entry.h" #include "gtkutil/image.h" diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index 9f91df48..59f3e85b 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -60,7 +60,6 @@ #include "os/file.h" #include "stream/stringstream.h" #include "moduleobserver.h" -#include "convert.h" #include "stringio.h" #include "gtkutil/accelerator.h" diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 76ccbb37..a45968b5 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -63,7 +63,6 @@ #include "container/array.h" #include "generic/static.h" #include "stream/stringstream.h" -#include "convert.h" #include "gtkutil/messagebox.h" #include "gtkutil/image.h" diff --git a/radiant/mru.cpp b/radiant/mru.cpp index 5de785d4..720e8645 100644 --- a/radiant/mru.cpp +++ b/radiant/mru.cpp @@ -27,7 +27,6 @@ #include "os/file.h" #include "generic/callback.h" #include "stream/stringstream.h" -#include "convert.h" #include "gtkutil/menu.h" #include "map.h" diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 938ed88a..447cd693 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -37,7 +37,6 @@ #include "debugging/debugging.h" #include "ifilesystem.h" -//#include "imap.h" #include @@ -59,15 +58,10 @@ #include "preferences.h" #include "watchbsp.h" #include "autosave.h" -#include "convert.h" QEGlobals_t g_qeglobals; -#if defined( WIN32 ) -#define PATH_MAX 260 -#endif - #if defined( POSIX ) #include // chmod #endif @@ -193,27 +187,7 @@ void bsp_shutdown(){ build_clear_variables(); } -class ArrayCommandListener : public CommandListener -{ - GPtrArray* m_array; -public: - ArrayCommandListener(){ - m_array = g_ptr_array_new(); - } - ~ArrayCommandListener(){ - g_ptr_array_free( m_array, TRUE ); - } - - void execute( const char* command ){ - g_ptr_array_add( m_array, g_strdup( command ) ); - } - - GPtrArray* array() const { - return m_array; - } -}; - -class BatchCommandListener : public CommandListener +class BatchCommandListener { TextOutputStream& m_file; std::size_t m_commandCount; @@ -255,32 +229,25 @@ void RunBSP( size_t buildIdx ){ bsp_init(); - ArrayCommandListener listener; - build_run( buildIdx, listener ); - bool monitor = false; - for ( guint i = 0; i < listener.array()->len; ++i ) - if( strstr( (char*)g_ptr_array_index( listener.array(), i ), RADIANT_MONITOR_ADDRESS ) ) - monitor = true; + const std::vector commands = build_construct_commands( buildIdx ); + const bool monitor = std::any_of( commands.cbegin(), commands.cend(), []( const CopiedString& command ){ + return strstr( command.c_str(), RADIANT_MONITOR_ADDRESS ) != 0; + } ); if ( g_WatchBSP_Enabled && monitor ) { // grab the file name for engine running const char* fullname = Map_Name( g_map ); const auto bspname = StringOutputStream( 64 )( PathFilename( fullname ) ); - BuildMonitor_Run( listener.array(), bspname.c_str() ); + BuildMonitor_Run( commands, bspname.c_str() ); } else { - char junkpath[PATH_MAX]; - strcpy( junkpath, SettingsPath_get() ); - strcat( junkpath, "junk.txt" ); + const auto junkpath = StringOutputStream( 256 )( SettingsPath_get(), "junk.txt" ); - char batpath[PATH_MAX]; #if defined( POSIX ) - strcpy( batpath, SettingsPath_get() ); - strcat( batpath, "qe3bsp.sh" ); + const auto batpath = StringOutputStream( 256 )( SettingsPath_get(), "qe3bsp.sh" ); #elif defined( WIN32 ) - strcpy( batpath, SettingsPath_get() ); - strcat( batpath, "qe3bsp.bat" ); + const auto batpath = StringOutputStream( 256 )( SettingsPath_get(), "qe3bsp.bat" ); #else #error "unsupported platform" #endif @@ -292,7 +259,8 @@ void RunBSP( size_t buildIdx ){ batchFile << "#!/bin/sh \n\n"; #endif BatchCommandListener listener( batchFile, g_WatchBSP0_DumpLog? junkpath : 0 ); - build_run( buildIdx, listener ); + for( const auto& command : commands ) + listener.execute( command.c_str() ); written = true; } } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 5a30a5d3..b140d738 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -69,7 +69,6 @@ #include "commandlib.h" #include "texmanip.h" #include "textures.h" -#include "convert.h" #include "gtkutil/menu.h" #include "gtkutil/nonmodal.h" diff --git a/radiant/watchbsp.cpp b/radiant/watchbsp.cpp index d51325e2..9aa41027 100644 --- a/radiant/watchbsp.cpp +++ b/radiant/watchbsp.cpp @@ -39,7 +39,6 @@ #include #include "commandlib.h" -#include "convert.h" #include "string/string.h" #include "stream/stringstream.h" @@ -97,13 +96,13 @@ private: socket_t *m_pListenSocket; socket_t *m_pInSocket; netmessage_t msg; - GPtrArray *m_pCmd; + std::vector m_commands; // used to timeout EBeginStep Timer m_timeout_timer; std::size_t m_iCurrentStep; QTimer m_monitoring_timer; // name of the map so we can run the engine - char *m_sBSPName; + CopiedString m_sBSPName; // buffer we use in push mode to receive data directly from the network xmlParserInputBufferPtr m_xmlInputBuffer; xmlParserCtxtPtr m_xmlParserCtxt; @@ -118,12 +117,10 @@ private: public: CWatchBSP(){ - m_pCmd = 0; m_bBSPPlugin = false; m_pListenSocket = NULL; m_pInSocket = NULL; m_eState = EIdle; - m_sBSPName = NULL; m_xmlInputBuffer = NULL; m_bNeedCtxtInit = true; m_monitoring_timer.callOnTimeout( [this](){ RoutineProcessing(); } ); @@ -142,17 +139,9 @@ public: // called regularly to keep listening void RoutineProcessing(); // start a monitoring loop with the following steps - void DoMonitoringLoop( GPtrArray *pCmd, const char *sBSPName ); + void DoMonitoringLoop( const std::vector& commands, const char *sBSPName ); void EndMonitoringLoop(){ Reset(); - if ( m_sBSPName ) { - string_release( m_sBSPName, string_length( m_sBSPName ) ); - m_sBSPName = 0; - } - if ( m_pCmd ) { - g_ptr_array_free( m_pCmd, TRUE ); - m_pCmd = 0; - } } // close everything - may be called from the outside to abort the process void Reset(); @@ -316,7 +305,7 @@ CWatchBSP *GetWatchBSP(){ return g_pWatchBSP; } -void BuildMonitor_Run( GPtrArray* commands, const char* mapName ){ +void BuildMonitor_Run( const std::vector& commands, const char* mapName ){ GetWatchBSP()->DoMonitoringLoop( commands, mapName ); } @@ -617,12 +606,12 @@ void CWatchBSP::DoEBeginStep(){ if ( !m_bBSPPlugin ) { globalOutputStream() << "=== running build command ===\n" - << static_cast( g_ptr_array_index( m_pCmd, m_iCurrentStep ) ) << "\n"; + << m_commands[m_iCurrentStep] << "\n"; - if ( !Q_Exec( NULL, (char *)g_ptr_array_index( m_pCmd, m_iCurrentStep ), NULL, true, false ) ) { + if ( !Q_Exec( NULL, const_cast( m_commands[m_iCurrentStep].c_str() ), NULL, true, false ) ) { StringOutputStream msg( 256 ); msg << "Failed to execute the following command: "; - msg << reinterpret_cast( g_ptr_array_index( m_pCmd, m_iCurrentStep ) ); + msg << m_commands[m_iCurrentStep]; msg << "\nCheck that the file exists and that you don't run out of system resources.\n"; globalOutputStream() << msg.c_str(); qt_MessageBox( MainFrame_getWindow(), msg.c_str(), "Build monitoring", EMessageBoxType::Error ); @@ -644,8 +633,8 @@ void CWatchBSP::RoutineProcessing(){ // timeout: if we don't get an incoming connection fast enough, go back to idle if ( m_timeout_timer.elapsed_sec() > g_WatchBSP_Timeout ) { qt_MessageBox( MainFrame_getWindow(), "The connection timed out, assuming the build process failed\n" - "Make sure you are using a networked version of Q3Map?\n" - "Otherwise you need to disable BSP Monitoring in prefs.", "BSP process monitoring" ); + "Make sure you are using a networked version of Q3Map?\n" + "Otherwise you need to disable BSP Monitoring in prefs.", "BSP process monitoring" ); EndMonitoringLoop(); #if 0 if ( m_bBSPPlugin ) { @@ -731,7 +720,7 @@ void CWatchBSP::RoutineProcessing(){ #endif // move to next step or finish m_iCurrentStep++; - if ( m_iCurrentStep < m_pCmd->len ) { + if ( m_iCurrentStep < m_commands.size() ) { DoEBeginStep(); } else @@ -764,7 +753,7 @@ void CWatchBSP::RoutineProcessing(){ globalOutputStream() << cmd.c_str() << " " << cmdline.c_str() << "\n"; // execute now - if ( !Q_Exec( cmd.c_str(), (char *)cmdline.c_str(), EnginePath_get(), false, false ) ) { + if ( !Q_Exec( cmd.c_str(), cmdline.c_str(), EnginePath_get(), false, false ) ) { StringOutputStream msg; msg << "Failed to execute the following command: " << cmd.c_str() << cmdline.c_str(); globalOutputStream() << msg.c_str(); @@ -782,17 +771,8 @@ void CWatchBSP::RoutineProcessing(){ } } -GPtrArray* str_ptr_array_clone( GPtrArray* array ){ - GPtrArray* cloned = g_ptr_array_sized_new( array->len ); - for ( guint i = 0; i < array->len; ++i ) - { - g_ptr_array_add( cloned, g_strdup( (char*)g_ptr_array_index( array, i ) ) ); - } - return cloned; -} - -void CWatchBSP::DoMonitoringLoop( GPtrArray *pCmd, const char *sBSPName ){ - m_sBSPName = string_clone( sBSPName ); +void CWatchBSP::DoMonitoringLoop( const std::vector& commands, const char *sBSPName ){ + m_sBSPName = sBSPName; if ( m_eState != EIdle ) { globalWarningStream() << "WatchBSP got a monitoring request while not idling...\n"; // prompt the user, should we cancel the current process and go ahead? @@ -802,7 +782,7 @@ void CWatchBSP::DoMonitoringLoop( GPtrArray *pCmd, const char *sBSPName ){ Reset(); // } } - m_pCmd = str_ptr_array_clone( pCmd ); + m_commands = commands; m_iCurrentStep = 0; DoEBeginStep(); } diff --git a/radiant/watchbsp.h b/radiant/watchbsp.h index 3976c2a8..f568498f 100644 --- a/radiant/watchbsp.h +++ b/radiant/watchbsp.h @@ -30,11 +30,13 @@ #pragma once +#include +#include "string/string.h" + void BuildMonitor_Construct(); void BuildMonitor_Destroy(); -typedef struct _GPtrArray GPtrArray; -void BuildMonitor_Run( GPtrArray* commands, const char* mapName ); +void BuildMonitor_Run( const std::vector& commands, const char* mapName ); extern bool g_WatchBSP_Enabled; extern bool g_WatchBSP_LeakStop;