private string GetFile(OFType fileType, string currentFile) { openFileDialog.Filter = ResourceHelper.BuildFileFilter(FileFilterType.ImportMapping, FileFilterType.XML, FileFilterType.AllShoeboxDictionaryDatabases, FileFilterType.AllFiles); openFileDialog.FilterIndex = (fileType == OFType.Settings) ? 1 : (fileType == OFType.Database) ? 3 : 4; // only require the file to exist if its Database or Settings openFileDialog.CheckFileExists = true; if (fileType == OFType.SaveAs) openFileDialog.CheckFileExists = false; openFileDialog.Multiselect = false; bool done = false; while (!done) { // LT-6620 : putting in an invalid path was causing an exception in the openFileDialog.ShowDialog() // Now we make sure parts are valid before setting the values in the openfile dialog. string dir = string.Empty; try { dir = Path.GetDirectoryName(currentFile); } catch{} if (Directory.Exists(dir)) openFileDialog.InitialDirectory = dir; // if we don't set it to something, it remembers the last file it saw. This can be // a very poor default if we just opened a valuable data file and are now choosing // a place to save settings (LT-8126) if (File.Exists(currentFile) || (fileType == OFType.SaveAs && Directory.Exists(dir))) openFileDialog.FileName = currentFile; else openFileDialog.FileName = ""; openFileDialog.Title = String.Format(LexTextControls.ksSelectXFile, fileType.ToString()); if (openFileDialog.ShowDialog() == DialogResult.OK) { bool isValid = false; string text; // Before doing the 'fileType' based tests, make sure it's not a PhaseX file if (GetDictionaryFileAsPhaseFileNumber(openFileDialog.FileName) > 0) { isValid = true; // trusting that phaseX files properly named are valid text = LexTextControls.ksPhaseFile; } else if (fileType == OFType.Database) { text = LexTextControls.ksStandardFormat; Sfm2Xml.IsSfmFile validFile = new Sfm2Xml.IsSfmFile(openFileDialog.FileName); isValid = validFile.IsValid; } else if (fileType == OFType.SaveAs) { text = LexTextControls.ksXmlSettings; isValid = true; // no requirements sense the file will be overridden } else { text = LexTextControls.ksXmlSettings; isValid = MarkerPresenter.IsValidMapFile(openFileDialog.FileName); } if (!isValid) { string msg = String.Format(LexTextControls.ksSelectedFileXInvalidY, openFileDialog.FileName, text, System.Environment.NewLine); DialogResult dr = MessageBox.Show(this, msg, LexTextControls.ksPossibleInvalidFile, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) return openFileDialog.FileName; else if (dr == DialogResult.No) continue; else break; // exit with current still } return openFileDialog.FileName; } else done = true; } return currentFile; }