Skip to content

Commit d640267

Browse files
committed
ModAPI.Common: add safety to PathDialogs functions
1 parent 10f3805 commit d640267

File tree

1 file changed

+65
-59
lines changed

1 file changed

+65
-59
lines changed

ModAPI.Common/PathDialogs.cs

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Threading;
22
using System.IO;
33
using System.Windows.Forms;
4+
using System;
45

56
namespace ModAPI.Common
67
{
@@ -11,43 +12,47 @@ public static string ProcessGalacticAdventures()
1112
{
1213
string path = null;
1314

14-
if (!LauncherSettings.ForceGamePath)
15+
try
1516
{
16-
path = SporePath.GetFromRegistry(SporePath.Game.GalacticAdventures);
17-
}
18-
19-
// for debugging purposes
20-
// path = null;
21-
22-
if (path != null)
23-
{
24-
// move the path to SporebinEP1
25-
path = SporePath.MoveToSporebinEP1(path);
26-
}
17+
if (!LauncherSettings.ForceGamePath)
18+
{
19+
path = SporePath.GetFromRegistry(SporePath.Game.GalacticAdventures);
20+
}
2721

28-
// If we didn't find the path in the registry or was not valid, ask the user
29-
if (path == null || !Directory.Exists(path))
30-
{
22+
if (path != null)
23+
{
24+
// move the path to SporebinEP1
25+
path = SporePath.MoveToSporebinEP1(path);
26+
}
3127

32-
if (path == null)
28+
// If we didn't find the path in the registry or was not valid, ask the user
29+
if (path == null || !Directory.Exists(path))
3330
{
34-
path = LauncherSettings.GamePath;
35-
if (path == null || path.Length == 0)
36-
{
37-
var result = MessageBox.Show(CommonStrings.GalacticAdventuresNotFoundSpecifyManual, CommonStrings.GalacticAdventuresNotFound,
38-
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
3931

40-
if (result == DialogResult.OK)
32+
if (path == null)
33+
{
34+
path = LauncherSettings.GamePath;
35+
if (path == null || path.Length == 0)
4136
{
42-
path = ShowGalacticAdventuresChooserDialog();
37+
var result = MessageBox.Show(CommonStrings.GalacticAdventuresNotFoundSpecifyManual, CommonStrings.GalacticAdventuresNotFound,
38+
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
39+
40+
if (result == DialogResult.OK)
41+
{
42+
path = ShowGalacticAdventuresChooserDialog();
43+
}
4344
}
4445
}
46+
else
47+
{
48+
// move the path to SporebinEP1
49+
path = SporePath.MoveToSporebinEP1(path);
50+
}
4551
}
46-
else
47-
{
48-
// move the path to SporebinEP1
49-
path = SporePath.MoveToSporebinEP1(path);
50-
}
52+
}
53+
catch (Exception)
54+
{
55+
return null;
5156
}
5257

5358
return path;
@@ -58,43 +63,47 @@ public static string ProcessSpore()
5863
{
5964
string path = null;
6065

61-
if (!LauncherSettings.ForceGamePath)
66+
try
6267
{
63-
path = SporePath.GetFromRegistry(SporePath.Game.Spore);
64-
}
65-
66-
// for debugging purposes
67-
// path = null;
68-
69-
if (path != null)
70-
{
71-
// move the path to Sporebin
72-
path = SporePath.MoveToSporebin(path);
73-
}
68+
if (!LauncherSettings.ForceGamePath)
69+
{
70+
path = SporePath.GetFromRegistry(SporePath.Game.Spore);
71+
}
7472

75-
// If we didn't find the path in the registry or was not valid, ask the user
76-
if (path == null || !Directory.Exists(path))
77-
{
73+
if (path != null)
74+
{
75+
// move the path to Sporebin
76+
path = SporePath.MoveToSporebin(path);
77+
}
7878

79-
if (path == null)
79+
// If we didn't find the path in the registry or was not valid, ask the user
80+
if (path == null || !Directory.Exists(path))
8081
{
81-
path = LauncherSettings.GamePath;
82-
if (path == null || path.Length == 0)
83-
{
84-
var result = MessageBox.Show(CommonStrings.SporeNotFoundSpecifyManual, CommonStrings.SporeNotFound,
85-
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
8682

87-
if (result == DialogResult.OK)
83+
if (path == null)
84+
{
85+
path = LauncherSettings.GamePath;
86+
if (path == null || path.Length == 0)
8887
{
89-
path = ShowSporeChooserDialog();
88+
var result = MessageBox.Show(CommonStrings.SporeNotFoundSpecifyManual, CommonStrings.SporeNotFound,
89+
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
90+
91+
if (result == DialogResult.OK)
92+
{
93+
path = ShowSporeChooserDialog();
94+
}
9095
}
9196
}
97+
else
98+
{
99+
// move the path to Sporebin
100+
path = SporePath.MoveToSporebin(path);
101+
}
92102
}
93-
else
94-
{
95-
// move the path to Sporebin
96-
path = SporePath.MoveToSporebin(path);
97-
}
103+
}
104+
catch (Exception)
105+
{
106+
return null;
98107
}
99108

100109
return path;
@@ -105,9 +114,6 @@ public static string ProcessSteam()
105114
{
106115
string path = SporePath.GetFromRegistry(SporePath.SteamRegistryKeys, new string[] { SporePath.SteamRegistryValue });
107116

108-
// for debugging purposes
109-
// path = null;
110-
111117
if (path != null)
112118
{
113119
// move the path to Steam

0 commit comments

Comments
 (0)