From c614492e2e3b029f5fd7de573c0ad733e388ef7c Mon Sep 17 00:00:00 2001 From: mika Date: Sun, 21 Apr 2024 00:08:01 +0300 Subject: [PATCH] add support for 2022.x custom asset store downloads location, fixes #73 --- UnityLauncherPro/MainWindow.xaml.cs | 1 + UnityLauncherPro/Tools.cs | 39 +++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/UnityLauncherPro/MainWindow.xaml.cs b/UnityLauncherPro/MainWindow.xaml.cs index 49c59f3..407f963 100644 --- a/UnityLauncherPro/MainWindow.xaml.cs +++ b/UnityLauncherPro/MainWindow.xaml.cs @@ -1827,6 +1827,7 @@ private void ChkAllowSingleInstanceOnly_CheckedChanged(object sender, RoutedEven private void BtnAssetPackages_Click(object sender, RoutedEventArgs e) { + Tools.OpenCustomAssetPath(); Tools.OpenAppdataSpecialFolder("../Roaming/Unity/Asset Store-5.x"); } diff --git a/UnityLauncherPro/Tools.cs b/UnityLauncherPro/Tools.cs index 2802d49..f4e953a 100644 --- a/UnityLauncherPro/Tools.cs +++ b/UnityLauncherPro/Tools.cs @@ -829,7 +829,8 @@ public static string ParseDownloadURLFromWebpage(string version, bool preferFull else { // TODO version here is actually HASH - url = $"https://beta.unity3d.com/download/{version}/download.html"; + string hash = version; + url = $"https://beta.unity3d.com/download/{hash}/download.html"; //Console.WriteLine(url); @@ -838,7 +839,7 @@ public static string ParseDownloadURLFromWebpage(string version, bool preferFull //Console.WriteLine(version); if (string.IsNullOrEmpty(version)) { - Console.WriteLine("Failed to get version number from hash: " + version); + SetStatus("Failed to get version (" + version + ") number from hash: " + hash); return null; } } @@ -2218,6 +2219,40 @@ internal static void SaveProjectSettings(Project proj, string customEnvVars) Console.WriteLine(fullPath); } } + + internal static void OpenCustomAssetPath() + { + // check if custom asset folder is used, then open both *since older versions might have assets in old folder + string keyPath = @"SOFTWARE\Unity Technologies\Unity Editor 5.x"; + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath)) + { + if (key == null) return; + // Enumerate subkeys + foreach (string valueName in key.GetValueNames()) + { + // Check if the subkey matches the desired pattern + if (Regex.IsMatch(valueName, @"AssetStoreCacheRootPath_h\d+") == false) continue; + + string customAssetPath = ""; + var valueKind = key.GetValueKind(valueName); + + if (valueKind == RegistryValueKind.Binary) + { + byte[] bytes = (byte[])key.GetValue(valueName); + customAssetPath = Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1); + } + else // should be string then + { + customAssetPath = (string)key.GetValue(valueName); + } + + if (string.IsNullOrEmpty(customAssetPath) == false && Directory.Exists(customAssetPath)) + { + Tools.LaunchExplorer(Path.Combine(customAssetPath, "Asset Store-5.x")); + } + } + } + } } // class } // namespace