NClass.Core.Project.Load C# (CSharp) Method

Load() public static method

/// Could not load the project. /// /// The save file is corrupt and could not be loaded. /// /// is empty string. ///
public static Load ( string fileName ) : Project
fileName string
return Project
		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;
		}