diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-09 02:58:11 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-09 02:58:47 +0100 |
commit | 959e18046d6ec0bc9eefc8efd9b136cb14314af6 (patch) | |
tree | 76a30a39ccce380ee79bc79f4c96dfd35c44a6e9 /SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs | |
download | SpacebarDiscordDesktopLauncher-959e18046d6ec0bc9eefc8efd9b136cb14314af6.tar.xz |
Initial commit
Diffstat (limited to 'SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs')
-rw-r--r-- | SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs b/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs new file mode 100644 index 0000000..8b6db0e --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs @@ -0,0 +1,38 @@ +namespace SpacebarDiscordDesktopLauncher; + +public static class WindowsDiscordClientFinder +{ + public static string? FindDiscord() + { + Console.WriteLine($"Looking for installed Discord desktop instance..."); + + var basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + foreach (var discordBranch in new String[] { "", "PTB", "Canary", "Development" }) + { + if (Path.Exists(Path.Combine(basePath, "Discord" + discordBranch))) + return Path.Combine(GetLatestAppVersion(Path.Combine(basePath, "Discord" + discordBranch)), + discordBranch + ".exe"); + } + + Console.WriteLine("Could not find Discord! Do you have the normal Discord client installed?"); + Console.ReadLine(); + return null; + } + + private static string GetLatestAppVersion(string basePath) + { + var dirs = Directory.GetDirectories(basePath); + var newestDir = ""; + var newestDirDate = DateTime.MinValue; + foreach (var dir in dirs) + { + var di = new DirectoryInfo(dir); + if (!di.Name.StartsWith("app", StringComparison.InvariantCultureIgnoreCase)) continue; + if (di.CreationTimeUtc <= newestDirDate) continue; + newestDirDate = di.CreationTimeUtc; + newestDir = di.FullName; + } + + return newestDir; + } +} \ No newline at end of file |