Skip to content

Commit

Permalink
Respecc WOW6432Node
Browse files Browse the repository at this point in the history
  • Loading branch information
xparadoxical committed Sep 16, 2020
1 parent e63baf2 commit 3d757a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions IntelOrca.PvZTools/PvZProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class PvZProcess : AppProcess
{
internal PvZProcess()
{
(string? path, bool goty) = GetInstallLocation(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); //as 32bit
(string? path, bool goty) = GetInstallLocation(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", wow6432node: true);
if (path is null)
{
(path, goty) = GetInstallLocation(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); //as 64bit
(path, goty) = GetInstallLocation(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", wow6432node: false);
if (path is null) throw new NullReferenceException("Could not find a Plants vs. Zombies installation.");
}

Expand All @@ -23,19 +23,20 @@ internal PvZProcess()
}

readonly string[] displayNames = new string[] { "Plants vs. Zombies", "Plants vs. Zombies SDR" };
readonly string goty = "Plants vs. Zombies: Game of the Year";
readonly string gotyName = "Plants vs. Zombies: Game of the Year";

private (string? path, bool goty) GetInstallLocation(string regkey)
private (string? path, bool goty) GetInstallLocation(string regkey, bool wow6432node)
{
using RegistryKey installed = Registry.LocalMachine.OpenSubKey(regkey);
using RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, wow6432node ? RegistryView.Registry32 : RegistryView.Registry64);
using RegistryKey installed = hklm.OpenSubKey(regkey);
foreach (string id in installed.GetSubKeyNames())
{
using RegistryKey program = installed.OpenSubKey(id);
string displayName = (string)program.GetValue("DisplayName");

if (displayNames.Contains(displayName))
return ((string)program.GetValue("InstallLocation") ?? Path.GetDirectoryName((string)program.GetValue("DisplayIcon")), false);
else if (goty == (string)program.GetValue("DisplayName"))
else if (gotyName == (string)program.GetValue("DisplayName"))
return ((string)program.GetValue("InstallLocation") ?? Path.GetDirectoryName((string)program.GetValue("DisplayIcon")), true);
}

Expand Down
2 changes: 2 additions & 0 deletions IntelOrca.PvZTools/PvZTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<ErrorReport>prompt</ErrorReport>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -38,6 +39,7 @@
<ErrorReport>prompt</ErrorReport>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down

0 comments on commit 3d757a3

Please sign in to comment.