Skip to content

Commit

Permalink
[AutoUpdater] Remove references to Program Files. Check for existing …
Browse files Browse the repository at this point in the history
…installation directory from Registry to use as target destination.
Soapwood committed Aug 7, 2024

Verified

This commit was signed with the committer’s verified signature.
dimbleby David Hotham
1 parent 369c9fc commit 3c42894
Showing 4 changed files with 55 additions and 3 deletions.
45 changes: 45 additions & 0 deletions VXAutoUpdater/Core/RegistryInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Microsoft.Win32;

namespace VXMusicDesktop.Core;

public class RegistryInterface
{
private static readonly string VxMusicInstallPathRootKey = "{{VXMUSIC_INSTALL_PATH_ROOT}}";

private static readonly string SteamRegistryValue = "SteamPath";
private static readonly string SteamRegistryKey = @"HKEY_CURRENT_USER\Software\Valve\Steam";

private const string VX_MUSIC_REGISTRY_VALUE = "InstallPath";
private const string VX_MUSIC_DESKTOP_EXECUTABLE_REGISTRY_VALUE = "Executable";
private const string VX_MUSIC_REGISTRY_KEY = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VirtualXtensions\VXMusic";

public static string? VxMusicInstallPath;
public static string? VxMusicDesktopExecutablePath;

public static void GetExistingVXMusicInstallationPath()
{
VxMusicInstallPath = GetRegistryEntry(VX_MUSIC_REGISTRY_KEY, VX_MUSIC_REGISTRY_VALUE);
Console.WriteLine($"VxMusicInstallPath: {VxMusicInstallPath}");

VxMusicDesktopExecutablePath = GetRegistryEntry(VX_MUSIC_REGISTRY_KEY, VX_MUSIC_DESKTOP_EXECUTABLE_REGISTRY_VALUE);
Console.WriteLine($"VxMusicDesktopExecutablePath: {VxMusicDesktopExecutablePath}");
}

private static string GetRegistryEntry(string registryKey, string registryValue)
{
try
{
// Try to read the Steam installation path from the registry
object value = Registry.GetValue(registryKey, registryValue, null);

Check warning on line 34 in VXAutoUpdater/Core/RegistryInterface.cs

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
if (value != null) return value.ToString();

Check warning on line 35 in VXAutoUpdater/Core/RegistryInterface.cs

GitHub Actions / build

Possible null reference return.
}
catch (Exception ex)
{
Console.WriteLine($"Error accessing registry entry {registryKey}: {registryValue}.");
Console.WriteLine(ex.Message);
}

return "";
}
}
8 changes: 7 additions & 1 deletion VXAutoUpdater/Core/VXMusicAutoUpdater.cs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
using Octokit;
using VXAutoUpdaterDesktop;
using System.Windows;
using VXMusicDesktop.Core;
using Application = System.Windows.Application;
using FileMode = System.IO.FileMode;
using ProductHeaderValue = Octokit.ProductHeaderValue;
@@ -42,6 +43,11 @@ public VXMusicAutoUpdater(string repositoryOwner, string repositoryName, string
AutoUpdaterAppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualXtensions", "VXMusic", "AutoUpdater");
OverlayAppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualXtensions", "VXMusic", "Overlay");

RegistryInterface.GetExistingVXMusicInstallationPath();

if (!Path.Exists(RegistryInterface.VxMusicInstallPath))
UpdateMessageInMainWindow("WARNING: Current VXMusic installation not found. Please try re-installing.");

if (!Path.Exists(AutoUpdaterAppDataPath))
Directory.CreateDirectory(AutoUpdaterAppDataPath);

@@ -85,7 +91,7 @@ public static async Task UpdateApplicationBasedOnRequestedVersion(string branch,

// Call the method to extract and replace files
string extractPath = Path.Combine(_autoUpdater.AutoUpdaterAppDataPath, $"{_autoUpdater.UpdateZipName.Split(".zip")[0]}");
string targetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "VXMusic");
string targetPath = Path.Combine(RegistryInterface.VxMusicInstallPath);

_autoUpdater.ExtractAndReplaceVxInstallation(_autoUpdater.UpdateZipPath, extractPath, targetPath);

3 changes: 2 additions & 1 deletion VXMusicDesktop/Update/VXMusicUpdateHandler.cs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using System.Windows;
using Microsoft.Extensions.Logging;
using Octokit;
using VXMusicDesktop.Core;

namespace VXMusicDesktop.Update;

@@ -98,7 +99,7 @@ public async Task<bool> IsUpdateAvailableOnStableBranch()
public void LaunchVxMusicUpdater()
{
// Prepare AppData folder for temporary copy of VXAutoUpdater
string autoUpdaterPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "VXMusic", "VXAutoUpdater");
string autoUpdaterPath = Path.Combine(RegistryInterface.VxMusicInstallPath, "VXAutoUpdater");
string temporaryFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualXtensions", "VXMusic", "AutoUpdaterTemp");

CopyDirectory(autoUpdaterPath, temporaryFolder);
2 changes: 1 addition & 1 deletion VXMusicDesktop/VXMusicDesktop.csproj
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<PackageIcon>VXLogo.png</PackageIcon>
<ApplicationIcon>Images\VXLogoIcon.ico</ApplicationIcon>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<Version>0.6.5.6</Version>
<Version>0.6.5.7</Version>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Title>VXMusicDesktop</Title>
<Authors>VirtualXtensions</Authors>

0 comments on commit 3c42894

Please sign in to comment.