aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/CrashHandler.cs
blob: f49a8f390811d85a486bdbefbcb54983c0c9a8e8 (plain) (blame)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Management;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.Threading;
using System.IO;

namespace ShiftOS.Engine
{
    public class GetHardwareInfo
    {
        public static string GetProcessorName()
        {
            string ProcessorName = "";
            ManagementObjectSearcher mos
    = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");

            foreach (ManagementObject mo in mos.Get())
                ProcessorName = mo["Name"].ToString();

            return ProcessorName;
        }
        public static string GetGPUName()
        {
            string GPUName = "";
            ManagementObjectSearcher mos
    = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController");

            foreach (ManagementObject mo in mos.Get())
                GPUName = mo["Name"].ToString();

            return GPUName;
        }
        public static string GetRAMAmount()
        {
            var RAMAmount = "";
            ManagementObjectSearcher mos
    = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory");

            foreach (ManagementObject mo in mos.Get())
                RAMAmount = mo["Capacity"].ToString();

            RAMAmount = (RAMAmount + " B");

            return RAMAmount;
        }
    }


    public partial class CrashHandler : Form
    {
        public CrashHandler()
        {
            InitializeComponent();

            
            //Send the bug to Debugle
            // or alternatively, send to [email protected] OR [email protected]
            
        }

        public static Exception HandledException = null;

        public static void Start(Exception e)
        {
            if (SaveSystem.CurrentSave != null)
            {
                TerminalBackend.InvokeCommand("sos.save"); //save ShiftOS to disk before killing the session
            }

            //Close ALL FORMS in the current session.
            while (Application.OpenForms.Count != 0)
            {
                Application.OpenForms[0].Dispose();
            }

            //Disconnect us from the ShiftOS multi-user domain.
            ServerManager.Disconnect();

            //Set our global exception variable, and show the exception dialog.
            HandledException = e;
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location);
            DateTime lastModified = fileInfo.LastWriteTime;

            string rtbcrash_Text = $@" === ShiftOS has crashed === 

Basic Information For User:
---------------------------------

When:   {DateTime.Now.ToString()}
Why:    {HandledException.Message}
What:   {HandledException.GetType().Name}

We, at the ShiftOS Development Team, apologise for your game crash,
we will take this bug report seriously - and it has been emailed
to the development team of ShiftOS, thank you for enjoying our game!

Advanced Information (for experts and developers):
----------------------------------------------------

Host system information:
---------------------------------

Operating system:   {Environment.OSVersion.Platform.ToString()}
Version:            {Environment.OSVersion.VersionString}
Is 64-bit:          {Environment.Is64BitOperatingSystem}
ShiftOS exec path:  {Application.ExecutablePath}

Advanced Host Information:
---------------------------------

CPU Name:           {GetHardwareInfo.GetProcessorName()}
Physical RAM Installed:         {GetHardwareInfo.GetRAMAmount()}
GPU Name:           {GetHardwareInfo.GetGPUName()}

ShiftOS basic information:
---------------------------------

ShiftOS Version:    {Assembly.GetExecutingAssembly().GetName().Version}
ShiftOS Date:       {lastModified.ToString()}

ShiftOS environment information:
---------------------------------

Is Save loaded:             {(SaveSystem.CurrentSave != null)}
Paths loaded in system:     {JsonConvert.SerializeObject(Paths.GetAll())}


Crash: {HandledException.GetType().Name}
--------------------------------------------

Exception message:              {HandledException.Message}
HResult (this is technical):    {HandledException.HResult}
Has inner exception:            {(HandledException.InnerException != null)}
Stack trace:
{HandledException.StackTrace}";

            if (HandledException.InnerException != null)
            {
                var i = HandledException.InnerException;
                rtbcrash_Text += $@"

Inner: {i.GetType().Name}
--------------------------------------------

Exception message:              {i.Message}
HResult (this is technical):    {i.HResult}
Stack trace:
{i.StackTrace}";

            }

            File.WriteAllText("crash.txt", rtbcrash_Text);
            var result = MessageBox.Show(caption: "ShiftOS - Fatal error", text: "ShiftOS has encountered a fatal error and has been shut down. Info about the error has been saved to a file called crash.txt in the same folder as the active executable. Would you like to try and recover the game session?", buttons: MessageBoxButtons.YesNo);
            if(result == DialogResult.Yes)
            {
                Application.Restart();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnjump_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Restart();
        }
    }
}