/// <summary> /// Load all project data into the local ProjectSpace instance /// </summary> /// <param name="projectPath">Path to the project directory</param> /// <returns>A success flag and a message in case of an error.</returns> public (bool, string) LoadProject(string projectPath) { // Check if the directory path is valid if (projectPath.Equals("") || !Path.IsPathRooted(projectPath)) { return(false, "The given directory path is invalid!"); } // Check if the project config file exists var projectConfigFile = Path.Combine(projectPath, ProjectConfigFile); if (!File.Exists(projectConfigFile)) { return(false, "Project doesn't contain \n a config file!"); } // Check if the project model file exists if (!File.Exists(projectConfigFile)) { return(false, "Project doesn't contain \n a model file!"); } try { // Load the project configuration from XML (excluding 3D model) CurrentProject = _xmlDeSerializer.DeserializeData(projectConfigFile); CurrentProjectDir = projectPath; // Check if the project model file exists return(!File.Exists(projectConfigFile) ? (false, "Project doesn't contain \n an object file!") : (true, "")); } catch (Exception) { return(false, "The project couldn't \n be loaded!"); } }
/// <summary> /// Try to create a new project /// </summary> /// <param name="name">The name of the project</param> /// <param name="dirPath">The path to the directory in which the project shall be created</param> /// <param name="importPath">The path to the model that shall be imported</param> /// <param name="overwrite">True if the directory can be overwritten</param> /// <returns> /// A tuple containing a bool that is true if the operation was /// successful and a string that contains a message in the case /// of an error /// </returns> public (bool, string) CreateProject(string name, string dirPath, string importPath, bool overwrite) { // Check if the name is empty if (name.Equals("")) { return(false, "Name is empty!"); } // Check if the directory path is valid if (dirPath.Equals("") || !Path.IsPathRooted(dirPath)) { return(false, "The given directory \n path is invalid!"); } // Check if the import path is valid if (!File.Exists(importPath) || !Path.IsPathRooted(importPath)) { return(false, "The given import \n path is incorrect!"); } var objectFile = Path.GetFileName(importPath); // Create the project path var projectPath = Path.Combine(dirPath, name); // Check if the project directory exists if (Directory.Exists(projectPath)) { if (!overwrite) { return(false, "Directory already exists!"); } // Create a new ProjectSpace CurrentProject = new ProjectSpace(name, objectFile); CurrentProjectDir = projectPath; // Save the new open project in the config _configManager.Config.lastProject = projectPath; return(CreateProjectFiles(projectPath, importPath)); } // Otherwise try to create the directories try { Directory.CreateDirectory(projectPath); // Create a new ProjectSpace CurrentProject = new ProjectSpace(name, objectFile); CurrentProjectDir = projectPath; // Save the new open project in the config _configManager.Config.lastProject = projectPath; return(CreateProjectFiles(projectPath, importPath)); } catch (Exception) { return(false, "The target project \n could not be created!"); } }