From 967275ec19c690442e415f42967af1823b517b93 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 22 Feb 2015 21:51:17 +0100 Subject: [PATCH] Parametrize crash reporter. --- code/nel/src/misc/report.cpp | 21 ++++--- .../tools/misc/crash_report/crash_report.cpp | 61 ++++++++++++++++++- .../misc/crash_report/crash_report_socket.cpp | 7 +-- .../misc/crash_report/crash_report_socket.h | 4 ++ .../misc/crash_report/crash_report_widget.cpp | 56 ++++++++++++++++- .../misc/crash_report/crash_report_widget.h | 7 +++ 6 files changed, 139 insertions(+), 17 deletions(-) diff --git a/code/nel/src/misc/report.cpp b/code/nel/src/misc/report.cpp index 09cfc1178..58740ce28 100644 --- a/code/nel/src/misc/report.cpp +++ b/code/nel/src/misc/report.cpp @@ -92,18 +92,21 @@ static bool CanSendMailReport= false; static bool DebugDefaultBehavior, QuitDefaultBehavior; +static std::string URL = "FILL_IN_CRASH_REPORT_HOSTNAME_HERE"; + static void doSendReport() { std::string filename; - // Unfortunately Qt 4.8.5 on Windows messes up arguments. - // As a workaround the report filename is hardcoded for now. - // - //filename = "report_"; - //filename += NLMISC::toString( time( NULL ) ); - //filename += ".txt"; + filename = "report_"; + filename += NLMISC::toString( time( NULL ) ); + filename += ".txt"; - filename = "rcerrorlog.txt"; + std::string params; + params = "-log "; + params += filename; + params += " -host "; + params += URL; std::ofstream f; f.open( filename.c_str() ); @@ -115,9 +118,9 @@ static void doSendReport() f.close(); #ifdef NL_OS_WINDOWS - NLMISC::launchProgram( "crash_report.exe", filename ); + NLMISC::launchProgram( "crash_report.exe", params ); #else - NLMISC::launchProgram( "crash_report", filename ); + NLMISC::launchProgram( "crash_report", params ); #endif } diff --git a/code/nel/tools/misc/crash_report/crash_report.cpp b/code/nel/tools/misc/crash_report/crash_report.cpp index d04928d21..e083de126 100644 --- a/code/nel/tools/misc/crash_report/crash_report.cpp +++ b/code/nel/tools/misc/crash_report/crash_report.cpp @@ -21,12 +21,71 @@ #include #include +#include +#include +#include + +class CCmdLineParser +{ +public: + static void parse( int argc, char **argv, std::vector< std::pair< std::string, std::string > > &v ) + { + std::stack< std::string > stack; + std::string key; + std::string value; + + for( int i = argc - 1 ; i >= 0; i-- ) + { + stack.push( std::string( argv[ i ] ) ); + } + + while( !stack.empty() ) + { + key = stack.top(); + stack.pop(); + + // If not a real parameter ( they start with '-' ), discard. + if( key[ 0 ] != '-' ) + continue; + + // Remove the '-' + key = key.substr( 1 ); + + // No more parameters + if( stack.empty() ) + { + v.push_back( std::make_pair( key, "" ) ); + break; + } + + value = stack.top(); + + // If next parameter is a key, process it in the next iteration + if( value[ 0 ] == '-' ) + { + v.push_back( std::make_pair( key, "" ) ); + continue; + } + // Otherwise store the pair + else + { + v.push_back( std::make_pair( key, value ) ); + stack.pop(); + } + } + } +}; + int main( int argc, char **argv ) { QApplication app( argc, argv ); + std::vector< std::pair< std::string, std::string > > params; + + CCmdLineParser::parse( argc, argv, params ); + CCrashReportWidget w; - w.setFileName( "rcerrorlog.txt" ); + w.setup( params ); w.show(); return app.exec(); diff --git a/code/nel/tools/misc/crash_report/crash_report_socket.cpp b/code/nel/tools/misc/crash_report/crash_report_socket.cpp index 209ea89e8..5f8720e05 100644 --- a/code/nel/tools/misc/crash_report/crash_report_socket.cpp +++ b/code/nel/tools/misc/crash_report/crash_report_socket.cpp @@ -22,11 +22,6 @@ #include #include -namespace -{ - static const char *BUG_URL = "http://192.168.2.66/dfighter/r.php"; -} - class CCrashReportSocketPvt { public: @@ -53,7 +48,7 @@ void CCrashReportSocket::sendReport( const SCrashReportData &data ) params.addQueryItem( "descr", data.description ); params.addQueryItem( "email", data.email ); - QUrl url( BUG_URL ); + QUrl url( m_url ); QNetworkRequest request( url ); request.setRawHeader( "Connection", "close" ); diff --git a/code/nel/tools/misc/crash_report/crash_report_socket.h b/code/nel/tools/misc/crash_report/crash_report_socket.h index 24bf6c451..32ccc5da0 100644 --- a/code/nel/tools/misc/crash_report/crash_report_socket.h +++ b/code/nel/tools/misc/crash_report/crash_report_socket.h @@ -34,6 +34,9 @@ public: CCrashReportSocket( QObject *parent ); ~CCrashReportSocket(); + void setURL( const char *URL ){ m_url = URL; } + QString url() const{ return m_url; } + void sendReport( const SCrashReportData &data ); Q_SIGNALS: @@ -45,6 +48,7 @@ private Q_SLOTS: private: CCrashReportSocketPvt *m_pvt; + QString m_url; }; #endif diff --git a/code/nel/tools/misc/crash_report/crash_report_widget.cpp b/code/nel/tools/misc/crash_report/crash_report_widget.cpp index 49925765d..ff0028223 100644 --- a/code/nel/tools/misc/crash_report/crash_report_widget.cpp +++ b/code/nel/tools/misc/crash_report/crash_report_widget.cpp @@ -47,8 +47,39 @@ CCrashReportWidget::~CCrashReportWidget() m_socket = NULL; } +void CCrashReportWidget::setup( const std::vector< std::pair< std::string, std::string > > ¶ms ) +{ + for( int i = 0; i < params.size(); i++ ) + { + const std::pair< std::string, std::string > &p = params[ i ]; + const std::string &k = p.first; + const std::string &v = p.second; + + if( k == "log" ) + { + m_fileName = v.c_str(); + } + else + if( k == "host" ) + { + m_socket->setURL( v.c_str() ); + } + else + if( k == "title" ) + { + setWindowTitle( v.c_str() ); + } + } +} + void CCrashReportWidget::onLoad() { + if( !checkSettings() ) + { + close(); + return; + } + QFile f( m_fileName ); bool b = f.open( QFile::ReadOnly | QFile::Text ); if( !b ) @@ -57,6 +88,7 @@ void CCrashReportWidget::onLoad() tr( "No log file found" ), tr( "There was no log file found, therefore nothing to report. Exiting..." ) ); close(); + return; } QTextStream ss( &f ); @@ -107,4 +139,26 @@ void CCrashReportWidget::onReportFailed() tr( "Failed to send the report..." ) ); close(); -} \ No newline at end of file +} + +bool CCrashReportWidget::checkSettings() +{ + if( m_fileName.isEmpty() ) + { + QMessageBox::information( this, + tr( "No log file specified." ), + tr( "No log file specified. Exiting..." ) ); + return false; + } + + if( m_socket->url().isEmpty() ) + { + QMessageBox::information( this, + tr( "No host specified." ), + tr( "No host specified. Exiting..." ) ); + return false; + } + + return true; +} + diff --git a/code/nel/tools/misc/crash_report/crash_report_widget.h b/code/nel/tools/misc/crash_report/crash_report_widget.h index 47d16ad77..0baf2521d 100644 --- a/code/nel/tools/misc/crash_report/crash_report_widget.h +++ b/code/nel/tools/misc/crash_report/crash_report_widget.h @@ -22,6 +22,8 @@ #include "ui_crash_report_widget.h" +#include +#include class CCrashReportSocket; @@ -34,6 +36,8 @@ public: void setFileName( const char *fn ){ m_fileName = fn; } + void setup( const std::vector< std::pair< std::string, std::string > > ¶ms ); + private Q_SLOTS: void onLoad(); void onSendClicked(); @@ -44,6 +48,9 @@ private Q_SLOTS: void onReportFailed(); private: + bool checkSettings(); + + Ui::CrashReportWidget m_ui; QString m_fileName; CCrashReportSocket *m_socket;