mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-29 20:30:54 +00:00
Parametrize crash reporter.
--HG-- branch : feature-crashreport
This commit is contained in:
parent
cfe2d60350
commit
955ef48460
6 changed files with 139 additions and 17 deletions
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
@ -21,12 +21,71 @@
|
|||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
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();
|
||||
|
|
|
@ -22,11 +22,6 @@
|
|||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
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" );
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
|
||||
#include "ui_crash_report_widget.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue