Skip to content

Commit 8432a46

Browse files
committed
ModAPI.Common: add caching mechanism to PathDialog functions
1 parent b732287 commit 8432a46

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

ModAPI.Common/PathDialogs.cs

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ namespace ModAPI.Common
88
public static class PathDialogs
99
{
1010
// Returns path to SporebinEP1 or null
11+
private static string _galacticAdventuresPath = null;
1112
public static string ProcessGalacticAdventures()
1213
{
1314
string path = null;
1415

16+
if (_galacticAdventuresPath != null)
17+
{
18+
return _galacticAdventuresPath;
19+
}
20+
1521
try
1622
{
1723
if (!LauncherSettings.ForceGamePath)
@@ -55,14 +61,21 @@ public static string ProcessGalacticAdventures()
5561
return null;
5662
}
5763

58-
return path;
64+
_galacticAdventuresPath = path;
65+
return _galacticAdventuresPath;
5966
}
6067

6168
// Returns path to Sporebin or null
69+
private static string _coreSporePath = null;
6270
public static string ProcessSpore()
6371
{
6472
string path = null;
6573

74+
if (_coreSporePath != null)
75+
{
76+
return _coreSporePath;
77+
}
78+
6679
try
6780
{
6881
if (!LauncherSettings.ForceGamePath)
@@ -106,49 +119,10 @@ public static string ProcessSpore()
106119
return null;
107120
}
108121

109-
return path;
110-
}
111-
112-
// Returns path to Steam or null
113-
public static string ProcessSteam()
114-
{
115-
string path = SporePath.GetFromRegistry(SporePath.SteamRegistryKeys, new string[] { SporePath.SteamRegistryValue });
116-
117-
if (path != null)
118-
{
119-
// move the path to Steam
120-
path = SporePath.MoveToSteam(path);
121-
}
122-
123-
// If we didn't find the path in the registry or was not valid, ask the user
124-
if (path == null || !Directory.Exists(path))
125-
{
126-
127-
if (path == null)
128-
{
129-
path = LauncherSettings.GamePath;
130-
if (path == null || path.Length == 0)
131-
{
132-
var result = MessageBox.Show(CommonStrings.SteamNotFoundSpecifyManual, CommonStrings.SteamNotFound,
133-
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
134-
135-
if (result == DialogResult.OK)
136-
{
137-
path = ShowSteamChooserDialog();
138-
}
139-
}
140-
}
141-
else
142-
{
143-
// move the path to Sporebin
144-
path = SporePath.MoveToSteam(path);
145-
}
146-
}
147-
148-
return path;
122+
_coreSporePath = path;
123+
return _coreSporePath;
149124
}
150125

151-
152126
// -- DIALOGS -- //
153127
private static string ShowGalacticAdventuresChooserDialog()
154128
{

0 commit comments

Comments
 (0)