diff --git a/LegacyInstaller/MainWindow.xaml b/LegacyInstaller/MainWindow.xaml
index 829db3d..9a96af5 100644
--- a/LegacyInstaller/MainWindow.xaml
+++ b/LegacyInstaller/MainWindow.xaml
@@ -1,26 +1,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LegacyInstaller/MainWindow.xaml.cs b/LegacyInstaller/MainWindow.xaml.cs
index 1c0a962..34bc82d 100644
--- a/LegacyInstaller/MainWindow.xaml.cs
+++ b/LegacyInstaller/MainWindow.xaml.cs
@@ -1,295 +1,295 @@
-using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Reflection;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-
-namespace LegacyInstaller
-{
- public partial class MainWindow : Window
- {
- public static Label downloadInfoLabelObject;
- private const string VersionsResourcePath = "LegacyInstaller.BSVersions.json";
- private const string LaunchFileResourcePath = "LegacyInstaller.LaunchBS.bat";
-
- public List Versions { get; set; } = new List();
- public Version SelectedVersion { get; private set; }
-
- public string BSInstallDir { get; private set; }
- public string SelectedVersionInstallDir => BSInstallDir != null && SelectedVersion != null ? $"{BSInstallDir} {SelectedVersion.BSVersion}" : null;
-
- private SteamProcess _steamProcess = null;
- public MainWindow()
- {
- InitializeComponent();
- var bsVersionsStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(VersionsResourcePath);
- string versionList = new StreamReader(bsVersionsStream).ReadToEnd();
- Versions = JsonConvert.DeserializeObject>(versionList);
- AddToCombo(Versions.ToArray(), versionDropdown);
-
- var detectedBSPath = Utilities.DetectBeatSaberInstallPath();
- if (detectedBSPath != null)
- {
- BSInstallDir = (string)detectedBSPath;
- bsPathTextBox.Text = (string)detectedBSPath;
- }
-
- var detectedSteamPath = Utilities.DetectSteamInstallPath();
- if (detectedSteamPath != null)
- {
- steamPathTextBox.Text = (string)detectedSteamPath;
- _steamProcess = new SteamProcess((string)detectedSteamPath);
- }
-
- RefreshUI(true);
- Task.Run(RefreshInternal);
- }
-
- public void AddToCombo(Array array, ComboBox c)
- {
- foreach (var a in array)
- {
- c.Items.Add(a);
- }
- }
- private void RefreshUI(bool idle = true)
- {
- versionDropdown.IsEnabled = idle;
- bsPathTextBox.IsEnabled = idle;
- bsPathBrowseButton.IsEnabled = idle;
- steamPathTextBox.IsEnabled = idle;
- steamPathBrowseButton.IsEnabled = idle;
-
- if (!idle)
- installButton.IsEnabled = false;
- else
- {
- if (_steamProcess != null && BSInstallDir != null && _steamProcess.CurrentUserId != 0 && _steamProcess.Process != null)
- {
- installButton.IsEnabled = true;
-
- if (SelectedVersionInstallDir != null && Directory.Exists(SelectedVersionInstallDir))
- {
- var steamShortcutExists = _steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}");
- installButton.Content = steamShortcutExists ? "Uninstall" : "Add To Steam";
- installStateLabel.Content = steamShortcutExists ? "Already Installed" : "(Already Installed)";
-
- }
- else
- {
- installButton.Content = "Install";
- installStateLabel.Content = "";
- }
- }
- else
- {
- installStateLabel.Content = "";
- installButton.IsEnabled = false;
- }
-
- var labelText = "";
- if (_steamProcess == null)
- labelText += "Please set your Steam install directory.\n";
- if (BSInstallDir == null)
- labelText += "Please set your Beat Saber install directory.\n";
- if (_steamProcess != null && (_steamProcess.CurrentUserId == 0 || _steamProcess.Process == null))
- labelText += "Please log into Steam.\n";
- downloadInfoLabelObject.Content = labelText;
- }
- }
- private async Task RefreshInternal()
- {
- if (_steamProcess == null || BSInstallDir == null)
- return;
-
- await _steamProcess.WaitForMainWindow();
- this.Dispatcher.Invoke((Action)delegate { RefreshUI(); });
-
- var currentLaunchBSChecksum = Utilities.GenerateStringChecksum(await new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(LaunchFileResourcePath)).ReadToEndAsync());
- foreach (var version in Versions)
- {
- var versionExists = Directory.Exists($"{BSInstallDir} {version.BSVersion}");
- var shortcutExists = _steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {version.BSVersion}");
-
- if (versionExists && !shortcutExists)
- _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {version.BSVersion}", $"{BSInstallDir} {version.BSVersion}", "LaunchBS.bat"));
- if (!versionExists && shortcutExists)
- _steamProcess.Shortcuts.DeleteSteamShortcut($"Beat Saber {version.BSVersion}");
- if (!versionExists)
- continue;
-
- // Restore LaunchBS.bat if it doesnt exist or is old
- var launchBSPath = Path.Combine($"{BSInstallDir} {version.BSVersion}", "LaunchBS.bat");
- if (!File.Exists(launchBSPath) || currentLaunchBSChecksum != Utilities.GenerateStringChecksum(File.ReadAllText(launchBSPath)))
- await CopyLaunchFileTo($"{BSInstallDir} {version.BSVersion}");
- }
-
- if (_steamProcess.Shortcuts.HasChanged)
- await RestartSteam();
- }
- private async void StealFocus(int delay)
- {
- await Task.Delay(delay);
- await Task.Run(() => this.Dispatcher.Invoke((Action)delegate
- {
- this.Topmost = true;
- this.Topmost = false;
- this.Activate();
- }));
- }
-
- private async Task RestartSteam(string openTo = null)
- {
- this.Dispatcher.Invoke((Action)delegate
- {
- installStateLabel.Content = "Restarting Steam...";
- downloadInfoLabel.Content = "Waiting for Steam login...";
- RefreshUI(false);
- });
- await _steamProcess.Restart(openTo);
- this.Dispatcher.Invoke((Action)delegate
- {
- installStateLabel.Content = "Done!";
- downloadInfoLabel.Content = "";
- RefreshUI(true);
- });
- }
-
-
- private void bsPathBrowseButton_Click(object sender, RoutedEventArgs e)
- {
- var dialog = new System.Windows.Forms.FolderBrowserDialog();
- if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
- return;
-
- bsPathTextBox.Text = dialog.SelectedPath;
- if (bsPathTextBox.Text != null && Directory.Exists(bsPathTextBox.Text))
- BSInstallDir = bsPathTextBox.Text;
- else
- BSInstallDir = null;
- }
-
- private void bsPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (bsPathTextBox.Text != null && Directory.Exists(bsPathTextBox.Text))
- {
- BSInstallDir = bsPathTextBox.Text;
- RefreshUI();
- }
- else
- BSInstallDir = null;
- }
-
- private void steamPathBrowseButton_Click(object sender, RoutedEventArgs e)
- {
- var dialog = new System.Windows.Forms.FolderBrowserDialog();
- if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
- return;
-
- steamPathTextBox.Text = dialog.SelectedPath;
- if (steamPathTextBox.Text != null && Directory.Exists(steamPathTextBox.Text))
- _steamProcess = new SteamProcess(steamPathTextBox.Text);
- else
- _steamProcess = null;
- }
-
- private void steamPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (steamPathTextBox.Text != null && Directory.Exists(steamPathTextBox.Text))
- {
- _steamProcess = new SteamProcess(steamPathTextBox.Text);
- RefreshUI();
- }
- else
- _steamProcess = null;
- }
-
-
-
- private void versionDropdown_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
- {
- SelectedVersion = (Version)versionDropdown.SelectedItem;
- }
-
- private void installButton_Click(object sender, RoutedEventArgs e)
- {
- if (Directory.Exists(SelectedVersionInstallDir))
- {
- if (!_steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}"))
- _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {SelectedVersion.BSVersion}", SelectedVersionInstallDir, "LaunchBS.bat"));
- else
- {
- _steamProcess.Shortcuts.DeleteSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}");
- Directory.Delete(SelectedVersionInstallDir, true);
- }
-
- _ = RestartSteam();
- return;
- }
-
- installStateLabel.Content = "Downloading...";
- downloadInfoLabel.Content = "Waiting for download to start...";
-
- _ = InstallVersion(SelectedVersion);
- }
-
- private async Task InstallVersion(Version version)
- {
- // Start download
- StealFocus(500); // Steal focus after download start
- await _steamProcess.Downloader.DownloadDepot(version.ManifestId, FileSystemChanged);
-
- // Copy files
- this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Copying..."; });
- Directory.CreateDirectory(SelectedVersionInstallDir);
- var watcher = new FileSystemWatcher(SelectedVersionInstallDir);
- watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
- watcher.IncludeSubdirectories = true;
- watcher.EnableRaisingEvents = true;
- watcher.Changed += FileSystemChanged;
- await Utilities.CopyDirectory(_steamProcess.Downloader.ContentAppDepotDir, SelectedVersionInstallDir);
-
- // Install to steam
- this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Installing..."; });
- await CopyLaunchFileTo(SelectedVersionInstallDir);
- _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {SelectedVersion.BSVersion}", SelectedVersionInstallDir, "LaunchBS.bat"));
-
- // Restart steam
- var steamAppId = Utilities.GetSteamAppId($"Beat Saber {SelectedVersion.BSVersion}", $"{BSInstallDir} {SelectedVersion.BSVersion}", "LaunchBS.bat");
- await RestartSteam($"steam://nav/games/details/{steamAppId}");
-
- // Enable UI
- this.Dispatcher.Invoke((Action)delegate { RefreshUI(true); });
- }
-
- private void FileSystemChanged(object sender, FileSystemEventArgs e)
- {
- if (!e.FullPath.Contains(_steamProcess.Downloader.ContentAppDepotDir) && !e.FullPath.Contains(SelectedVersionInstallDir))
- return;
-
- this.Dispatcher.Invoke((Action)delegate
- {
- downloadInfoLabel.Content = DateTime.Now.ToString("ffffff") + ": " + e.FullPath.Replace(_steamProcess.Downloader.ContentAppDepotDir, "").Replace(SelectedVersionInstallDir, "");
- });
- }
-
- private async Task CopyLaunchFileTo(string targetDir)
- {
- var filePath = Path.Combine(targetDir, "LaunchBS.bat");
- var fileResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(LaunchFileResourcePath);
- var fileStream = File.Create(filePath);
- fileResourceStream.Seek(0, SeekOrigin.Begin);
- await fileResourceStream.CopyToAsync(fileStream);
- fileStream.Close();
- }
-
- private void downloadInfoLabel_Initialized(object sender, EventArgs e)
- {
- downloadInfoLabelObject = (Label)sender;
- RefreshUI();
- }
- }
-}
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace LegacyInstaller
+{
+ public partial class MainWindow : Window
+ {
+ public static Label downloadInfoLabelObject;
+ private const string VersionsResourcePath = "LegacyInstaller.BSVersions.json";
+ private const string LaunchFileResourcePath = "LegacyInstaller.LaunchBS.bat";
+
+ public List Versions { get; set; } = new List();
+ public Version SelectedVersion { get; private set; }
+
+ public string BSInstallDir { get; private set; }
+ public string SelectedVersionInstallDir => BSInstallDir != null && SelectedVersion != null ? $"{BSInstallDir} {SelectedVersion.BSVersion}" : null;
+
+ private SteamProcess _steamProcess = null;
+ public MainWindow()
+ {
+ InitializeComponent();
+ var bsVersionsStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(VersionsResourcePath);
+ string versionList = new StreamReader(bsVersionsStream).ReadToEnd();
+ Versions = JsonConvert.DeserializeObject>(versionList);
+ AddToCombo(Versions.ToArray(), versionDropdown);
+
+ var detectedBSPath = Utilities.DetectBeatSaberInstallPath();
+ if (detectedBSPath != null)
+ {
+ BSInstallDir = (string)detectedBSPath;
+ bsPathTextBox.Text = (string)detectedBSPath;
+ }
+
+ var detectedSteamPath = Utilities.DetectSteamInstallPath();
+ if (detectedSteamPath != null)
+ {
+ steamPathTextBox.Text = (string)detectedSteamPath;
+ _steamProcess = new SteamProcess((string)detectedSteamPath);
+ }
+
+ RefreshUI(true);
+ Task.Run(RefreshInternal);
+ }
+
+ public void AddToCombo(Array array, ComboBox c)
+ {
+ foreach (var a in array)
+ {
+ c.Items.Add(a);
+ }
+ }
+ private void RefreshUI(bool idle = true)
+ {
+ versionDropdown.IsEnabled = idle;
+ bsPathTextBox.IsEnabled = idle;
+ bsPathBrowseButton.IsEnabled = idle;
+ steamPathTextBox.IsEnabled = idle;
+ steamPathBrowseButton.IsEnabled = idle;
+
+ if (!idle)
+ installButton.IsEnabled = false;
+ else
+ {
+ if (_steamProcess != null && BSInstallDir != null && _steamProcess.CurrentUserId != 0 && _steamProcess.Process != null)
+ {
+ installButton.IsEnabled = true;
+
+ if (SelectedVersionInstallDir != null && Directory.Exists(SelectedVersionInstallDir))
+ {
+ var steamShortcutExists = _steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}");
+ installButton.Content = steamShortcutExists ? "Uninstall" : "Add To Steam";
+ installStateLabel.Content = steamShortcutExists ? "Already Installed" : "(Already Installed)";
+
+ }
+ else
+ {
+ installButton.Content = "Install";
+ installStateLabel.Content = "";
+ }
+ }
+ else
+ {
+ installStateLabel.Content = "";
+ installButton.IsEnabled = false;
+ }
+
+ var labelText = "";
+ if (_steamProcess == null)
+ labelText += "Please set your Steam install directory.\n";
+ if (BSInstallDir == null)
+ labelText += "Please set your Beat Saber install directory.\n";
+ if (_steamProcess != null && (_steamProcess.CurrentUserId == 0 || _steamProcess.Process == null))
+ labelText += "Please log into Steam.\n";
+ downloadInfoLabelObject.Content = labelText;
+ }
+ }
+ private async Task RefreshInternal()
+ {
+ if (_steamProcess == null || BSInstallDir == null)
+ return;
+
+ await _steamProcess.WaitForMainWindow();
+ this.Dispatcher.Invoke((Action)delegate { RefreshUI(); });
+
+ var currentLaunchBSChecksum = Utilities.GenerateStringChecksum(await new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(LaunchFileResourcePath)).ReadToEndAsync());
+ foreach (var version in Versions)
+ {
+ var versionExists = Directory.Exists($"{BSInstallDir} {version.BSVersion}");
+ var shortcutExists = _steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {version.BSVersion}");
+
+ if (versionExists && !shortcutExists)
+ _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {version.BSVersion}", $"{BSInstallDir} {version.BSVersion}", "LaunchBS.bat"));
+ if (!versionExists && shortcutExists)
+ _steamProcess.Shortcuts.DeleteSteamShortcut($"Beat Saber {version.BSVersion}");
+ if (!versionExists)
+ continue;
+
+ // Restore LaunchBS.bat if it doesnt exist or is old
+ var launchBSPath = Path.Combine($"{BSInstallDir} {version.BSVersion}", "LaunchBS.bat");
+ if (!File.Exists(launchBSPath) || currentLaunchBSChecksum != Utilities.GenerateStringChecksum(File.ReadAllText(launchBSPath)))
+ await CopyLaunchFileTo($"{BSInstallDir} {version.BSVersion}");
+ }
+
+ if (_steamProcess.Shortcuts.HasChanged)
+ await RestartSteam();
+ }
+ private async void StealFocus(int delay)
+ {
+ await Task.Delay(delay);
+ await Task.Run(() => this.Dispatcher.Invoke((Action)delegate
+ {
+ this.Topmost = true;
+ this.Topmost = false;
+ this.Activate();
+ }));
+ }
+
+ private async Task RestartSteam(string openTo = null)
+ {
+ this.Dispatcher.Invoke((Action)delegate
+ {
+ installStateLabel.Content = "Restarting Steam...";
+ downloadInfoLabel.Content = "Waiting for Steam login...";
+ RefreshUI(false);
+ });
+ await _steamProcess.Restart(openTo);
+ this.Dispatcher.Invoke((Action)delegate
+ {
+ installStateLabel.Content = "Done!";
+ downloadInfoLabel.Content = "";
+ RefreshUI(true);
+ });
+ }
+
+
+ private void bsPathBrowseButton_Click(object sender, RoutedEventArgs e)
+ {
+ var dialog = new System.Windows.Forms.FolderBrowserDialog();
+ if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
+ return;
+
+ bsPathTextBox.Text = dialog.SelectedPath;
+ if (bsPathTextBox.Text != null && Directory.Exists(bsPathTextBox.Text))
+ BSInstallDir = bsPathTextBox.Text;
+ else
+ BSInstallDir = null;
+ }
+
+ private void bsPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (bsPathTextBox.Text != null && Directory.Exists(bsPathTextBox.Text))
+ {
+ BSInstallDir = bsPathTextBox.Text;
+ RefreshUI();
+ }
+ else
+ BSInstallDir = null;
+ }
+
+ private void steamPathBrowseButton_Click(object sender, RoutedEventArgs e)
+ {
+ var dialog = new System.Windows.Forms.FolderBrowserDialog();
+ if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
+ return;
+
+ steamPathTextBox.Text = dialog.SelectedPath;
+ if (steamPathTextBox.Text != null && Directory.Exists(steamPathTextBox.Text))
+ _steamProcess = new SteamProcess(steamPathTextBox.Text);
+ else
+ _steamProcess = null;
+ }
+
+ private void steamPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (steamPathTextBox.Text != null && Directory.Exists(steamPathTextBox.Text))
+ {
+ _steamProcess = new SteamProcess(steamPathTextBox.Text);
+ RefreshUI();
+ }
+ else
+ _steamProcess = null;
+ }
+
+
+
+ private void versionDropdown_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
+ {
+ SelectedVersion = (Version)versionDropdown.SelectedItem;
+ }
+
+ private void installButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (Directory.Exists(SelectedVersionInstallDir))
+ {
+ if (!_steamProcess.Shortcuts.CheckForSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}"))
+ _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {SelectedVersion.BSVersion}", SelectedVersionInstallDir, "LaunchBS.bat"));
+ else
+ {
+ _steamProcess.Shortcuts.DeleteSteamShortcut($"Beat Saber {SelectedVersion.BSVersion}");
+ Directory.Delete(SelectedVersionInstallDir, true);
+ }
+
+ _ = RestartSteam();
+ return;
+ }
+
+ installStateLabel.Content = "Downloading...";
+ downloadInfoLabel.Content = "Waiting for download to start...";
+
+ _ = InstallVersion(SelectedVersion);
+ }
+
+ private async Task InstallVersion(Version version)
+ {
+ // Start download
+ StealFocus(500); // Steal focus after download start
+ await _steamProcess.Downloader.DownloadDepot(version.ManifestId, FileSystemChanged);
+
+ // Copy files
+ this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Copying..."; });
+ Directory.CreateDirectory(SelectedVersionInstallDir);
+ var watcher = new FileSystemWatcher(SelectedVersionInstallDir);
+ watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
+ watcher.IncludeSubdirectories = true;
+ watcher.EnableRaisingEvents = true;
+ watcher.Changed += FileSystemChanged;
+ await Utilities.CopyDirectory(_steamProcess.Downloader.ContentAppDepotDir, SelectedVersionInstallDir);
+
+ // Install to steam
+ this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Installing..."; });
+ await CopyLaunchFileTo(SelectedVersionInstallDir);
+ _steamProcess.Shortcuts.AddSteamShortcut(new SteamShortcut($"Beat Saber {SelectedVersion.BSVersion}", SelectedVersionInstallDir, "LaunchBS.bat"));
+
+ // Restart steam
+ var steamAppId = Utilities.GetSteamAppId($"Beat Saber {SelectedVersion.BSVersion}", $"{BSInstallDir} {SelectedVersion.BSVersion}", "LaunchBS.bat");
+ await RestartSteam($"steam://nav/games/details/{steamAppId}");
+
+ // Enable UI
+ this.Dispatcher.Invoke((Action)delegate { RefreshUI(true); });
+ }
+
+ private void FileSystemChanged(object sender, FileSystemEventArgs e)
+ {
+ if (!e.FullPath.Contains(_steamProcess.Downloader.ContentAppDepotDir) && !e.FullPath.Contains(SelectedVersionInstallDir))
+ return;
+
+ this.Dispatcher.Invoke((Action)delegate
+ {
+ downloadInfoLabel.Content = DateTime.Now.ToString("ffffff") + ": " + e.FullPath.Replace(_steamProcess.Downloader.ContentAppDepotDir, "").Replace(SelectedVersionInstallDir, "");
+ });
+ }
+
+ private async Task CopyLaunchFileTo(string targetDir)
+ {
+ var filePath = Path.Combine(targetDir, "LaunchBS.bat");
+ var fileResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(LaunchFileResourcePath);
+ var fileStream = File.Create(filePath);
+ fileResourceStream.Seek(0, SeekOrigin.Begin);
+ await fileResourceStream.CopyToAsync(fileStream);
+ fileStream.Close();
+ }
+
+ private void downloadInfoLabel_Initialized(object sender, EventArgs e)
+ {
+ downloadInfoLabelObject = (Label)sender;
+ RefreshUI();
+ }
+ }
+}
diff --git a/LegacyInstaller/Utilities.cs b/LegacyInstaller/Utilities.cs
index 945d365..ff28049 100644
--- a/LegacyInstaller/Utilities.cs
+++ b/LegacyInstaller/Utilities.cs
@@ -1,127 +1,135 @@
-using Microsoft.Win32;
-using System;
-using System.Data.HashFunction.CRC;
-using System.IO;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace LegacyInstaller
-{
- public static class Utilities
- {
- public static async Task CopyDirectory(string sourceDir, string targetDir)
- {
- try
- {
- Directory.CreateDirectory(targetDir);
-
- foreach (var file in Directory.GetFiles(sourceDir))
- {
- var fileSource = File.OpenRead(file);
- var fileTarget = File.Create(Path.Combine(targetDir, Path.GetFileName(file)));
- await fileSource.CopyToAsync(fileTarget);
- }
-
- foreach (var directory in Directory.GetDirectories(sourceDir))
- await CopyDirectory(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
- }
- catch { }
- }
-
- public static int Search(byte[] src, byte[] pattern)
- {
- int maxFirstCharSlot = src.Length - pattern.Length + 1;
- for (int i = 0; i < maxFirstCharSlot; i++)
- {
- if (src[i] != pattern[0]) // compare only first byte
- continue;
-
- // found a match on first byte, now try to match rest of the pattern
- for (int j = pattern.Length - 1; j >= 1; j--)
- {
- if (src[i + j] != pattern[j]) break;
- if (j == 1) return i;
- }
- }
- return -1;
- }
-
- public static string GenerateChecksum(string targetDir)
- {
- var sha = SHA1.Create();
-
- var files = Directory.GetFiles(targetDir, "*.*", SearchOption.AllDirectories);
- var bytes = new byte[0];
- foreach (var file in files)
- {
- if (file.Contains("LaunchBS"))
- continue;
- if (!File.Exists(file))
- continue;
- bytes = bytes.Concat(sha.ComputeHash(File.ReadAllBytes(file))).ToArray();
- }
- return BitConverter.ToString(sha.ComputeHash(bytes));
- }
-
- public static string GenerateStringChecksum(string input)
- {
- var sha = SHA1.Create();
- return BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(input)));
- }
-
- public static string DetectSteamInstallPath()
- {
- try
- {
- var detectedSteamPath = Registry.GetValue(
- @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam",
- "InstallPath",
- null
- );
-
- if (detectedSteamPath != null && Directory.Exists((string)detectedSteamPath))
- return (string)detectedSteamPath;
- }
- catch { }
- return null;
- }
-
- public static string DetectBeatSaberInstallPath()
- {
- try
- {
+using Microsoft.Win32;
+using System;
+using System.Data.HashFunction.CRC;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LegacyInstaller
+{
+ public static class Utilities
+ {
+ public static async Task CopyDirectory(string sourceDir, string targetDir)
+ {
+ try
+ {
+ Directory.CreateDirectory(targetDir);
+
+ foreach (var file in Directory.GetFiles(sourceDir))
+ {
+ var fileSource = File.OpenRead(file);
+ var fileTarget = File.Create(Path.Combine(targetDir, Path.GetFileName(file)));
+ await fileSource.CopyToAsync(fileTarget);
+ }
+
+ foreach (var directory in Directory.GetDirectories(sourceDir))
+ await CopyDirectory(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
+ }
+ catch { }
+ }
+
+ public static int Search(byte[] src, byte[] pattern)
+ {
+ int maxFirstCharSlot = src.Length - pattern.Length + 1;
+ for (int i = 0; i < maxFirstCharSlot; i++)
+ {
+ if (src[i] != pattern[0]) // compare only first byte
+ continue;
+
+ // found a match on first byte, now try to match rest of the pattern
+ for (int j = pattern.Length - 1; j >= 1; j--)
+ {
+ if (src[i + j] != pattern[j]) break;
+ if (j == 1) return i;
+ }
+ }
+ return -1;
+ }
+
+ public static string GenerateChecksum(string targetDir)
+ {
+ var sha = SHA1.Create();
+
+ var files = Directory.GetFiles(targetDir, "*.*", SearchOption.AllDirectories);
+ var bytes = new byte[0];
+ foreach (var file in files)
+ {
+ if (file.Contains("LaunchBS"))
+ continue;
+ if (!File.Exists(file))
+ continue;
+ bytes = bytes.Concat(sha.ComputeHash(File.ReadAllBytes(file))).ToArray();
+ }
+ return BitConverter.ToString(sha.ComputeHash(bytes));
+ }
+
+ public static string GenerateStringChecksum(string input)
+ {
+ var sha = SHA1.Create();
+ return BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(input)));
+ }
+
+ public static string DetectSteamInstallPath()
+ {
+ try
+ {
+ var detectedSteamPath = Registry.GetValue(
+ @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam",
+ "InstallPath",
+ null
+ );
+
+ if (detectedSteamPath != null && Directory.Exists((string)detectedSteamPath))
+ return (string)detectedSteamPath;
+ }
+ catch { }
+ return null;
+ }
+
+ public static string DetectBeatSaberInstallPath()
+ {
+ try
+ {
+ var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
+ var bsRegistryKey = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 620980");
+ if (bsRegistryKey != null)
+ {
+ var bsInstallPath = bsRegistryKey.GetValue("InstallLocation");
+ if (bsInstallPath != null && Directory.Exists((string)bsInstallPath))
+ return (string)bsInstallPath;
+ }
if (Directory.Exists("C:/Program Files (x86)/Steam/steamapps/common/Beat Saber"))
{
return "C:/Program Files (x86)/Steam/steamapps/common/Beat Saber";
- }
- }
- catch { }
- return null;
- }
-
- public static int GetCurrentSteamUser()
- => (int)RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)
- .OpenSubKey(@"SOFTWARE\Valve\Steam\ActiveProcess").GetValue("ActiveUser");
-
- public static UInt64 GetSteamAppId(string appName, string path, string exe)
- {
- var crc = CRCFactory.Instance.Create(new CRCConfig
- {
- HashSizeInBits = 32,
- Polynomial = 0x04C11DB7,
- ReflectIn = true,
- InitialValue = 0xffffffff,
- ReflectOut = true,
- XOrOut = 0xffffffff
- });
-
- byte[] inputBytes = Encoding.UTF8.GetBytes("\"" + Path.Combine(path, exe) + "\"" + appName);
- UInt64 top32 = BitConverter.ToUInt32(crc.ComputeHash(inputBytes).Hash, 0) | 0x80000000;
- UInt64 gameId = (top32 << 32) | 0x02000000;
-
- return gameId;
- }
- }
-}
+ }
+ }
+ catch { }
+ return "Please enter the Beat Saber install path manually";
+ }
+
+ public static int GetCurrentSteamUser()
+ => (int)RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)
+ .OpenSubKey(@"SOFTWARE\Valve\Steam\ActiveProcess").GetValue("ActiveUser");
+
+ public static UInt64 GetSteamAppId(string appName, string path, string exe)
+ {
+ var crc = CRCFactory.Instance.Create(new CRCConfig
+ {
+ HashSizeInBits = 32,
+ Polynomial = 0x04C11DB7,
+ ReflectIn = true,
+ InitialValue = 0xffffffff,
+ ReflectOut = true,
+ XOrOut = 0xffffffff
+ });
+
+ byte[] inputBytes = Encoding.UTF8.GetBytes("\"" + Path.Combine(path, exe) + "\"" + appName);
+ UInt64 top32 = BitConverter.ToUInt32(crc.ComputeHash(inputBytes).Hash, 0) | 0x80000000;
+ UInt64 gameId = (top32 << 32) | 0x02000000;
+
+ return gameId;
+ }
+ }
+}