1 /*
2  * Copyright 2011-2012 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ARX_TOOLS_CRASHREPORTER_ERRORREPORT_H
21 #define ARX_TOOLS_CRASHREPORTER_ERRORREPORT_H
22 
23 #include <vector>
24 
25 #include "Configure.h"
26 
27 #ifdef ARX_HAVE_WINAPI
28 // Win32
29 #include <winsock2.h>
30 #endif // ARX_HAVE_WINAPI
31 
32 // BOOST
33 #define BOOST_DATE_TIME_NO_LIB
34 #include <boost/version.hpp>
35 #if BOOST_VERSION < 104500
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-fpermissive"
38 #endif
39 #include <boost/interprocess/mapped_region.hpp>
40 #include <boost/interprocess/shared_memory_object.hpp>
41 #include <boost/interprocess/sync/interprocess_semaphore.hpp>
42 #if BOOST_VERSION < 104500
43 #pragma GCC diagnostic pop
44 #endif
45 #include <boost/scope_exit.hpp>
46 
47 // Qt
48 #include <QString>
49 #include <QList>
50 #include <QDateTime>
51 #include <QStringList>
52 
53 #include "platform/crashhandler/CrashInfo.h"
54 #include "io/fs/FilePath.h"
55 
56 class ErrorReport
57 {
58 public:
59 	class IProgressNotifier
60 	{
61 	public:
62 		virtual void taskStarted(const QString& taskDescription, int numSteps) = 0;
63 		virtual void taskStepStarted(const QString& taskStepDescription) = 0;
64 		virtual void taskStepEnded() = 0;
65 		virtual void setError(const QString& strError) = 0;
66 		virtual void setDetailedError(const QString& strDetailedError) = 0;
67 	};
68 
69 	struct File
70 	{
71 		fs::path	path;
72 		bool		attachToReport;
73 
FileFile74 		File(const fs::path _path, bool _attach)
75 		{
76 			path = _path;
77 			attachToReport = _attach;
78 		}
79 	};
80 
81 	typedef std::vector<File> FileList;
82 
83 public:
84 
85 	explicit ErrorReport(const QString & sharedMemoryName);
86 
87 	bool GenerateReport(IProgressNotifier* progressNotifier);
88 	bool SendReport(IProgressNotifier* progressNotifier);
89 
90 	FileList& GetAttachedFiles();
91 
92 	const QString& GetErrorDescription() const;
93 	const QString& GetIssueLink() const;
94 
95 	void SetLoginInfo(const QString& username, const QString& password);
96 	void SetReproSteps(const QString& reproSteps);
97 
98 private:
99 
100 	bool Initialize();
101 
102 	bool WriteReport(const fs::path& fileName);
103 
104 	bool GetCrashDump(const fs::path& fileName);
105 	bool getCrashDescription();
106 	bool GetMiscCrashInfo();
107 
108 	void AddSSLCertificate();
109 	void AddFile(const fs::path& fileName);
110 
111 	void ReleaseApplicationLock();
112 
113 private:
114 
115 	fs::path m_ReportFolder;
116 
117 	FileList m_AttachedFiles;
118 
119 	QDateTime m_CrashDateTime;
120 	double m_RunningTimeSec;
121 
122 	QString m_OSName;
123 	QString m_OSArchitecture;
124 	QString m_OSDistribution;
125 
126 	fs::path m_ProcessPath;
127 	quint64 m_ProcessMemoryUsage;
128 	QString m_ProcessArchitecture;
129 
130 	QString m_SharedMemoryName;
131 	boost::interprocess::shared_memory_object m_SharedMemory;
132 
133 	boost::interprocess::mapped_region m_MemoryMappedRegion;
134 	CrashInfo * m_pCrashInfo;
135 
136 	QString m_ReportUniqueID;
137 	QString m_ReportTitle;
138 	QString m_ReportDescription;
139 	QString m_ReportDescriptionText;
140 	QString m_ReproSteps;
141 	QString m_IssueLink;
142 
143 	QString m_Username;
144 	QString m_Password;
145 
146 	QString m_DetailedError;
147 };
148 
149 #endif // ARX_TOOLS_CRASHREPORTER_ERRORREPORT_H
150