/// <exception cref="IOException"> /// Could not load the project. /// </exception> /// <exception cref="InvalidDataException"> /// The save file is corrupt and could not be loaded. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="fileName"/> is empty string. /// </exception> public static Project Load(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException(Strings.ErrorBlankFilename, "fileName"); } if (!File.Exists(fileName)) { throw new FileNotFoundException(Strings.ErrorFileNotFound); } XmlDocument document = new XmlDocument(); try { document.Load(fileName); } catch (Exception ex) { throw new IOException(Strings.ErrorCouldNotLoadFile, ex); } XmlElement root = document["Project"]; if (root == null) { root = document["ClassProject"]; // Old file format if (root == null) { throw new InvalidDataException(Strings.ErrorCorruptSaveFile); } else { Project oldProject = LoadWithPreviousFormat(root); oldProject.FilePath = fileName; oldProject.name = Path.GetFileNameWithoutExtension(fileName); oldProject.isUntitled = false; return(oldProject); } } Project project = new Project(); project.loading = true; try { project.Deserialize(root); } catch (Exception ex) { throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex); } project.loading = false; project.FilePath = fileName; project.isReadOnly = project.projectFile.IsReadOnly; return(project); }
/// <exception cref="IOException"> /// Could not load the project. /// </exception> /// <exception cref="InvalidDataException"> /// The save file is corrupt and could not be loaded. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="fileName"/> is empty string. /// </exception> public static Project Load(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException(Strings.ErrorBlankFilename, "fileName"); } if (!File.Exists(fileName)) { throw new FileNotFoundException(Strings.ErrorFileNotFound); } XmlDocument document = new XmlDocument(); try { document.Load(fileName); } catch (Exception ex) { throw new IOException(Strings.ErrorCouldNotLoadFile, ex); } XmlElement root = document["Project"]; Project project = new Project(); project.Loading = true; try { project.Deserialize(root); } catch (Exception ex) { throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex); } project.Loading = false; project.FilePath = fileName; project.IsReadOnly = project._projectFile.IsReadOnly; return(project); }
/// <exception cref="IOException"> /// Could not load the project. /// </exception> /// <exception cref="InvalidDataException"> /// The save file is corrupt and could not be loaded. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="fileName"/> is empty string. /// </exception> public static Project Load(string fileName) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentException(Strings.ErrorBlankFilename, "fileName"); if (!File.Exists(fileName)) throw new FileNotFoundException(Strings.ErrorFileNotFound); XmlDocument document = new XmlDocument(); try { document.Load(fileName); } catch (Exception ex) { throw new IOException(Strings.ErrorCouldNotLoadFile, ex); } XmlElement root = document["Project"]; if (root == null) { root = document["ClassProject"]; // Old file format if (root == null) { throw new InvalidDataException(Strings.ErrorCorruptSaveFile); } else { Project oldProject = LoadWithPreviousFormat(root); oldProject.FilePath = fileName; oldProject.name = Path.GetFileNameWithoutExtension(fileName); oldProject.isUntitled = false; return oldProject; } } Project project = new Project(); project.loading = true; try { project.Deserialize(root); } catch (Exception ex) { throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex); } project.loading = false; project.FilePath = fileName; project.isReadOnly = project.projectFile.IsReadOnly; return project; }