initial commit
This commit is contained in:
commit
9d20827c46
2469 changed files with 470994 additions and 0 deletions
12
crashreporter/.gitignore
vendored
Normal file
12
crashreporter/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/Makefile
|
||||
/Makefile.Debug
|
||||
/Makefile.Release
|
||||
/_moc
|
||||
/_obj
|
||||
/_ui
|
||||
/debug
|
||||
/release
|
||||
/.moc
|
||||
/.obj
|
||||
/.ui
|
||||
/crashreporter
|
||||
294
crashreporter/crashreporter.cpp
Normal file
294
crashreporter/crashreporter.cpp
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* crashreporter.cpp - simple crash reporter
|
||||
* Copyright (C) 2008 Michail Pishchagin
|
||||
*
|
||||
* 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 2
|
||||
* 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 library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QProcess>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QHttpRequestHeader>
|
||||
#include <QCloseEvent>
|
||||
#include <QUrl>
|
||||
|
||||
#include "ui_crashreporter.h"
|
||||
|
||||
#if defined(Q_WS_WIN)
|
||||
#include "mailmsg_windows.h"
|
||||
#endif
|
||||
|
||||
class CrashReporter : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CrashReporter()
|
||||
: QWidget()
|
||||
, http_(0)
|
||||
, restartButton_(0)
|
||||
, quitButton_(0)
|
||||
{
|
||||
ui_.setupUi(this);
|
||||
|
||||
appName_ = "Application";
|
||||
|
||||
http_ = new QHttp(this);
|
||||
connect(http_, SIGNAL(done(bool)), SLOT(httpDone(bool)));
|
||||
|
||||
ui_.textEdit->setFocus();
|
||||
}
|
||||
|
||||
void doShow()
|
||||
{
|
||||
ui_.label->setText(ui_.label->text().arg(appName_));
|
||||
|
||||
if (!appPath_.isEmpty()) {
|
||||
restartButton_ = ui_.buttonBox->addButton(tr("Restart %1").arg(appName_), QDialogButtonBox::AcceptRole);
|
||||
connect(restartButton_, SIGNAL(clicked()), SLOT(restartApp()));
|
||||
}
|
||||
|
||||
quitButton_ = ui_.buttonBox->addButton(tr("Quit %1").arg(appName_), QDialogButtonBox::RejectRole);
|
||||
connect(quitButton_, SIGNAL(clicked()), SLOT(quitApp()));
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
void setAppName(const QString& appName)
|
||||
{
|
||||
appName_ = appName;
|
||||
}
|
||||
|
||||
void setAppVersion(const QString& appVersion)
|
||||
{
|
||||
appVersion_ = appVersion;
|
||||
}
|
||||
|
||||
void setAppPath(const QString& appPath)
|
||||
{
|
||||
appPath_ = appPath;
|
||||
}
|
||||
|
||||
void setMinidump(const QString& minidump)
|
||||
{
|
||||
minidump_ = minidump;
|
||||
}
|
||||
|
||||
void setReportURL(const QString& reportURL)
|
||||
{
|
||||
reportURL_ = reportURL;
|
||||
}
|
||||
|
||||
void setReportEmail(const QString& reportEmail)
|
||||
{
|
||||
reportEmail_ = reportEmail;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void restartApp()
|
||||
{
|
||||
if (!appPath_.isEmpty()) {
|
||||
QProcess::startDetached(appPath_);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
void quitApp()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
QByteArray makeFormField(const QString& name, const QByteArray& data)
|
||||
{
|
||||
QByteArray result;
|
||||
result.append("------FormBoundary5WRMUdn8jqMNiFOP\r\n");
|
||||
result.append("Content-Disposition: form-data; name=\"" + name + "\"\r\n");
|
||||
result.append("\r\n");
|
||||
result.append(data);
|
||||
result.append("\r\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool reportCrash()
|
||||
{
|
||||
if (reportURL_.isEmpty()) {
|
||||
qWarning("report url is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
QFileInfo fi(minidump_);
|
||||
if (!fi.exists()) {
|
||||
qWarning("minidump not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile minidump(minidump_);
|
||||
if (!minidump.open(QIODevice::ReadOnly)) {
|
||||
qWarning("unable to open minidump");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ui_.groupBox->isChecked() || !http_)
|
||||
return false;
|
||||
|
||||
if (restartButton_)
|
||||
restartButton_->setEnabled(false);
|
||||
if (quitButton_)
|
||||
quitButton_->setEnabled(false);
|
||||
|
||||
QUrl url(reportURL_, QUrl::TolerantMode);
|
||||
QHttpRequestHeader header("POST", url.path());
|
||||
header.setValue("User-Agent", "crashreporter");
|
||||
header.setValue("Host", url.port() == -1 ? url.host() : QString("%1:%2").arg(url.host(), url.port()));
|
||||
header.setValue("Accept-Language", "en-us");
|
||||
header.setValue("Content-Type", "multipart/form-data; boundary=----FormBoundary5WRMUdn8jqMNiFOP");
|
||||
header.setValue("Accept", "*/*");
|
||||
|
||||
QByteArray bytes;
|
||||
bytes.append(makeFormField("app-name", appName_.toUtf8()));
|
||||
bytes.append(makeFormField("app-version", appVersion_.toUtf8()));
|
||||
bytes.append(makeFormField("comments", ui_.textEdit->toPlainText().toUtf8()));
|
||||
bytes.append(makeFormField("upload_file_minidump", minidump.readAll()));
|
||||
|
||||
bytes.append("------FormBoundary5WRMUdn8jqMNiFOP--");
|
||||
bytes.append("\r\n");
|
||||
|
||||
int contentLength = bytes.length();
|
||||
header.setContentLength(contentLength);
|
||||
|
||||
http_->setHost(url.host(), url.port() == -1 ? 80 : url.port());
|
||||
http_->request(header, bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void httpDone(bool error)
|
||||
{
|
||||
if (error) {
|
||||
qWarning("CrashReporter: ERROR: %s", qPrintable(http_->errorString()));
|
||||
sendEmail();
|
||||
http_->abort();
|
||||
}
|
||||
else {
|
||||
QString result(http_->readAll());
|
||||
QRegExp rx("CrashID\\=([\\d\\w-]+)");
|
||||
if (rx.indexIn(result) != -1) {
|
||||
qWarning("CrashReporter: CrashID=%s", qPrintable(rx.capturedTexts().at(1)));
|
||||
}
|
||||
}
|
||||
|
||||
delete http_;
|
||||
http_ = 0;
|
||||
close();
|
||||
}
|
||||
|
||||
void sendEmail()
|
||||
{
|
||||
if (reportEmail_.isEmpty()) {
|
||||
qWarning("report email is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(Q_WS_WIN)
|
||||
QStringList attachments;
|
||||
QFileInfo fi(minidump_);
|
||||
if (fi.exists()) {
|
||||
attachments << fi.absoluteFilePath();
|
||||
}
|
||||
|
||||
MailMsg::sendEmail(reportEmail_,
|
||||
"Crash report",
|
||||
ui_.textEdit->toPlainText(),
|
||||
attachments);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
// reimplemented
|
||||
void closeEvent(QCloseEvent* e)
|
||||
{
|
||||
if (reportCrash()) {
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
QWidget::closeEvent(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Ui::CrashReporter ui_;
|
||||
QHttp* http_;
|
||||
QPushButton* restartButton_;
|
||||
QPushButton* quitButton_;
|
||||
QString appName_;
|
||||
QString appVersion_;
|
||||
QString appPath_;
|
||||
QString minidump_;
|
||||
QString reportURL_;
|
||||
QString reportEmail_;
|
||||
};
|
||||
|
||||
static QString optionValue(const QString& optionName, const QString string)
|
||||
{
|
||||
if (string.startsWith(QString("-%1=").arg(optionName))) {
|
||||
QStringList list = string.split("=");
|
||||
list.removeFirst();
|
||||
if (!list.isEmpty()) {
|
||||
return list.join("=");
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
CrashReporter crashReporter;
|
||||
|
||||
for (int n = 1; n < argc; ++n) {
|
||||
QString str = argv[n];
|
||||
if (!optionValue("appName", str).isEmpty()) {
|
||||
crashReporter.setAppName(optionValue("appName", str));
|
||||
}
|
||||
|
||||
if (!optionValue("appVersion", str).isEmpty()) {
|
||||
crashReporter.setAppVersion(optionValue("appVersion", str));
|
||||
}
|
||||
|
||||
if (!optionValue("appPath", str).isEmpty()) {
|
||||
crashReporter.setAppPath(optionValue("appPath", str));
|
||||
}
|
||||
|
||||
if (!optionValue("minidump", str).isEmpty()) {
|
||||
crashReporter.setMinidump(optionValue("minidump", str));
|
||||
}
|
||||
|
||||
if (!optionValue("reportURL", str).isEmpty()) {
|
||||
crashReporter.setReportURL(optionValue("reportURL", str));
|
||||
}
|
||||
|
||||
if (!optionValue("reportEmail", str).isEmpty()) {
|
||||
crashReporter.setReportEmail(optionValue("reportEmail", str));
|
||||
}
|
||||
}
|
||||
|
||||
crashReporter.doShow();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "crashreporter.moc"
|
||||
33
crashreporter/crashreporter.pro
Normal file
33
crashreporter/crashreporter.pro
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
TEMPLATE = app
|
||||
CONFIG += qt debug
|
||||
CONFIG -= app_bundle
|
||||
QT += gui network
|
||||
SOURCES += crashreporter.cpp
|
||||
INTERFACES += crashreporter.ui
|
||||
include($$PWD/mailmsg/mailmsg.pri)
|
||||
|
||||
include(/users/mblsha/src/psi-git/qa/oldtest/unittest.pri)
|
||||
|
||||
mac {
|
||||
QMAKE_POST_LINK = rm -f ../test/test.app/Contents/Resources/crashreporter; mkdir -p ../test/test.app/Contents/Resources; cp crashreporter ../test/test.app/Contents/Resources
|
||||
}
|
||||
|
||||
win32 {
|
||||
QMAKE_POST_LINK = del /Q ..\test\release\crashreporter.exe && copy release\crashreporter.exe ..\test\release\crashreporter.exe
|
||||
}
|
||||
|
||||
windows {
|
||||
# otherwise we would get 'unresolved external _WinMainCRTStartup'
|
||||
# when compiling with MSVC
|
||||
MOC_DIR = _moc
|
||||
OBJECTS_DIR = _obj
|
||||
UI_DIR = _ui
|
||||
RCC_DIR = _rcc
|
||||
}
|
||||
!windows {
|
||||
MOC_DIR = .moc
|
||||
OBJECTS_DIR = .obj
|
||||
UI_DIR = .ui
|
||||
RCC_DIR = .rcc
|
||||
}
|
||||
|
||||
59
crashreporter/crashreporter.ui
Normal file
59
crashreporter/crashreporter.ui
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<ui version="4.0" >
|
||||
<class>CrashReporter</class>
|
||||
<widget class="QWidget" name="Form" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>422</width>
|
||||
<height>313</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Crash Reporter</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>%1 had a problem and crashed. We'll try to restore all your data when it restarts. To help us diagnose and fix the problem, you can send us a crash report.</string>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Send crash report</string>
|
||||
</property>
|
||||
<property name="checkable" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<string>Add a comment:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit" />
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::NoButton</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
7
crashreporter/mailmsg/mailmsg.pri
Normal file
7
crashreporter/mailmsg/mailmsg.pri
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
win32 {
|
||||
SOURCES += $$PWD/mailmsg_windows.cpp
|
||||
HEADERS += $$PWD/mailmsg_windows.h
|
||||
}
|
||||
124
crashreporter/mailmsg/mailmsg_windows.cpp
Normal file
124
crashreporter/mailmsg/mailmsg_windows.cpp
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* mailmsg_windows.cpp - send e-mails programmaticaly. On Windows.
|
||||
* Copyright (C) 2008 Michail Pishchagin
|
||||
*
|
||||
* 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 2
|
||||
* 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 library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
// based on code taken from MailMsg.cpp by Michael Carruth
|
||||
// http://code.google.com/p/crashrpt/
|
||||
|
||||
#include <windows.h>
|
||||
#include <mapi.h>
|
||||
|
||||
#include "mailmsg_windows.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QLibrary>
|
||||
#include <QSettings>
|
||||
|
||||
LPSTR qStringToLPSTR(const QString& qString)
|
||||
{
|
||||
// return qString.toLocal8Bit().data();
|
||||
return qString.toLatin1().data();
|
||||
}
|
||||
|
||||
QString mapi32path()
|
||||
{
|
||||
// // try to determine default Simple MAPI handler
|
||||
// // first, look for current user's default client
|
||||
// registry::tstring default_client = registry::const_key(HKEY_CURRENT_USER, "Software\\Clients\\Mail")[""].reg_sz("");
|
||||
//
|
||||
// if (default_client.empty()) {
|
||||
// // then look for machine-wide settings
|
||||
// default_client = registry::const_key(HKEY_LOCAL_MACHINE, "Software\\Clients\\Mail")[""].reg_sz("");
|
||||
// }
|
||||
//
|
||||
// if (!default_client.empty()) {
|
||||
// registry::const_key regClient(HKEY_LOCAL_MACHINE, registry::tstring("Software\\Clients\\Mail\\" + default_client).c_str());
|
||||
// registry::tstring s = regClient["DLLPath"].reg_sz("");
|
||||
//
|
||||
// if (s.empty())
|
||||
// s = regClient["DLLPathEx"].reg_sz("");
|
||||
//
|
||||
// if (!s.empty())
|
||||
// dllpath = s;
|
||||
// }
|
||||
|
||||
return "mapi32";
|
||||
}
|
||||
|
||||
void MailMsg::sendEmail(const QString& to, const QString& subject, const QString& message, const QStringList& attachments)
|
||||
{
|
||||
qWarning("sending off email...");
|
||||
QLibrary mapi32(mapi32path());
|
||||
if (!mapi32.load()) {
|
||||
qWarning("MailMsg: failed to load mapi32.dll");
|
||||
return;
|
||||
}
|
||||
|
||||
LPMAPISENDMAIL mapiSendMail = 0;
|
||||
mapiSendMail = (LPMAPISENDMAIL)mapi32.resolve("MAPISendMail");
|
||||
if (!mapiSendMail) {
|
||||
qWarning("MailMsg: failed to resolve MAPISendMail");
|
||||
return;
|
||||
}
|
||||
|
||||
MapiRecipDesc* pRecipients = NULL;
|
||||
MapiFileDesc* pAttachments = NULL;
|
||||
MapiMessage msg;
|
||||
|
||||
pRecipients = new MapiRecipDesc[1];
|
||||
pRecipients[0].ulReserved = 0;
|
||||
pRecipients[0].ulRecipClass = MAPI_TO;
|
||||
pRecipients[0].lpszAddress = qStringToLPSTR(to);
|
||||
pRecipients[0].lpszName = qStringToLPSTR(to);
|
||||
pRecipients[0].ulEIDSize = 0;
|
||||
pRecipients[0].lpEntryID = NULL;
|
||||
|
||||
if (attachments.size())
|
||||
pAttachments = new MapiFileDesc[attachments.size()];
|
||||
for (int i = 0; i < attachments.size(); ++i) {
|
||||
pAttachments[i].ulReserved = 0;
|
||||
pAttachments[i].flFlags = 0;
|
||||
pAttachments[i].nPosition = 0xFFFFFFFF;
|
||||
pAttachments[i].lpszPathName = qStringToLPSTR(attachments[i]);
|
||||
pAttachments[i].lpszFileName = qStringToLPSTR(attachments[i]);
|
||||
pAttachments[i].lpFileType = NULL;
|
||||
}
|
||||
|
||||
msg.ulReserved = 0;
|
||||
msg.lpszSubject = qStringToLPSTR(subject);
|
||||
msg.lpszNoteText = qStringToLPSTR(message);
|
||||
msg.lpszMessageType = NULL;
|
||||
msg.lpszDateReceived = NULL;
|
||||
msg.lpszConversationID = NULL;
|
||||
msg.flFlags = 0;
|
||||
msg.lpOriginator = NULL;
|
||||
msg.nRecipCount = 1;
|
||||
msg.lpRecips = pRecipients;
|
||||
msg.nFileCount = attachments.size();
|
||||
msg.lpFiles = pAttachments;
|
||||
|
||||
int status = mapiSendMail(0, 0, &msg, MAPI_DIALOG | MAPI_LOGON_UI | MAPI_NEW_SESSION, 0);
|
||||
Q_UNUSED(status);
|
||||
|
||||
if (pRecipients)
|
||||
delete[] pRecipients;
|
||||
|
||||
if (pAttachments)
|
||||
delete[] pAttachments;
|
||||
}
|
||||
31
crashreporter/mailmsg/mailmsg_windows.h
Normal file
31
crashreporter/mailmsg/mailmsg_windows.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* mailmsg_windows.h - send e-mails programmaticaly. On Windows.
|
||||
* Copyright (C) 2008 Michail Pishchagin
|
||||
*
|
||||
* 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 2
|
||||
* 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 library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MAILMSG_WINDOWS_H
|
||||
#define MAILMSG_WINDOWS_H
|
||||
|
||||
class QString;
|
||||
class QStringList;
|
||||
|
||||
namespace MailMsg {
|
||||
void sendEmail(const QString& to, const QString& subject, const QString& message, const QStringList& attachments);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in a new issue