private static string ShowInstallDirectoryDialog(string currentPath) { using (var fb = new CommonOpenFileDialog { IsFolderPicker = true, InitialDirectory = currentPath, AllowNonFileSystemItems = false, AddToMostRecentlyUsedList = false, EnsurePathExists = true, EnsureFileExists = true, Multiselect = false, Title = "Select the install directory of the game." }) { retryFolderSelect: if (fb.ShowDialog() == CommonFileDialogResult.Ok) { var path = fb.FileName; if (!InstallDirectoryHelper.IsValidGamePath(path)) { if (MessageBox.Show( "The selected directory doesn't seem to contain the game. Make sure the directory is correct and try again.", "Select install directory", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { goto retryFolderSelect; } } return(path); } return(null); } }
private static string ShowInstallDirectoryDialog(string currentPath) { using (var fb = new FolderBrowserDialog()) { fb.RootFolder = Environment.SpecialFolder.MyComputer; fb.SelectedPath = currentPath ?? ""; fb.ShowNewFolderButton = false; fb.Description = "Select the install directory of the game."; retryFolderSelect: if (fb.ShowDialog() == DialogResult.OK) { var path = fb.SelectedPath; if (!InstallDirectoryHelper.IsValidGamePath(path)) { if (MessageBox.Show( "The selected directory doesn't seem to contain the game. Make sure the directory is correct and try again.", "Select install directory", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { goto retryFolderSelect; } } return(path); } return(null); } }
private static DirectoryInfo GetKoikatuDirectory() { var path = Settings.Default.GamePath; if (!InstallDirectoryHelper.IsValidGamePath(path)) { try { path = Registry.CurrentUser.OpenSubKey(@"Software\Illusion\Koikatu\koikatu") ?.GetValue("INSTALLDIR") as string; } catch (SystemException) { } if (!InstallDirectoryHelper.IsValidGamePath(path)) { MessageBox.Show( "Koikatu is either not registered properly or its install directory is missing or inaccessible.\n\nYou will have to select game directory manually.", "Failed to find Koikatu install directory", MessageBoxButtons.OK, MessageBoxIcon.Error); path = ShowInstallDirectoryDialog(path); } if (string.IsNullOrEmpty(path) || !InstallDirectoryHelper.IsValidGamePath(path)) { MessageBox.Show( "Koikatu is either not registered properly or its install directory is missing or inaccessible.", "Failed to get Koikatu install directory", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } Settings.Default.GamePath = path; } CheckInstallPathPermissions(path); return(new DirectoryInfo(path)); }
private static DirectoryInfo GetGameDirectory() { var path = Settings.Default.GamePath; if (!InstallDirectoryHelper.IsValidGamePath(path)) { for (var dir = new DirectoryInfo(Program.ProgramLocation); dir.Exists && dir.Parent != null; dir = dir.Parent) { if (InstallDirectoryHelper.IsValidGamePath(dir.FullName)) { path = dir.FullName; break; } } if (!InstallDirectoryHelper.IsValidGamePath(path)) { MessageBox.Show( "Your game's install directory could not be detected or is inaccessible.\n\nYou will have to select the game directory manually.", "Failed to find game install directory", MessageBoxButtons.OK, MessageBoxIcon.Error); if (string.IsNullOrWhiteSpace(path)) { // Get a plausible initial path try { path = Registry.CurrentUser.OpenSubKey(@"Software\Illusion\Koikatu\koikatu") ?.GetValue("INSTALLDIR") as string; } catch (SystemException) { } } path = ShowInstallDirectoryDialog(path); } if (!InstallDirectoryHelper.IsValidGamePath(path)) { MessageBox.Show( "Your game is either not registered properly or its install directory is missing or inaccessible.", "Failed to find game install directory", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } Settings.Default.GamePath = path; if (path.Length > 100) { MessageBox.Show( "Your game path is very long and is likely to cause issues with running the game and/or KK Manager.\n\nPlease consider moving your game to a simpler directory like \"D:\\Games\\Koikatsu\" to avoid potential issues. ", "Game directory warning", MessageBoxButtons.OK); } else if (path.Any(x => x > 127)) { MessageBox.Show( "Your game path contains special characters that might cause issues with running the game.\n\nPlease consider moving your game to a simpler directory like \"D:\\Games\\Koikatsu\" to avoid potential issues. ", "Game directory warning", MessageBoxButtons.OK); } } CheckInstallPathPermissions(path); return(new DirectoryInfo(path)); }