private IonMobilityLibrarySpec FindIonMobilityDatabase(string documentPath, IonMobilityLibrarySpec ionMobilityLibSpec) { IonMobilityLibrarySpec result; if (Settings.Default.IonMobilityLibraryList.TryGetValue(ionMobilityLibSpec.Name, out result)) { if (result.IsNone || File.Exists(result.PersistencePath)) return result; } // First look for the file name in the document directory string fileName = Path.GetFileName(ionMobilityLibSpec.PersistencePath); string filePath = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName ?? string.Empty); if (File.Exists(filePath)) { try { var lib = ionMobilityLibSpec as IonMobilityLibrary; if (lib != null) return lib.ChangeDatabasePath(filePath); } // ReSharper disable once EmptyGeneralCatchClause catch { //Todo: should this fail silenty or report an error } } _out.WriteLine(Resources.CommandLine_FindIonMobilityDatabase_Error__Could_not_find_the_ion_mobility_library__0__, Path.GetFileName(ionMobilityLibSpec.PersistencePath)); return null; }
private IonMobilityLibrarySpec FindIonMobilityLibrary(IWin32Window parent, string documentPath, IonMobilityLibrarySpec ionMobilityLibrarySpec) { IonMobilityLibrarySpec result; if (Settings.Default.IonMobilityLibraryList.TryGetValue(ionMobilityLibrarySpec.Name, out result)) { if (result != null && File.Exists(result.PersistencePath)) return result; } if (documentPath == null) return null; // First look for the file name in the document directory string fileName = Path.GetFileName(ionMobilityLibrarySpec.PersistencePath); string filePath = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName ?? string.Empty); if (File.Exists(filePath)) { try { var ionMobilityLib = ionMobilityLibrarySpec as IonMobilityLibrary; if (ionMobilityLib != null) return ionMobilityLib.ChangeDatabasePath(filePath); } // ReSharper disable once EmptyGeneralCatchClause catch { //Todo: should this fail silenty or raise another dialog box? } } do { using (var dlg = new MissingFileDlg { ItemName = ionMobilityLibrarySpec.Name, ItemType = Resources.SkylineWindow_FindIonMobilityLibrary_Ion_Mobility_Library, Filter = TextUtil.FileDialogFilterAll(Resources.SkylineWindow_FindIonMobilityDatabase_ion_mobility_library_files, IonMobilityDb.EXT), FileHint = Path.GetFileName(ionMobilityLibrarySpec.PersistencePath), FileDlgInitialPath = Path.GetDirectoryName(documentPath), Title = Resources.SkylineWindow_FindIonMobilityLibrary_Find_Ion_Mobility_Library }) { if (dlg.ShowDialog(parent) == DialogResult.OK) { if (dlg.FilePath == null) return IonMobilityLibrary.NONE; try { var ionMobilityLib = ionMobilityLibrarySpec as IonMobilityLibrary; if (ionMobilityLib != null) return ionMobilityLib.ChangeDatabasePath(dlg.FilePath); } catch (DatabaseOpeningException e) { var message = TextUtil.SpaceSeparate( Resources.SkylineWindow_FindIonMobilityDatabase_The_ion_mobility_library_specified_could_not_be_opened_, e.Message); MessageBox.Show(message); } } else { return null; } } } while (true); }