mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Finished basic implementation of uninstalling legacy versions.
This commit is contained in:
@@ -27,5 +27,34 @@ namespace CustomActions
|
||||
session.Log("End IsKBInstalled");
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult UninstallLegacyVersion(Session session)
|
||||
{
|
||||
session.Log("Begin UninstallLegacyVersion");
|
||||
UninstallNSISVersions uninstaller = new UninstallNSISVersions();
|
||||
string uninstallString = uninstaller.GetLegacyUninstallString();
|
||||
uninstaller.UninstallLegacyVersion();
|
||||
session.Log("End UninstallLegacyVersion");
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult IsLegacyVersionInstalled(Session session)
|
||||
{
|
||||
session.Log("Begin IsLegacyVersionInstalled");
|
||||
UninstallNSISVersions uninstaller = new UninstallNSISVersions();
|
||||
if (uninstaller.IsLegacymRemoteNGInstalled())
|
||||
{
|
||||
session["LEGACYVERSIONINSTALLED"] = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
session["LEGACYVERSIONINSTALLED"] = "0";
|
||||
}
|
||||
|
||||
session.Log("End IsLegacyVersionInstalled");
|
||||
return ActionResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -46,6 +47,7 @@
|
||||
<Compile Include="CustomActions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="InstalledWindowsUpdateGatherer.cs" />
|
||||
<Compile Include="UninstallNSISVersions.cs" />
|
||||
<Content Include="CustomAction.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
75
Installer Projects/CustomActions/UninstallNSISVersions.cs
Normal file
75
Installer Projects/CustomActions/UninstallNSISVersions.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace CustomActions
|
||||
{
|
||||
public class UninstallNSISVersions
|
||||
{
|
||||
private const string REGISTRY_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\mRemoteNG";
|
||||
private const string REGISTRY_PATH_Wow6432 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\mRemoteNG";
|
||||
private RegistryKey _activeRegistryPath;
|
||||
|
||||
|
||||
public UninstallNSISVersions()
|
||||
{
|
||||
GetLegacymRemoteNGRegistryKeyPath();
|
||||
}
|
||||
|
||||
public void UninstallLegacyVersion()
|
||||
{
|
||||
if (!IsLegacymRemoteNGInstalled())
|
||||
return;
|
||||
string uninstallString = GetLegacyUninstallString();
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(uninstallString);
|
||||
processStartInfo.UseShellExecute = true;
|
||||
processStartInfo.Arguments = string.Format("_?={0}", uninstallString.Replace("Uninstall.exe", "").Replace(@"""", ""));
|
||||
Process uninstallProcess = Process.Start(processStartInfo);
|
||||
while (uninstallProcess.HasExited == false)
|
||||
{
|
||||
Debug.WriteLine("Waiting for uninstaller to exit");
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLegacymRemoteNGInstalled()
|
||||
{
|
||||
return (_activeRegistryPath != null);
|
||||
}
|
||||
|
||||
public string GetLegacyUninstallString()
|
||||
{
|
||||
if (IsLegacymRemoteNGInstalled())
|
||||
return _activeRegistryPath.GetValue("UninstallString").ToString();
|
||||
return "";
|
||||
}
|
||||
|
||||
private void GetLegacymRemoteNGRegistryKeyPath()
|
||||
{
|
||||
GetUninstallKeyPath();
|
||||
GetUninstallKeyPath6432();
|
||||
}
|
||||
|
||||
private void GetUninstallKeyPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
_activeRegistryPath = Registry.LocalMachine.OpenSubKey(REGISTRY_PATH);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ }
|
||||
}
|
||||
|
||||
private void GetUninstallKeyPath6432()
|
||||
{
|
||||
try
|
||||
{
|
||||
_activeRegistryPath = Registry.LocalMachine.OpenSubKey(REGISTRY_PATH_Wow6432);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
|
||||
<?include $(sys.CURRENTDIR)Includes\Config.wxi?>
|
||||
<Fragment>
|
||||
<CustomAction Id="CheckIfLegacyVersionInstalled" Return="check" Execute="immediate" BinaryKey="CustomActions.CA.dll" DllEntry="IsLegacyVersionInstalled" />
|
||||
</Fragment>
|
||||
<Fragment>
|
||||
<CustomAction Id="UninstallLegacyVersion" Return="check" Execute="immediate" BinaryKey="CustomActions.CA.dll" DllEntry="UninstallLegacyVersion" />
|
||||
</Fragment>
|
||||
</Wix>
|
||||
@@ -27,6 +27,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CustomActions\CheckForInstalledWindowsUpdates.wxs" />
|
||||
<Compile Include="CustomActions\UninstallLegacyVersions.wxs" />
|
||||
<Compile Include="Fragments\FilesFragment.wxs" />
|
||||
<Compile Include="Fragments\DirectoriesFragment.wxs" />
|
||||
<Compile Include="Fragments\MainExeFragment.wxs" />
|
||||
|
||||
@@ -17,13 +17,17 @@
|
||||
<RegistrySearch Id='mRemoteNGRegistry' Type='raw' Root='HKLM' Key='Software\mRemoteNG' Name='InstallDir' />
|
||||
</Property>
|
||||
<Property Id='REQUIREDDOTNETFRAMEWORKVERSION' Value='$(var.RequiredDotNetFrameworkVersion)' />
|
||||
<Property Id='LEGACYVERSIONINSTALLED' Value='0' />
|
||||
<PropertyRef Id="NETFRAMEWORK40FULL" />
|
||||
<PropertyRef Id="WIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED" />
|
||||
<Icon Id="mRemoteNG.ico" SourceFile="Resources\mRemoteNG.ico" />
|
||||
|
||||
<InstallUISequence>
|
||||
<Custom Action="SetRDP80KBValue" After="AppSearch" />
|
||||
<Custom Action="CheckIfRDP80Installed" After="SetRDP80KBValue">NOT Installed AND (VersionNT = 601 OR VersionNT64 = 601)</Custom>
|
||||
<Custom Action="CheckIfRDP80Installed" After="SetRDP80KBValue">(NOT Installed) AND (VersionNT = 601 OR VersionNT64 = 601)</Custom>
|
||||
<LaunchConditions After="SetWIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED" />
|
||||
<Custom Action="CheckIfLegacyVersionInstalled" After="LaunchConditions" />
|
||||
<Custom Action="UninstallLegacyVersion" After="CheckIfLegacyVersionInstalled">(NOT Installed) AND (LEGACYVERSIONINSTALLED = 1)</Custom>
|
||||
</InstallUISequence>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user