summaryrefslogtreecommitdiff
path: root/Runtime/Export/CrashReporter.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Export/CrashReporter.txt')
-rw-r--r--Runtime/Export/CrashReporter.txt150
1 files changed, 150 insertions, 0 deletions
diff --git a/Runtime/Export/CrashReporter.txt b/Runtime/Export/CrashReporter.txt
new file mode 100644
index 0000000..2f689c9
--- /dev/null
+++ b/Runtime/Export/CrashReporter.txt
@@ -0,0 +1,150 @@
+C++RAW
+
+#include "UnityPrefix.h"
+#include "Runtime/Misc/BuildSettings.h"
+#include "Runtime/Scripting/ScriptingUtility.h"
+
+CSRAW
+using System;
+using System.Collections.Generic;
+
+namespace UnityEngine
+{
+
+CLASS CrashReport
+ CSRAW static List<CrashReport> internalReports;
+ CSRAW static object reportsLock = new object();
+
+ CSRAW static int Compare(CrashReport c1, CrashReport c2)
+ {
+ long t1 = c1.time.Ticks;
+ long t2 = c2.time.Ticks;
+ if (t1 > t2)
+ return 1;
+ if (t1 < t2)
+ return -1;
+ return 0;
+ }
+
+ CSRAW static void PopulateReports()
+ {
+ lock (reportsLock)
+ {
+ if (internalReports != null)
+ return;
+
+ string[] ids = GetReports();
+ internalReports = new List<CrashReport>(ids.Length);
+ foreach (var id in ids)
+ {
+ double secondsSinceUnixEpoch;
+ string text;
+ GetReportData(id, out secondsSinceUnixEpoch, out text);
+ DateTime time = new DateTime(1970, 1, 1).AddSeconds(secondsSinceUnixEpoch);
+ internalReports.Add(new CrashReport(id, time, text));
+ }
+ internalReports.Sort(Compare);
+ }
+ }
+
+ CSRAW public static CrashReport[] reports
+ {
+ get
+ {
+ PopulateReports();
+ lock (reportsLock)
+ {
+ return internalReports.ToArray();
+ }
+ }
+ }
+
+ CSRAW public static CrashReport lastReport
+ {
+ get
+ {
+ PopulateReports();
+ lock (reportsLock)
+ {
+ if (internalReports.Count > 0)
+ {
+ return internalReports[internalReports.Count - 1];
+ }
+ }
+
+ return null;
+ }
+ }
+
+ CSRAW public static void RemoveAll()
+ {
+ foreach (var report in reports)
+ report.Remove();
+ }
+
+ CSRAW readonly string id;
+ CSRAW public readonly DateTime time;
+ CSRAW public readonly string text;
+
+ CSRAW CrashReport(string id, DateTime time, string text)
+ {
+ this.id = id;
+ this.time = time;
+ this.text = text;
+ }
+
+ CSRAW public void Remove()
+ {
+ if (RemoveReport(id))
+ {
+ lock (reportsLock)
+ {
+ internalReports.Remove(this);
+ }
+ }
+ }
+
+ THREAD_SAFE CUSTOM private static string[] GetReports()
+ {
+ if (!GetBuildSettings().hasAdvancedVersion)
+ {
+ ErrorString("Crash reports are only supported in Unity Pro.");
+ std::vector<std::string> reports;
+ return Scripting::StringVectorToMono(reports);
+ }
+
+#if UNITY_IPHONE
+ extern ScriptingArrayPtr GetCrashReports();
+ return GetCrashReports();
+#else
+ std::vector<std::string> reports;
+ return Scripting::StringVectorToMono(reports);
+#endif
+ }
+
+ THREAD_SAFE CUSTOM private static void GetReportData(string id, out double secondsSinceUnixEpoch, out string text)
+ {
+#if UNITY_IPHONE
+ extern void GetCrashReportData(ICallString id, double* secondsSinceUnixEpoch, ICallString* text);
+ GetCrashReportData(id, secondsSinceUnixEpoch, text);
+#else
+ *secondsSinceUnixEpoch = 0.0;
+#if !UNITY_WINRT && !UNITY_FLASH
+ text->str = scripting_string_new("");
+#endif
+#endif
+ }
+
+ THREAD_SAFE CUSTOM private static bool RemoveReport(string id)
+ {
+#if UNITY_IPHONE
+ extern bool RemoveCrashReport(ICallString id);
+ return RemoveCrashReport(id);
+#else
+ return false;
+#endif
+ }
+END
+
+CSRAW
+}