-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathProjectDefinition.cs
More file actions
86 lines (71 loc) · 2.12 KB
/
Copy pathProjectDefinition.cs
File metadata and controls
86 lines (71 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using RPGCore.Packages;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace RPGCore.Projects;
/// <summary>
/// Represents a configuration definition for the package.
/// </summary>
public class ProjectDefinition : IDefinition
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly XmlDocument document;
/// <summary>
/// <para>A path to the project directory on the system.</para>
/// </summary>
public string Path { get; }
/// <summary>
/// General properties defined for this package.
/// </summary>
public ProjectDefinitionProperties Properties { get; }
// Work-in-progress "References" feature.
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal List<Reference> References { get; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)] IDefinitionProperties IDefinition.Properties => Properties;
private ProjectDefinition(string path, XmlDocument document)
{
var projectFile = new FileInfo(path);
Properties = new ProjectDefinitionProperties(projectFile, document);
References = new List<Reference>();
var projectReferenceTags = document.GetElementsByTagName("ProjectReference");
for (int i = 0; i < projectReferenceTags.Count; i++)
{
var projectReferenceElement = projectReferenceTags.Item(i);
if (projectReferenceElement is XmlElement element)
{
References.Add(new ProjectReference(this, element));
}
}
var resourceReferenceTags = document.GetElementsByTagName("ResourceReference");
for (int i = 0; i < resourceReferenceTags.Count; i++)
{
var resourceReferenceElement = resourceReferenceTags.Item(i);
if (resourceReferenceElement is XmlElement element)
{
References.Add(new ResourceReference(this, element));
}
}
Path = path;
this.document = document;
}
public void SaveChanges()
{
XmlProjectFile.Format(document);
document.Save(Path);
}
public static ProjectDefinition Load(string path)
{
if (!File.Exists(path))
{
return null;
}
var doc = new XmlDocument
{
PreserveWhitespace = true
};
doc.Load(path);
var model = new ProjectDefinition(path, doc);
return model;
}
}