Skip to content

Commit 270549e

Browse files
Fixed Issue with Null Reference Exception with getting Existing MelonLoader Install Version
1 parent dee5303 commit 270549e

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
6. Fixed Issue with not Auto-Creating a Plugins folder.
1616
7. Fixed Issue with not Auto-Creating a Mods folder.
1717
8. Fixed Issue with not Auto-Creating a UserData folder.
18+
9. Fixed Issue with Null Reference Exception with getting Existing MelonLoader Install Version.
1819

1920
---
2021

MainForm.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,33 +119,40 @@ private void CheckUnityGame()
119119
string folder_path = Path.Combine(Path.GetDirectoryName(Automated_UnityGame_Display.Text), "MelonLoader");
120120
string legacy_file_path = Path.Combine(folder_path, "MelonLoader.ModHandler.dll");
121121
string file_path = Path.Combine(folder_path, "MelonLoader.dll");
122-
if (File.Exists(legacy_file_path) || File.Exists(file_path))
123-
{
124-
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo((File.Exists(legacy_file_path) ? legacy_file_path : file_path));
125-
CurrentInstalledVersion = new Version(fileVersionInfo.ProductVersion);
126-
Automated_Install.Size = new Size(206, 44);
127-
ManualZip_Install.Size = new Size(206, 44);
128-
Automated_Uninstall.Visible = true;
129-
ManualZip_Uninstall.Visible = true;
130-
ManualZip_Install.Text = "RE-INSTALL";
131-
Version selected_ver = new Version(Automated_Version_Selection.Text.Substring(1));
132-
int compare_ver = selected_ver.CompareTo(CurrentInstalledVersion);
133-
if (compare_ver < 0)
134-
Automated_Install.Text = "DOWNGRADE";
135-
else if (compare_ver > 0)
136-
Automated_Install.Text = "UPDATE";
137-
else
138-
Automated_Install.Text = "RE-INSTALL";
139-
}
140-
else
122+
if (!File.Exists(legacy_file_path) || !File.Exists(file_path))
141123
{
142124
ManualZip_Install.Text = "INSTALL";
143125
Automated_Install.Text = "INSTALL";
144126
Automated_Install.Size = new Size(419, 44);
145127
ManualZip_Install.Size = new Size(419, 44);
146128
Automated_Uninstall.Visible = false;
147129
ManualZip_Uninstall.Visible = false;
130+
return;
148131
}
132+
string fileversion = null;
133+
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo((File.Exists(legacy_file_path) ? legacy_file_path : file_path));
134+
if (fileVersionInfo != null)
135+
{
136+
fileversion = fileVersionInfo.ProductVersion;
137+
if (string.IsNullOrEmpty(fileversion))
138+
fileversion = fileVersionInfo.FileVersion;
139+
}
140+
if (string.IsNullOrEmpty(fileversion))
141+
fileversion = "0.0.0.0";
142+
CurrentInstalledVersion = new Version(fileversion);
143+
Automated_Install.Size = new Size(206, 44);
144+
ManualZip_Install.Size = new Size(206, 44);
145+
Automated_Uninstall.Visible = true;
146+
ManualZip_Uninstall.Visible = true;
147+
ManualZip_Install.Text = "RE-INSTALL";
148+
Version selected_ver = new Version(Automated_Version_Selection.Text.Substring(1));
149+
int compare_ver = selected_ver.CompareTo(CurrentInstalledVersion);
150+
if (compare_ver < 0)
151+
Automated_Install.Text = "DOWNGRADE";
152+
else if (compare_ver > 0)
153+
Automated_Install.Text = "UPDATE";
154+
else
155+
Automated_Install.Text = "RE-INSTALL";
149156
}
150157

151158
private void ThemeChanged(object sender, EventArgs e)

0 commit comments

Comments
 (0)