Skip to content

Commit

Permalink
Added support for "Add or remove programs"
Browse files Browse the repository at this point in the history
  • Loading branch information
Athlon007 committed May 6, 2021
1 parent 893736d commit 1442b90
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 23 deletions.
14 changes: 14 additions & 0 deletions MSCLoader/Installer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 1.0.1 (08.04.2021)

### Added

- Mod Loader Pro will now be listed in "Add or remove programs" list in Windows settings

### Bug Fixes

- Fixed the custom Mods folder location setting sometimes not being applied as it should

## 1.0 (30.04.2021)

- Initial release

## GM-0.99.5

### Bug Fixes
Expand Down
70 changes: 70 additions & 0 deletions MSCLoader/Installer/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.IO.Compression;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Win32;
using System.Reflection;

namespace Installer
{
Expand Down Expand Up @@ -189,6 +191,8 @@ private void Client_DownloadDebuggerCompleted(object sender, System.ComponentMod
UnpackZip(DebuggerPath, false, Installer.Instance.UserModsFolderName());
}

long size;

async void UnpackZip(string pathToZip, bool goToEnd = false, string toFolder = "")
{
Installer.Instance.UpdateStatus(100, "Extracting...");
Expand Down Expand Up @@ -222,12 +226,19 @@ await Task.Run(() =>
f.ExtractToFile(path, true);
});
stage++;
size += new FileInfo(path).Length;
}

file.Dispose();
}
downloadFinished = true;

Installer.Instance.UpdateStatus(100, "Creating registry entries...");
await Task.Run(() =>
{
CreateUninstaller();
});

if (goToEnd)
Installer.Instance.TabEnd();
}
Expand All @@ -246,5 +257,64 @@ internal void DeleteTemporaryFiles()

}
}

const string UninstallGuid = "{ef4c06bc-ec46-4bbb-9250-6fc5a25323bf}";

private void CreateUninstaller()
{
using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
{
if (parent == null)
{
throw new Exception("Uninstall registry key not found.");
}
try
{
RegistryKey key = null;

try
{
string guidText = UninstallGuid;
key = parent.OpenSubKey(guidText, true) ??
parent.CreateSubKey(guidText);

if (key == null)
{
throw new Exception(String.Format("Unable to create uninstaller."));
}

Assembly asm = GetType().Assembly;
Version v = Assembly.LoadFrom(Path.Combine(Installer.Instance.MscPath, "mysummercar_Data/Managed/MSCLoader.dll")).GetName().Version;
string exe = Path.Combine(Installer.Instance.MscPath, "Uninstaller.exe").Replace("/", "\\");


key.SetValue("DisplayName", "MSC Mod Loader Pro");
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("Publisher", "Mod Loader Pro Team");
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayVersion", v.ToString());
key.SetValue("URLInfoAbout", "http://mscloaderpro.github.io/");
key.SetValue("Contact", "");
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("UninstallString", $"\"{exe}\"");
key.SetValue("EstimatedSize", size / 1000, RegistryValueKind.DWord);
}
finally
{
if (key != null)
{
key.Close();
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. The service is fully installed but can only be uninstalled manually through the command line.",
ex);
}
}
}
}
}
14 changes: 10 additions & 4 deletions MSCLoader/Installer/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,18 @@ void CreateFolders()
Directory.CreateDirectory(Path.Combine(modsPath, "Assets"));
Directory.CreateDirectory(Path.Combine(modsPath, "References"));
Directory.CreateDirectory(Path.Combine(modsPath, "Settings"));
}

string configFile = Path.Combine(MscPath, "ModLoaderSettings.ini");
string input = File.ReadAllText(configFile);
input = input.Replace("ModsFolderPath=Mods", "ModsFolderPath=" + txtModsFolderName.Text);
File.WriteAllText(configFile, input);
string configFile = Path.Combine(MscPath, "ModLoaderSettings.ini");
string[] input = File.ReadAllText(configFile).Split('\n');
for (int i = 0; i < input.Length; i++)
{
if (input[i].Contains("ModsFolderPath="))
{
input[i] = "ModsFolderPath=" + txtModsFolderName.Text;
}
}
File.WriteAllText(configFile, string.Join("\n", input));
}

internal void SetVersionString(string s)
Expand Down
4 changes: 2 additions & 2 deletions MSCLoader/Installer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
1 change: 1 addition & 0 deletions MSCLoader/MSCLoader/Resources/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 1.0.7
Addressed an issue related with objects using PartMagnet being not detacheable, if the object has been disabled
Fixed music not playing after quitting from game to the main menu (issue #5)
CoolUpdater: Added info page, if CoolUpdater is open by the user
Uninstaller: Added support for launching the Uninstaller via "Add or remove programs"

Version 1.0.6
Fixed UI scaling on ultrawide resolutions.
Expand Down
30 changes: 15 additions & 15 deletions MSCLoader/Uninstaller/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions MSCLoader/Uninstaller/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public Form1()
{
InitializeComponent();

Version version = Assembly.GetExecutingAssembly().GetName().Version;
labVer.Text = version.Major + "." + version.Minor;
if (version.Build != 0)
{
labVer.Text += "." + version.Build;
}

byte[] fontData = Properties.Resources.FugazOne_Regular;
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
Expand Down Expand Up @@ -190,6 +197,9 @@ private void button2_Click(object sender, EventArgs e)
Environment.Exit(0);
}

const string UninstallGuid = "{ef4c06bc-ec46-4bbb-9250-6fc5a25323bf}";
bool uninstalled;

private void button1_Click(object sender, EventArgs e)
{
string modsFolder = GetModFolderPath();
Expand All @@ -213,6 +223,23 @@ private void button1_Click(object sender, EventArgs e)
labQuestion.Text = "Mod Loader Pro has been succesfully removed from your system.";
labQuestion.SetToCenter(this);
chkDebugger.Visible = false;

using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
{
try
{
parent.DeleteSubKeyTree(UninstallGuid);
}
catch (Exception ex)
{
throw new Exception(
"An error occurred while trying to remove the uninstaller registry value.",
ex);
}
}

uninstalled = true;
}

void DeleteIfExists(string path)
Expand Down Expand Up @@ -242,6 +269,23 @@ string GetModFolderPath()

private void btnQuit_Click(object sender, EventArgs e)
{
if (uninstalled)
{
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C \"\" del Uninstaller.exe",
WorkingDirectory = Directory.GetCurrentDirectory(),
UseShellExecute = false,
CreateNoWindow = true
}
};

p.Start();
}

Environment.Exit(0);
}
}
Expand Down
3 changes: 3 additions & 0 deletions MSCLoader/Uninstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ static class Program
[STAThread]
static void Main()
{
string myAppPath = System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Uninstaller.exe", "");
System.IO.Directory.SetCurrentDirectory(myAppPath);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Expand Down
4 changes: 2 additions & 2 deletions MSCLoader/Uninstaller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

0 comments on commit 1442b90

Please sign in to comment.