Skip to content

Commit 2ed2198

Browse files
committed
fail nicely when exception thrown in Form1 constructor
1 parent 423aaba commit 2ed2198

File tree

1 file changed

+91
-83
lines changed

1 file changed

+91
-83
lines changed

UAssetGUI/Form1.cs

Lines changed: 91 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -76,119 +76,127 @@ public Form1()
7676

7777
UAGUtils.InitializeInvoke(this);
7878

79-
UAGConfig.Load();
79+
try
80+
{
81+
UAGConfig.Load();
8082

81-
Assembly assembly = Assembly.GetExecutingAssembly();
82-
UAGUtils._displayVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
83+
Assembly assembly = Assembly.GetExecutingAssembly();
84+
UAGUtils._displayVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
8385

84-
string gitVersionGUI = string.Empty;
85-
using (Stream stream = assembly.GetManifestResourceStream("UAssetGUI.git_commit.txt"))
86-
{
87-
if (stream != null)
86+
string gitVersionGUI = string.Empty;
87+
using (Stream stream = assembly.GetManifestResourceStream("UAssetGUI.git_commit.txt"))
8888
{
89-
using (StreamReader reader = new StreamReader(stream))
89+
if (stream != null)
9090
{
91-
if (reader != null) gitVersionGUI = reader.ReadToEnd().Trim();
91+
using (StreamReader reader = new StreamReader(stream))
92+
{
93+
if (reader != null) gitVersionGUI = reader.ReadToEnd().Trim();
94+
}
9295
}
9396
}
94-
}
9597

96-
if (!gitVersionGUI.All("0123456789abcdef".Contains)) gitVersionGUI = string.Empty;
98+
if (!gitVersionGUI.All("0123456789abcdef".Contains)) gitVersionGUI = string.Empty;
9799

98-
string gitVersionAPI = string.Empty;
99-
using (Stream stream = typeof(PropertyData).Assembly.GetManifestResourceStream("UAssetAPI.git_commit.txt"))
100-
{
101-
if (stream != null)
100+
string gitVersionAPI = string.Empty;
101+
using (Stream stream = typeof(PropertyData).Assembly.GetManifestResourceStream("UAssetAPI.git_commit.txt"))
102102
{
103-
using (StreamReader reader = new StreamReader(stream))
103+
if (stream != null)
104104
{
105-
if (reader != null) gitVersionAPI = reader.ReadToEnd().Trim();
105+
using (StreamReader reader = new StreamReader(stream))
106+
{
107+
if (reader != null) gitVersionAPI = reader.ReadToEnd().Trim();
108+
}
106109
}
107110
}
108-
}
109111

110-
if (!gitVersionAPI.All("0123456789abcdef".Contains)) gitVersionAPI = string.Empty;
112+
if (!gitVersionAPI.All("0123456789abcdef".Contains)) gitVersionAPI = string.Empty;
111113

112-
if (!string.IsNullOrEmpty(gitVersionGUI))
113-
{
114-
UAGUtils._displayVersion += " (" + gitVersionGUI;
115-
if (!string.IsNullOrEmpty(gitVersionAPI))
114+
if (!string.IsNullOrEmpty(gitVersionGUI))
116115
{
117-
UAGUtils._displayVersion += " - " + gitVersionAPI;
116+
UAGUtils._displayVersion += " (" + gitVersionGUI;
117+
if (!string.IsNullOrEmpty(gitVersionAPI))
118+
{
119+
UAGUtils._displayVersion += " - " + gitVersionAPI;
120+
}
121+
UAGUtils._displayVersion += ")";
118122
}
119-
UAGUtils._displayVersion += ")";
120-
}
121123

122-
this.Text = DisplayVersion;
123-
this.AllowDrop = true;
124-
dataGridView1.Visible = true;
124+
this.Text = DisplayVersion;
125+
this.AllowDrop = true;
126+
dataGridView1.Visible = true;
125127

126-
// Extra data viewer
127-
byteView1 = new ByteViewer
128-
{
129-
Dock = DockStyle.Fill,
130-
AutoScroll = true,
131-
AutoSize = true,
132-
Visible = false
133-
};
134-
splitContainer1.Panel2.Controls.Add(byteView1);
128+
// Extra data viewer
129+
byteView1 = new ByteViewer
130+
{
131+
Dock = DockStyle.Fill,
132+
AutoScroll = true,
133+
AutoSize = true,
134+
Visible = false
135+
};
136+
splitContainer1.Panel2.Controls.Add(byteView1);
135137

136-
jsonView = new TextBox
137-
{
138-
Dock = DockStyle.Fill,
139-
Visible = false,
140-
AutoSize = true,
141-
Multiline = true,
142-
ReadOnly = true,
143-
MaxLength = int.MaxValue,
144-
ScrollBars = ScrollBars.Both,
145-
};
146-
splitContainer1.Panel2.Controls.Add(jsonView);
138+
jsonView = new TextBox
139+
{
140+
Dock = DockStyle.Fill,
141+
Visible = false,
142+
AutoSize = true,
143+
Multiline = true,
144+
ReadOnly = true,
145+
MaxLength = int.MaxValue,
146+
ScrollBars = ScrollBars.Both,
147+
};
148+
splitContainer1.Panel2.Controls.Add(jsonView);
147149

148-
jsonView.TextChanged += (object sender, EventArgs e) => { if (tableEditor == null) return; tableEditor.dirtySinceLastLoad = true; SetUnsavedChanges(true); };
150+
jsonView.TextChanged += (object sender, EventArgs e) => { if (tableEditor == null) return; tableEditor.dirtySinceLastLoad = true; SetUnsavedChanges(true); };
149151

150-
importBinaryData.Visible = false;
151-
exportBinaryData.Visible = false;
152-
setBinaryData.Visible = false;
152+
importBinaryData.Visible = false;
153+
exportBinaryData.Visible = false;
154+
setBinaryData.Visible = false;
153155

154-
// Enable double buffering to look nicer
155-
if (!SystemInformation.TerminalServerSession)
156-
{
157-
Type ourGridType = dataGridView1.GetType();
158-
PropertyInfo pi = ourGridType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
159-
pi.SetValue(dataGridView1, true, null);
160-
}
156+
// Enable double buffering to look nicer
157+
if (!SystemInformation.TerminalServerSession)
158+
{
159+
Type ourGridType = dataGridView1.GetType();
160+
PropertyInfo pi = ourGridType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
161+
pi.SetValue(dataGridView1, true, null);
162+
}
161163

162-
// Auto resizing
163-
SizeChanged += frm_sizeChanged;
164-
FormClosing += frm_closing;
164+
// Auto resizing
165+
SizeChanged += frm_sizeChanged;
166+
FormClosing += frm_closing;
165167

166-
// position of ByteViewer buttons depends on splitter location so resize if splitter moves
167-
splitContainer1.SplitterMoved += (sender, e) => { ForceResize(); };
168+
// position of ByteViewer buttons depends on splitter location so resize if splitter moves
169+
splitContainer1.SplitterMoved += (sender, e) => { ForceResize(); };
168170

169-
// Drag-and-drop support
170-
DragEnter += new DragEventHandler(frm_DragEnter);
171-
DragDrop += new DragEventHandler(frm_DragDrop);
171+
// Drag-and-drop support
172+
DragEnter += new DragEventHandler(frm_DragEnter);
173+
DragDrop += new DragEventHandler(frm_DragDrop);
172174

173-
dataGridView1.MouseWheel += dataGridView1_MouseWheel;
174-
//dataGridView1.EditMode = UAGConfig.Data.DoubleClickToEdit ? DataGridViewEditMode.EditProgrammatically : DataGridViewEditMode.EditOnEnter;
175+
dataGridView1.MouseWheel += dataGridView1_MouseWheel;
176+
//dataGridView1.EditMode = UAGConfig.Data.DoubleClickToEdit ? DataGridViewEditMode.EditProgrammatically : DataGridViewEditMode.EditOnEnter;
175177

176-
menuStrip1.Renderer = new UAGMenuStripRenderer();
177-
foreach (ToolStripMenuItem entry in menuStrip1.Items)
178-
{
179-
entry.DropDownOpened += (sender, args) =>
180-
{
181-
isDropDownOpened[entry] = true;
182-
};
183-
entry.DropDownClosed += (sender, args) =>
178+
menuStrip1.Renderer = new UAGMenuStripRenderer();
179+
foreach (ToolStripMenuItem entry in menuStrip1.Items)
184180
{
185-
isDropDownOpened[entry] = false;
186-
};
187-
}
181+
entry.DropDownOpened += (sender, args) =>
182+
{
183+
isDropDownOpened[entry] = true;
184+
};
185+
entry.DropDownClosed += (sender, args) =>
186+
{
187+
isDropDownOpened[entry] = false;
188+
};
189+
}
188190

189-
ac7decrypt = new AC7Decrypt();
191+
ac7decrypt = new AC7Decrypt();
190192

191-
UpdateRPC();
193+
UpdateRPC();
194+
}
195+
catch (Exception ex)
196+
{
197+
MessageBox.Show("An error occured while initializing!\n" + ex.GetType() + ": " + ex.Message + "\n\nUAssetGUI will now close.", "UAssetGUI");
198+
Environment.Exit(1); // kill the process
199+
}
192200
}
193201

194202
private static Dictionary<ToolStripItem, bool> isDropDownOpened = new Dictionary<ToolStripItem, bool>();

0 commit comments

Comments
 (0)