public static List <ModelicaLibrary> GetLibrariesFromSettings(CyPhy2Modelica_v2Settings settings, string projectDir) { var libraries = new List <ModelicaLibrary>(); // If directory name was saved append package.mo // support all formats foreach (var dirPath in settings.IncludeDirectoryPath) { if (LibraryExists(dirPath, projectDir) == false) { continue; } var newLib = ModelicaLibrary.GetLibraryFromPath(dirPath); var found = libraries.FirstOrDefault(x => x.Name == newLib.Name); if (found == null) { libraries.Add(newLib); } } foreach (var dirPath in settings.NonCheckedIncludeDirPaths) { if (LibraryExists(dirPath, projectDir) == false) { continue; } var newLib = ModelicaLibrary.GetLibraryFromPath(dirPath); var found = libraries.FirstOrDefault(x => x.Name == newLib.Name); if (found == null) { newLib.IsSelected = false; libraries.Add(newLib); } else { found.Versions.Add(newLib.Versions.FirstOrDefault()); } } return(libraries); }
private void btnBrowseIncludeDir_Click(object sender, EventArgs e) { string startupDir = ""; var lastItem = libData.Cast <ModelicaLibrary>().LastOrDefault(); if (lastItem != null) { startupDir = (new DirectoryInfo(Path.GetDirectoryName(lastItem.GetCurrentLibraryPath()))).Parent.FullName; if (Path.IsPathRooted(startupDir) == false) { startupDir = Path.Combine(this.ProjectDir, startupDir); } } else { startupDir = this.ProjectDir; } var fbd = new OpenFileDialog() { Multiselect = false, Filter = "Modelica files (*.mo)|*.mo", InitialDirectory = startupDir, Title = "Select Modelica package. If multi-file package; select the package.mo highest up in the file hierarchy." }; var dr = fbd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { var pathToSave = fbd.FileName; // offer relative path if it is available Uri uri1 = new Uri(pathToSave); Uri uri2 = new Uri(this.ProjectDir + "\\"); string relativePath = Uri.UnescapeDataString(uri2.MakeRelativeUri(uri1).ToString().Replace('/', '\\')); if (relativePath != pathToSave && Path.GetFullPath(relativePath) == pathToSave) { var saveRelative = MessageBox.Show( "Would you like to save the path as relative?", "Save as relative path", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (saveRelative == System.Windows.Forms.DialogResult.Yes) { pathToSave = relativePath; } } var modelicaLibrary = ModelicaLibrary.GetLibraryFromPath(pathToSave); if (modelicaLibrary == null) { MessageBox.Show(pathToSave + "\ndoes not have a valid Modelica package name!", "Invalid package name", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var existingPackage = libData.Cast <ModelicaLibrary>().Where(lib => lib.Name == modelicaLibrary.Name).FirstOrDefault(); if (existingPackage == null) { libData.Add(modelicaLibrary); } else { existingPackage.UpdateVersionPath(modelicaLibrary.Version, pathToSave); existingPackage.Version = modelicaLibrary.Version; } dataGridView1.Refresh(); } }