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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.Data.WindowsInstaller
{
using System;
using System.IO;
using System.Xml;
/// <summary>
/// Pdb generated by the binder.
/// </summary>
public sealed class Pdb
{
public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixpdb";
private static readonly Version CurrentVersion = new Version("4.0.0.0");
/// <summary>
/// Gets or sets the output that is a part of this pdb.
/// </summary>
/// <value>Type of the output.</value>
public Output Output { get; set; }
/// <summary>
/// Loads a pdb from a path on disk.
/// </summary>
/// <param name="path">Path to pdb file saved on disk.</param>
/// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
/// <returns>Pdb pdb.</returns>
public static Pdb Load(string path, bool suppressVersionCheck)
{
using (FileStream stream = File.OpenRead(path))
using (FileStructure fs = FileStructure.Read(stream))
{
if (FileFormat.Wixpdb != fs.FileFormat)
{
throw new WixUnexpectedFileFormatException(path, FileFormat.Wixpdb, fs.FileFormat);
}
Uri uri = new Uri(Path.GetFullPath(path));
using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri))
{
try
{
reader.MoveToContent();
return Pdb.Read(reader, suppressVersionCheck);
}
catch (XmlException xe)
{
throw new WixCorruptFileException(path, fs.FileFormat, xe);
}
}
}
}
/// <summary>
/// Saves a pdb to a path on disk.
/// </summary>
/// <param name="path">Path to save pdb file to on disk.</param>
public void Save(string path)
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));
using (FileStream stream = File.Create(path))
using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null))
using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream()))
{
writer.WriteStartDocument();
this.Write(writer);
writer.WriteEndDocument();
}
}
/// <summary>
/// Processes an XmlReader and builds up the pdb object.
/// </summary>
/// <param name="reader">Reader to get data from.</param>
/// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
/// <returns>The Pdb represented by the Xml.</returns>
internal static Pdb Read(XmlReader reader, bool suppressVersionCheck)
{
if ("wixPdb" != reader.LocalName)
{
throw new XmlException();
}
bool empty = reader.IsEmptyElement;
Pdb pdb = new Pdb();
Version version = null;
while (reader.MoveToNextAttribute())
{
switch (reader.LocalName)
{
case "version":
version = new Version(reader.Value);
break;
}
}
if (!suppressVersionCheck && null != version && !Pdb.CurrentVersion.Equals(version))
{
throw new WixException(ErrorMessages.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), Pdb.CurrentVersion.ToString()));
}
// loop through the rest of the pdb building up the Output object
if (!empty)
{
bool done = false;
// loop through all the fields in a row
while (!done && reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case "wixOutput":
pdb.Output = Output.Read(reader, suppressVersionCheck);
break;
default:
throw new XmlException();
}
break;
case XmlNodeType.EndElement:
done = true;
break;
}
}
if (!done)
{
throw new XmlException();
}
}
return pdb;
}
/// <summary>
/// Persists a pdb in an XML format.
/// </summary>
/// <param name="writer">XmlWriter where the Pdb should persist itself as XML.</param>
internal void Write(XmlWriter writer)
{
writer.WriteStartElement("wixPdb", XmlNamespaceUri);
writer.WriteAttributeString("version", Pdb.CurrentVersion.ToString());
this.Output.Write(writer);
writer.WriteEndElement();
}
}
}
|