예제 #1
0
        //Classic:
        //  New: C:\Users\{USER}\AppData\Local\osu!\
        //  Old: C:\Program Files\osu!\
        //    OR C:\Program Files(x86)\osu!\
        //Lazer:
        //       C:\Users\{USER}\AppData\Local\osulazer\
        public static bool TryGetPhysicalInstall(OsuVersion V, out FileInfo Found)
        {
            switch (V)
            {
            case OsuVersion.Classic:
                if ($"{FileSystemExtensions.LocalAppData.FullName}\\osu!\\osu!.exe".TryGetFileInfo(true, out Found))
                {
                    return(true);    // C:\Users\{USER}\AppData\Local\osu!\
                }
                else if ($"{FileSystemExtensions.ProgramFiles.FullName}\\osu!\\osu!.exe".TryGetFileInfo(true, out Found))
                {
                    return(true);    // C:\Program Files\osu!\
                }
                else if ($"{FileSystemExtensions.ProgramFiles86.FullName}\\osu!\\osu!.exe".TryGetFileInfo(true, out Found))
                {
                    return(true);    // C:\Program Files(x86)\osu!\
                }
                break;

            case OsuVersion.Lazer:
                if ($"{FileSystemExtensions.LocalAppData.FullName}\\osulazer\\osu!.exe".TryGetFileInfo(true, out Found))
                {
                    return(true);    // C:\Users\{USER}\AppData\Local\osulazer\
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(V), V, null);
            }

            Found = null;
            return(false);
        }
예제 #2
0
        public static IEnumerable <RegistryKey> GetOsuInstallationKeys(OsuVersion V)
        {
            //Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
            using (RegistryKey UninstallNode = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\")) {
                foreach (string LocalNodeName in UninstallNode.GetSubKeyNames())
                {
                    using (RegistryKey LocalNode = UninstallNode.OpenSubKey(LocalNodeName)) {
                        if (TryGetValue(LocalNode, "DisplayName", out object Value) && Value is string LocalAppName)
                        {
                            switch (V)
                            {
                            case OsuVersion.Classic:
                                if (LocalAppName.Equals("osu!", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    yield return(LocalNode);
                                }
                                break;

                            case OsuVersion.Lazer:
                                if (LocalAppName.Equals("osu!lazer", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    yield return(LocalNode);
                                }
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(V), V, null);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public static bool TryGetInstall(OsuVersion V, out FileInfo Found)
        {
#if (DEBUG)
            Stopwatch Watch = new Stopwatch();
            Watch.Start();
#endif
            if (TryGetPhysicalInstall(V, out Found))
            {
#if (DEBUG)
                Watch.Stop();
                Debug.WriteLine($"Found {V} through *file-system* search in {Watch.ElapsedMilliseconds:N2}ms.");
#endif
                return(true);
            }

            if (TryGetRegistryInstall(V, out Found))
            {
#if (DEBUG)
                Watch.Stop();
                Debug.WriteLine($"Found {V} through *registry* search in {Watch.ElapsedMilliseconds:N2}ms.");
#endif
                return(true);
            }

            Debug.WriteLine($"Unable to find {V}.");
            Found = null;
            return(false);
        }
예제 #4
0
        public static bool TryGetInstallLocation(OsuVersion V, out DirectoryInfo Found)
        {
            if (TryGetInstall(V, out FileInfo FoundFile))
            {
                Found = FoundFile.Directory;
                return(true);
            }

            Found = null;
            return(false);
        }
예제 #5
0
        public static bool TryGetRegistryInstall(OsuVersion V, out FileInfo Found)
        {
            foreach (RegistryKey Key in GetOsuInstallationKeys(V))
            {
                if (TryGetValue(Key, "UninstallString", out object Value) && Value is string UninstallCommand)
                {
                    if (GetPath(UninstallCommand).TryGetFileInfo(true, out Found))
                    {
                        //Debug.WriteLine($"/////Found: {Found}/////");
                        return(Found != null);
                    }
                }
            }

            Found = null;
            return(false);
        }