private void chooseModDirectory() { var dialog = new FolderSelectDialog() { DirectoryPath = kModsDirectoryPath ?? Environment.CurrentDirectory, Title = "Stonehearth Mods Root Directory" }; DialogResult result = DialogResult.Abort; do { result = dialog.ShowDialog(); if (result == DialogResult.OK) { string newPath = dialog.DirectoryPath; if (this.checkModsFolder(ref newPath)) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; Properties.Settings.Default.Save(); return; } else if (Directory.Exists(newPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user chocie if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { return; } } else { if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { return; } } } else { if (MessageBox.Show("No mods directory selected. Try again?", "No directory selected.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } }while (true); // repeat until we've got a proper directory or the user aborts }
private void changeSteamUploadsPathButton_Click(object sender, EventArgs e) { var dialog = new FolderSelectDialog() { DirectoryPath = steamUploadsPathTextbox.Text ?? Environment.CurrentDirectory, Title = "Steam Uploads Directory" }; DialogResult result = DialogResult.Abort; result = dialog.ShowDialog(); if (result == DialogResult.OK) { steamUploadsPathTextbox.Text = dialog.DirectoryPath; } }
private bool chooseModDirectory() { var dialog = new FolderSelectDialog() { DirectoryPath = kModsDirectoryPath ?? Environment.CurrentDirectory, Title = "Stonehearth Mods Root Directory" }; DialogResult result = DialogResult.Abort; do { result = dialog.ShowDialog(); if (result == DialogResult.OK) { string newPath = dialog.DirectoryPath; var check = this.checkModsFolder(ref newPath); if (check == ModFolderCheckResult.ZIPPED) { if (MessageBox.Show("The chosen directory appears to have compressed mods. To use it, the mods must be uncompressed. Would you like to do that?", "Compressed mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { var splash = new LoadingSplash(); splash.Show(); Application.DoEvents(); // Hacky, but whatever. foreach (var path in Directory.EnumerateFiles(newPath)) { if (path.EndsWith(".smod") && !Directory.Exists(path.Substring(0, path.Length - 5))) { System.IO.Compression.ZipFile.ExtractToDirectory(path, newPath); } } splash.Hide(); splash.Dispose(); check = ModFolderCheckResult.VALID; } } if (check == ModFolderCheckResult.VALID) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; Properties.Settings.Default.Save(); return(true); } else if (Directory.Exists(newPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user choice if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; return(true); } } else { if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { return(false); } } } else { if (MessageBox.Show("No mods directory selected. Try again?", "No directory selected.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } }while (true); // repeat until we've got a proper directory or the user aborts }