Skip to content

Commit

Permalink
Unfuck broken DOTNET_ROOT env vars from console.bat script.
Browse files Browse the repository at this point in the history
🤦🤦🤦🤦🤦🤦🤦🤦🤦🤦
  • Loading branch information
PJB3005 committed Oct 21, 2023
1 parent d0f82e1 commit ec6756e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SS14.Launcher.Bootstrap/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;

namespace SS14.Launcher.Bootstrap
{
internal static class Program
{
public static void Main(string[] args)
{
UnfuckDotnetRoot();

var path = typeof(Program).Assembly.Location;
var ourDir = Path.GetDirectoryName(path);
Debug.Assert(ourDir != null);
Expand All @@ -18,5 +21,39 @@ public static void Main(string[] args)
Environment.SetEnvironmentVariable("DOTNET_ROOT", dotnetDir);
Process.Start(new ProcessStartInfo(exeDir));
}

private static void UnfuckDotnetRoot()
{
//
// We ship a simple console.bat script that runs the game with cmd prompt logging,
// in a worst-case of needing logging.
//
// Well it turns out I dared copy paste "SETX" from StackOverflow instead of "SET".
// The former permanently alters the user's registry to set the environment variable
//
// WHY THE FUCK IS THAT SO EASY TO DO???
// AND WHY ARE PEOPLE ON STACKOVERFLOW POSTING SOMETHING SO DANGEROUS WITHOUT ASTERISK???
//
// Anyways, we have to fix our goddamn mess now. Ugh.
// Try to clear that registry key if somebody previously ran console.bat and it corrupted their system.
//

try
{
using var envKey = Registry.CurrentUser.OpenSubKey("Environment", true);
var val = envKey?.GetValue("DOTNET_ROOT");
if (val is not string s)
return;

if (!s.Contains("Space Station 14") && !s.Contains("SS14.Launcher"))
return;

envKey.DeleteValue("DOTNET_ROOT");
}
catch (Exception e)
{
Console.WriteLine($"Error while trying to fix DOTNET_ROOT env var: {e}");
}
}
}
}
1 change: 1 addition & 0 deletions SS14.Launcher.Bootstrap/SS14.Launcher.Bootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TargetFramework>net45</TargetFramework>
<TargetName>Space Station 14 Launcher</TargetName>
<ApplicationIcon>../SS14.Launcher/Assets/icon.ico</ApplicationIcon>
<LangVersion>11</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit ec6756e

Please sign in to comment.