Skip to content

Commit

Permalink
Merge uninstaller back into Olympus.Sharp.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Jan 26, 2025
1 parent 4c0429b commit 909eefb
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 483 deletions.
17 changes: 0 additions & 17 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,6 @@ steps:
arguments: '--configuration Release'


# Build uninstaller-winforms.
- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables.agentArch, 'windows'))
displayName: 'Build: dotnet: restore uninstaller-winforms'
inputs:
command: 'restore'
projects: 'uninstaller-winforms/*.csproj'

- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables.agentArch, 'windows'))
displayName: 'Build: dotnet: build uninstaller-winforms'
inputs:
command: 'build'
projects: 'uninstaller-winforms/*.csproj'
arguments: '--configuration Release'

# Create a dummy dir for platforms which don't use prebuilt LÖVE.
- task: CmdLine@2
condition: and(succeeded(), eq(variables.loveZIP, ''))
Expand Down Expand Up @@ -340,7 +324,6 @@ steps:
Remove-Item -Path love/lovec.exe -Force
Move-Item -Path love/love.exe -Destination love/main.exe
New-Item -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY/main -ItemType Directory
Copy-Item -Path uninstaller-winforms/bin/Release/net452/Olympus.exe -Destination love/uninstall.exe
Compress-Archive -Path love/* -DestinationPath $env:BUILD_ARTIFACTSTAGINGDIRECTORY/main/dist.zip -Force
New-Item -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY/update -ItemType Directory
New-Item -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY/platform-update -ItemType Directory
Expand Down
3 changes: 1 addition & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ and only contains the latest changes.
Its purpose is to be shown in Olympus when updating.

#changelog#
∙ Updated Olympus.Sharp to .NET 8 to fix various issues with the .NET Framework version
∙ Fixed "popen failed" error messages being truncated to the first letter
∙ Reintegrate the Windows uninstaller in Olympus.Sharp instead of having a separate uninstall.exe
10 changes: 6 additions & 4 deletions sharp/CmdWin32AppAdd.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if WIN32
using Microsoft.Win32;
using System.IO;
using System.Reflection;

namespace Olympus {
public class CmdWin32AppAdd : Cmd<string, string, string> {
Expand All @@ -11,7 +12,8 @@ public override string Run(string exepath, string version) {
return null;

DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(exepath));
string uninstallerPath = Path.GetDirectoryName(exepath) + @"\uninstall.exe";
string selfPath = Assembly.GetExecutingAssembly().Location;
selfPath = Path.Combine(Path.GetDirectoryName(selfPath), "Olympus.Sharp.exe");

key.SetValue("DisplayName", "Olympus");
key.SetValue("Publisher", "Everest Team");
Expand All @@ -21,8 +23,8 @@ public override string Run(string exepath, string version) {
key.SetValue("InstallLocation", dir);
key.SetValue("InstallDate", dir.CreationTime.ToString("yyyyMMdd"));
key.SetValue("EstimatedSize", (int) (GetDirectorySize(dir) / 1024));
key.SetValue("UninstallString", $"\"{uninstallerPath}\"");
key.SetValue("QuietUninstallString", $"\"{uninstallerPath}\" --quiet");
key.SetValue("UninstallString", $"\"{selfPath}\" --uninstall");
key.SetValue("QuietUninstallString", $"\"{selfPath}\" --uninstall --quiet");
key.SetValue("NoModify", 1);
key.SetValue("NoRepair", 1);

Expand All @@ -44,4 +46,4 @@ public static long GetDirectorySize(DirectoryInfo dir) {

}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
using Microsoft.Win32;
#if WIN32
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace Olympus {
public class CmdWin32AppUninstall {
public string Run(bool quiet) {
if (!quiet) {
try {
Application.EnableVisualStyles();
} catch {
}
}
public class CmdWin32AppUninstall : Cmd<bool, string> {
[DllImport("user32")]
private static extern int MessageBoxW(
IntPtr hWnd,
[MarshalAs(UnmanagedType.LPWStr)] string text,
[MarshalAs(UnmanagedType.LPWStr)] string caption,
uint type
);

private static void showMessage(string message) {
MessageBoxW(IntPtr.Zero, message, "Olympus", 0 /* MB_OK */);
}
private static bool askForConfirmation(string message) {
return MessageBoxW(IntPtr.Zero, message, "Olympus", 4 /* MB_YESNO */) == 6 /* IDYES */;
}

public override string Run(bool quiet) {
string selfPath = Assembly.GetExecutingAssembly().Location;

string root = Environment.GetEnvironmentVariable("OLYMPUS_ROOT");
Expand All @@ -28,56 +36,64 @@ public string Run(bool quiet) {
!File.Exists(Path.Combine(root, "love.dll")) ||
!Directory.Exists(Path.Combine(root, "sharp"))) {
if (!quiet)
MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't verify the main folder.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
showMessage("The Olympus uninstaller has encountered an error:\nCan't verify the main folder.\n\nPlease delete %AppData%/Olympus manually.");
return null;
}

if (selfPath.StartsWith(root)) {
string tmpDir = Path.Combine(Path.GetTempPath(), "Olympus.Uninstall");
string tmp = Path.Combine(tmpDir, "uninstall.exe");
string tmp = Path.Combine(tmpDir, "Olympus.Sharp.exe");
try {
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
string tmpDep = Path.Combine(tmpDir, "MonoMod.Utils.dll");
if (File.Exists(tmpDep))
File.Delete(tmpDep);
File.Copy(Path.Combine(Path.GetDirectoryName(selfPath), "MonoMod.Utils.dll"), tmpDep);
if (File.Exists(tmp))
File.Delete(tmp);
File.Copy(selfPath, tmp);
} catch {
}
catch {
if (!quiet)
MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't copy the uninstaller into %TMP%.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
showMessage("The Olympus uninstaller has encountered an error:\nCan't copy the uninstaller into %TMP%.\n\nPlease delete %AppData%/Olympus manually.");
return null;
}

Environment.SetEnvironmentVariable("OLYMPUS_ROOT", root);

Process process = new Process();
process.StartInfo.FileName = tmp;
process.StartInfo.Arguments = quiet ? " --quiet" : "";
process.StartInfo.Arguments = "--uninstall" + (quiet ? " --quiet" : "");
Environment.CurrentDirectory = process.StartInfo.WorkingDirectory = tmpDir;
process.Start();
return null;
}

if (!quiet && MessageBox.Show($"Do you want to uninstall Olympus from the following folder?\n{root}\n\nEverest and all your mods will stay installed.", "Olympus", MessageBoxButtons.YesNo) != DialogResult.Yes)
if (!quiet && !askForConfirmation($"Do you want to uninstall Olympus from the following folder?\n{root}\n\nEverest and all your mods will stay installed."))
return null;

try {
Directory.Delete(root, true);
} catch {
}
catch {
if (!quiet)
MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't delete the Olympus folder.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
showMessage("The Olympus uninstaller has encountered an error:\nCan't delete the Olympus folder.\n\nPlease delete %AppData%/Olympus manually.");
return null;
}

try {
using (RegistryKey key = Win32RegHelper.OpenOrCreateKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall", true))
key?.DeleteSubKeyTree("Olympus");
} catch {
}
catch {
}

if (!quiet)
MessageBox.Show("Olympus was uninstalled successfully.", "Olympus", MessageBoxButtons.OK);
showMessage("Olympus was uninstalled successfully.");

return null;
}
}
}
#endif
4 changes: 2 additions & 2 deletions sharp/Olympus.Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<ApplicationIcon />
<StartupObject />
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishTrimmed>true</PublishTrimmed>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>

<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('win'))">
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<DefineConstants>WIN32</DefineConstants>
</PropertyGroup>

Expand Down
7 changes: 7 additions & 0 deletions sharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public static void Main(string[] args) {
// Enable TLS 1.2 to fix connecting to GitHub.
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

#if WIN32
if (args.Length >= 1 && args[0] == "--uninstall") {
new CmdWin32AppUninstall().Run(args.Length >= 2 && args[1] == "--quiet");
return;
}
#endif

Process parentProc = null;
int parentProcID = 0;

Expand Down
Loading

0 comments on commit 909eefb

Please sign in to comment.