public void SaveProject(PartProject project, bool selectPath = false) { bool isNew = string.IsNullOrEmpty(project.ProjectPath); string targetPath = project.ProjectPath; if (selectPath || isNew) { using (var sfd = new SaveFileDialog()) { if (!string.IsNullOrEmpty(project.ProjectPath)) { sfd.InitialDirectory = Path.GetDirectoryName(project.ProjectPath); sfd.FileName = Path.GetFileName(project.ProjectPath); } else { if (SettingsManager.IsWorkspaceDefined) { sfd.InitialDirectory = SettingsManager.Current.ProjectWorkspace; } if (project.PartID > 0) { sfd.FileName = $"{project.PartID}.lpp"; } else { sfd.FileName = $"New part.lpp"; } } sfd.Filter = "LDD Part Project|*.lpp|All Files|*.*"; sfd.DefaultExt = ".lpp"; if (sfd.ShowDialog() == DialogResult.OK) { targetPath = sfd.FileName; } else { return; } } } string oldPath = project.ProjectPath; ProjectManager.SaveProject(targetPath); SettingsManager.AddRecentProject(project, true); if (oldPath != targetPath) { RebuildRecentFilesMenu(); } }
private void OpenPartProjectFile(string projectFilePath) { if (!CloseCurrentProject()) { return; } string tmpProjectDir = GetTemporaryWorkingDir(); PartProject loadedProject = null; bool exceptionThrown = false; try { using (var fs = File.OpenRead(projectFilePath)) loadedProject = PartProject.ExtractAndOpen(fs, tmpProjectDir); } catch (Exception ex) { ErrorMessageBox.Show(this, Messages.Error_OpeningProject, Messages.Caption_OpeningProject, ex.ToString()); exceptionThrown = true; } if (loadedProject != null) { loadedProject.ProjectPath = projectFilePath; loadedProject.ProjectWorkingDir = tmpProjectDir; SettingsManager.Current.LastOpenProject = new RecentFileInfo(loadedProject, true); SettingsManager.AddRecentProject(loadedProject); LoadPartProject(loadedProject); RebuildRecentFilesMenu(); } else if (!exceptionThrown) { ErrorMessageBox.Show(this, Messages.Error_OpeningProject, Messages.Caption_OpeningProject, "Invalid or corrupted project file. Missing \"project.xml\" file."); } }
private bool LoadPartProject(PartProject project, string tempPath = null) { if (!CloseCurrentProject()) { return(false); } ViewportPanel.ForceRender(); ProjectManager.SetCurrentProject(project, tempPath); if (project != null) { if (!ProjectManager.IsNewProject && string.IsNullOrEmpty(tempPath)) { RebuildRecentFilesMenu(); SettingsManager.AddRecentProject(ProjectManager.GetCurrentProjectInfo(), true); } AutoSaveTimer.Start(); } return(project != null); }