Skip to content

Commit 1827870

Browse files
committed
ModAPI.Common: improve GameVersion.cs
1 parent a11fd39 commit 1827870

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

ModAPI.Common/GameVersion.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace ModAPI.Common
1+
using System.IO;
2+
3+
namespace ModAPI.Common
24
{
35
public enum GameVersionType
46
{
@@ -24,9 +26,9 @@ public enum GameVersionType
2426

2527
public static class GameVersion
2628
{
27-
2829

29-
public static int[] ExecutableSizes = {
30+
31+
private static readonly int[] ExecutableSizes = {
3032
/* DISC*/ 24909584,
3133
/* ORIGIN */ 31347984,
3234
/* ORIGIN_P */ 24898224,
@@ -36,7 +38,7 @@ public static class GameVersion
3638
/* GOG_OCT24 */24895536,
3739
/* STEAM_OCT24 */ 25066744};
3840

39-
public static string[] VersionNames = {
41+
private static readonly string[] VersionNames = {
4042
"disk",
4143
"steam_patched", // origin uses the steam_patched one
4244
"steam_patched", // origin uses the steam_patched one
@@ -49,7 +51,7 @@ public static class GameVersion
4951
};
5052

5153
// Origin users download an alternative executable, so it uses a different name
52-
public static string[] ExecutableNames = {
54+
private static readonly string[] ExecutableNames = {
5355
"SporeApp.exe",
5456
"SporeApp_ModAPIFix.exe", // origin uses a different one
5557
"SporeApp_ModAPIFix.exe", // origin uses a different one
@@ -70,39 +72,50 @@ public static bool RequiresModAPIFix(GameVersionType versionType)
7072

7173
public static GameVersionType DetectVersion(string path)
7274
{
73-
if (path == null)
75+
if (!string.IsNullOrEmpty(path))
7476
{
75-
return GameVersionType.None;
76-
}
77-
var length = new System.IO.FileInfo(path).Length;
77+
var length = new FileInfo(path).Length;
7878

79-
for (int i = 0; i < ExecutableSizes.Length; i++)
80-
{
81-
if (length == ExecutableSizes[i])
79+
for (int i = 0; i < ExecutableSizes.Length; i++)
8280
{
83-
return (GameVersionType)i;
81+
if (length == ExecutableSizes[i])
82+
{
83+
return (GameVersionType)i;
84+
}
8485
}
8586
}
8687

8788
return GameVersionType.None;
8889
}
8990

91+
public static string GetVersionName(GameVersionType type)
92+
{
93+
return VersionNames[(int)type];
94+
}
95+
96+
public static string GetExecutableFileName(GameVersionType type)
97+
{
98+
return ExecutableNames[(int)type];
99+
}
100+
90101
public static string GetNewDLLName(GameVersionType type)
91102
{
92103
if (type == GameVersionType.Disc)
104+
{
93105
return "SporeModAPI.disk.dll";
94-
else if ((type == GameVersionType.Origin) ||
106+
}
107+
else if ((type == GameVersionType.Origin) ||
95108
(type == GameVersionType.Origin_Patched) ||
96-
(type == GameVersionType.EA_Oct24) ||
97-
(type == GameVersionType.Steam_Patched) ||
98-
(type == GameVersionType.GoG_Oct24) ||
109+
(type == GameVersionType.EA_Oct24) ||
110+
(type == GameVersionType.Steam_Patched) ||
111+
(type == GameVersionType.GoG_Oct24) ||
99112
(type == GameVersionType.Steam_Oct24))
113+
{
100114
return "SporeModAPI.march2017.dll";
115+
}
101116
else
102117
{
103-
System.Windows.Forms.MessageBox.Show("Your current Spore game version is not compatible with this Launcher Kit version. If you downloaded the game from EA App, Steam, or GOG, please update to version 3.1.0.29 to proceed. If you're using a higher version of Spore, please see https://launcherkit.sporecommunity.com/support.", "Unsupported Game Version");
104-
System.Diagnostics.Process.GetCurrentProcess().Kill();
105-
return string.Empty;
118+
return null;
106119
}
107120
}
108121
}

Spore ModAPI Launcher/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void Execute()
110110
}
111111

112112
// get the correct executable path
113-
this.ExecutablePath = Path.Combine(this.SporebinPath, GameVersion.ExecutableNames[(int)this.ExecutableType]);
113+
this.ExecutablePath = Path.Combine(this.SporebinPath, GameVersion.GetExecutableFileName(this.ExecutableType));
114114
if (!File.Exists(this.ExecutablePath))
115115
{
116116
// the file might only not exist in Origin (since Origin users will use a different executable compatible with ModAPI)
@@ -154,7 +154,7 @@ void Execute()
154154
}
155155
}
156156

157-
string dllEnding = GameVersion.VersionNames[(int)this.ExecutableType];
157+
string dllEnding = GameVersion.GetVersionName(this.ExecutableType);
158158
if (dllEnding == null)
159159
{
160160
MessageBox.Show(Strings.VersionNotDetected, CommonStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);

0 commit comments

Comments
 (0)