-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleCrashReporter.cpp
150 lines (117 loc) · 3.45 KB
/
AppleCrashReporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// AppleCrashReporter.cpp
// RobloxStudio
//
// standard C/C++ Headers
#include <fstream>
// 3rd Party Headers
#include "boost/filesystem.hpp"
// Roblox Headers
#include "util/standardout.h"
#include "util/Http.h"
#include "RobloxServicesTools.h"
// Qt Headers
#include <QApplication>
#include <QSettings>
#include <QStringList>
#include <QDir>
#include <QFile>
#include <QStringBuilder>
// Roblox Studio Headers
#include "AppleCrashReporter.h"
#include "RobloxSettings.h"
const int AppleCrashReporter::maxReport = 1;
void AppleCrashReporter::check()
{
QString plistPath = QApplication::applicationDirPath() % "/../info.plist";
QSettings settings(plistPath, QSettings::NativeFormat);
if (settings.value("ENABLE_APPLE_CRASH_REPORTER").toString() == "YES")
{
QStringList fileList;
getReports(fileList);
int max = qMin(maxReport,fileList.count());
if (max == 0) max = fileList.count();
for (int i = 0; i < max; i++)
submitFile(QDir::homePath() % "/Library/Logs/DiagnosticReports/" % fileList.at(i));
}
}
void AppleCrashReporter::getReports(QStringList& fileList)
{
QStringList filters;
filters << "RobloxStudio_*.crash";
QDir crashReportDir(QDir::homePath() % "/Library/Logs/DiagnosticReports/");
fileList = crashReportDir.entryList(filters);
}
void AppleCrashReporter::submitFile(QString fileName)
{
QFile file(fileName);
if(file.exists())
uploadAndDeletFileAsync(GetDmpUrl(RobloxSettings::getBaseURL().toStdString(), true), fileName.toStdString());
}
static void handler(std::exception* ex, std::string file)
{
if (ex)
return;
std::remove(file.c_str());
// Remove the link as well in CrashReporter Dir
file.replace(file.find("DiagnosticReports"), 17, "CrashReporter");
std::remove(file.c_str());
}
void AppleCrashReporter::uploadAndDeletFileAsync(std::string url, std::string file)
{
boost::shared_ptr<std::fstream> data(new std::fstream(file.c_str(), std::ios_base::in | std::ios_base::binary));
size_t begin = data->tellg();
data->seekg (0, std::ios::end);
size_t end = data->tellg();
if (end > begin)
{
data->seekg (0, std::ios::beg);
std::string version;
while (*data)
{
char buff[255];
data->getline(buff, 255);
std::string line = buff;
if (line.substr(0, 8) == "Version:")
{
// "Version: 0.34.0.107 (107)"
for (size_t i = 8; i < line.size(); ++i)
if (line[i] != ' ')
{
line = line.substr(i);
break;
}
// "0.34.0.107 (107)"
for (size_t i = 0; i < line.size(); ++i)
if (line[i] == ' ')
{
line = line.substr(0, i);
// "0.34.0.107"
while (true)
{
size_t j = line.find('.');
if (j == std::string::npos)
break;
line = line.replace(j, 1, ",%20");
}
// "0,%2034,%200,%20107"
version = line;
break;
}
}
}
boost::filesystem::path p(file);
std::string filename = "RobloxStudio_log_";
// extract file "guid"
filename += p.filename().string().substr(13, 17);
filename += "%20";
filename += version;
filename += ".crash";
std::string fullUrl = url;
fullUrl += "?filename=" + filename;
boost::shared_ptr<std::fstream> dataPost(new std::fstream(file.c_str(), std::ios_base::in));
dataPost->seekg (0, std::ios::beg);
RBX::StandardOut::singleton()->printf(RBX::MESSAGE_OUTPUT, "Uploading %s", fullUrl.c_str());
RBX::Http(fullUrl).post(dataPost, RBX::Http::kContentTypeUrlEncoded, true, boost::bind(handler, _2, p.string()));
}
}