@@ -23,7 +23,6 @@ public class ElderScrollsPlugin : IDisposable
2323 public static Dictionary < uint , List < RecordView > > LoadedRecordViews = new Dictionary < uint , List < RecordView > > ( ) ;
2424 public static List < KeyValuePair < string , bool > > pluginLocations = new List < KeyValuePair < string , bool > > ( ) ;
2525
26- protected string name = "" ;
2726 public List < string > Masters = new List < string > ( ) ;
2827 public RecordView Header ;
2928 public List < Group > TopGroups = new List < Group > ( ) ;
@@ -32,21 +31,21 @@ public class ElderScrollsPlugin : IDisposable
3231
3332 protected MemoryMappedFile mmf ;
3433
35- public string Name
34+ public string ProperName
3635 {
3736 get
3837 {
3938 if ( Header . Flags . HasFlag ( RecordFlag . IsMasterFile ) )
40- return name + ".esm" ;
39+ return Name + ".esm" ;
4140 else
42- return name + ".esp" ;
43- }
44- protected set
45- {
46- name = Path . GetFileNameWithoutExtension ( value ) ;
41+ return Name + ".esp" ;
4742 }
4843 }
4944
45+ public string Name { get ; protected set ; }
46+
47+ public string FileName { get ; protected set ; }
48+
5049 public ElderScrollsPlugin ( )
5150 {
5251 }
@@ -69,8 +68,12 @@ public void Read(string source)
6968
7069 public void WriteXML ( string destinationFolder )
7170 {
72- Header . Record . WriteXML ( Path . Combine ( destinationFolder , "Header.xml" ) , this ) ;
71+ var headerLocation = Path . Combine ( destinationFolder , "Header.xml" ) ;
72+ Header . Record . WriteXML ( headerLocation , this ) ;
7373//.Where(g => g.ToString() != "Interior Cells" && g.ToString() != "Worldspaces" && g.ToString() != "Dialog Topics")
74+ var xml = XDocument . Load ( headerLocation ) ;
75+ xml . Element ( "Record" ) . Add ( new XElement ( "FileName" , FileName ) ) ;
76+ xml . Save ( headerLocation ) ;
7477#if PARALLEL
7578 Parallel . ForEach ( TopGroups , group =>
7679 {
@@ -91,12 +94,15 @@ public void WriteXML(string destinationFolder)
9194 public static ElderScrollsPlugin ReadXML ( string sourceFolder )
9295 {
9396 ElderScrollsPlugin outPlug = new ElderScrollsPlugin ( ) ;
94- outPlug . name = Path . GetDirectoryName ( sourceFolder ) ;
95- outPlug . Header = new RecordView ( Path . Combine ( sourceFolder , "Header.xml" ) ) ;
97+ var headerLocation = Path . Combine ( sourceFolder , "Header.xml" ) ;
98+ var xml = XDocument . Load ( headerLocation ) ;
99+ outPlug . FileName = xml . Element ( "Record" ) . Element ( "FileName" ) . Value ;
100+ outPlug . Name = Path . GetDirectoryName ( sourceFolder ) ;
101+ outPlug . Header = new RecordView ( headerLocation ) ;
96102
97103 outPlug . ReadMasters ( ) ;
98104
99- outPlug . Masters . Add ( outPlug . Name ) ;
105+ outPlug . Masters . Add ( outPlug . FileName ) ;
100106
101107 foreach ( var folder in Directory . EnumerateDirectories ( sourceFolder , "*.*" , SearchOption . TopDirectoryOnly ) )
102108 {
@@ -129,7 +135,8 @@ public void WriteBinary(ESPWriter writer)
129135
130136 public void ReadBinary ( string file )
131137 {
132- name = Path . GetFileNameWithoutExtension ( file ) ;
138+ FileName = Path . GetFileName ( file ) ;
139+ Name = Path . GetFileNameWithoutExtension ( file ) ;
133140 FileInfo fi = new FileInfo ( file ) ;
134141 mmf = MemoryMappedFile . CreateFromFile ( file , FileMode . Open , Path . GetFileNameWithoutExtension ( file ) , fi . Length , MemoryMappedFileAccess . Read ) ;
135142
@@ -142,7 +149,7 @@ public void ReadBinary(string file)
142149
143150 ReadMasters ( ) ;
144151
145- Masters . Add ( Name ) ;
152+ Masters . Add ( FileName ) ;
146153
147154 while ( reader . BaseStream . Position < reader . BaseStream . Length )
148155 {
@@ -200,7 +207,7 @@ protected void ReadMasters()
200207 {
201208 foreach ( var masterData in headRec . MasterFiles )
202209 {
203- ElderScrollsPlugin master = ElderScrollsPlugin . LoadedPlugins . FirstOrDefault ( esp => esp . Name == masterData . FileName . Value ) ;
210+ ElderScrollsPlugin master = ElderScrollsPlugin . LoadedPlugins . FirstOrDefault ( esp => esp . FileName == masterData . FileName . Value ) ;
204211
205212 if ( master == null )
206213 {
0 commit comments