void AddNewGame() { var fullPath = ""; var row = GamesDataGridView.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault(); if (row != null) { var item = (x360ce.Engine.Data.Game)row.DataBoundItem; fullPath = item.FullPath; } var path = ""; AddGameOpenFileDialog.DefaultExt = ".exe"; if (!string.IsNullOrEmpty(fullPath)) { var fi = new System.IO.FileInfo(fullPath); if (string.IsNullOrEmpty(path)) { path = fi.Directory.FullName; } AddGameOpenFileDialog.FileName = fi.Name; } AddGameOpenFileDialog.Filter = EngineHelper.GetFileDescription(".exe") + " (*.exe)|*.exe|All files (*.*)|*.*"; AddGameOpenFileDialog.FilterIndex = 1; AddGameOpenFileDialog.RestoreDirectory = true; if (string.IsNullOrEmpty(path)) { path = System.IO.Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); } AddGameOpenFileDialog.InitialDirectory = path; AddGameOpenFileDialog.Title = "Browse for Executable"; var result = AddGameOpenFileDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { // Don't allow to add windows folder. var winFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Windows); if (AddGameOpenFileDialog.FileName.StartsWith(winFolder)) { MessageBoxForm.Show("Windows folders are not allowed.", "Windows Folder", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { ProcessExecutable(AddGameOpenFileDialog.FileName); } } }