diff options
Diffstat (limited to 'src/WixToolset.Core/HarvesterCore.cs')
-rw-r--r-- | src/WixToolset.Core/HarvesterCore.cs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/WixToolset.Core/HarvesterCore.cs b/src/WixToolset.Core/HarvesterCore.cs new file mode 100644 index 00000000..66a693f2 --- /dev/null +++ b/src/WixToolset.Core/HarvesterCore.cs | |||
@@ -0,0 +1,103 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset | ||
4 | { | ||
5 | using System; | ||
6 | using System.Diagnostics.CodeAnalysis; | ||
7 | using System.IO; | ||
8 | using WixToolset.Data; | ||
9 | using Wix = WixToolset.Data.Serialize; | ||
10 | |||
11 | /// <summary> | ||
12 | /// The WiX Toolset harvester core. | ||
13 | /// </summary> | ||
14 | public sealed class HarvesterCore : IHarvesterCore | ||
15 | { | ||
16 | private string extensionArgument; | ||
17 | private string rootDirectory; | ||
18 | |||
19 | /// <summary> | ||
20 | /// Gets whether the harvester core encountered an error while processing. | ||
21 | /// </summary> | ||
22 | /// <value>Flag if core encountered an error during processing.</value> | ||
23 | public bool EncounteredError | ||
24 | { | ||
25 | get { return Messaging.Instance.EncounteredError; } | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Gets or sets the value of the extension argument passed to heat. | ||
30 | /// </summary> | ||
31 | /// <value>The extension argument.</value> | ||
32 | public string ExtensionArgument | ||
33 | { | ||
34 | get { return this.extensionArgument; } | ||
35 | set { this.extensionArgument = value; } | ||
36 | } | ||
37 | |||
38 | /// <summary> | ||
39 | /// Gets or sets the value of the root directory that is being harvested. | ||
40 | /// </summary> | ||
41 | /// <value>The root directory being harvested.</value> | ||
42 | public string RootDirectory | ||
43 | { | ||
44 | get { return this.rootDirectory; } | ||
45 | set { this.rootDirectory = value; } | ||
46 | } | ||
47 | |||
48 | /// <summary> | ||
49 | /// Create an identifier based on passed file name | ||
50 | /// </summary> | ||
51 | /// <param name="name">File name to generate identifer from</param> | ||
52 | /// <returns></returns> | ||
53 | public string CreateIdentifierFromFilename(string filename) | ||
54 | { | ||
55 | return Common.GetIdentifierFromName(filename); | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Generate an identifier by hashing data from the row. | ||
60 | /// </summary> | ||
61 | /// <param name="prefix">Three letter or less prefix for generated row identifier.</param> | ||
62 | /// <param name="args">Information to hash.</param> | ||
63 | /// <returns>The generated identifier.</returns> | ||
64 | [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.InvalidOperationException.#ctor(System.String)")] | ||
65 | public string GenerateIdentifier(string prefix, params string[] args) | ||
66 | { | ||
67 | return Common.GenerateIdentifier(prefix, args); | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Sends a message to the message delegate if there is one. | ||
72 | /// </summary> | ||
73 | /// <param name="mea">Message event arguments.</param> | ||
74 | public void OnMessage(MessageEventArgs mea) | ||
75 | { | ||
76 | Messaging.Instance.OnMessage(mea); | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Resolves a file's path if the Wix.File.Source value starts with "SourceDir\". | ||
81 | /// </summary> | ||
82 | /// <param name="fileSource">The Wix.File.Source value with "SourceDir\".</param> | ||
83 | /// <returns>The full path of the file.</returns> | ||
84 | public string ResolveFilePath(string fileSource) | ||
85 | { | ||
86 | if (fileSource.StartsWith("SourceDir\\", StringComparison.Ordinal)) | ||
87 | { | ||
88 | string file = Path.GetFullPath(this.rootDirectory); | ||
89 | if (File.Exists(file)) | ||
90 | { | ||
91 | return file; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | fileSource = fileSource.Substring(10); | ||
96 | fileSource = Path.Combine(Path.GetFullPath(this.rootDirectory), fileSource); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return fileSource; | ||
101 | } | ||
102 | } | ||
103 | } | ||