diff options
Diffstat (limited to 'src/wix/heat/HarvesterCore.cs')
-rw-r--r-- | src/wix/heat/HarvesterCore.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/wix/heat/HarvesterCore.cs b/src/wix/heat/HarvesterCore.cs new file mode 100644 index 00000000..92b34ab0 --- /dev/null +++ b/src/wix/heat/HarvesterCore.cs | |||
@@ -0,0 +1,76 @@ | |||
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.Harvesters | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using WixToolset.Extensibility.Services; | ||
8 | using WixToolset.Harvesters.Extensibility; | ||
9 | |||
10 | /// <summary> | ||
11 | /// The WiX Toolset harvester core. | ||
12 | /// </summary> | ||
13 | internal class HarvesterCore : IHarvesterCore | ||
14 | { | ||
15 | public IMessaging Messaging { get; set; } | ||
16 | |||
17 | public IParseHelper ParseHelper { get; set; } | ||
18 | |||
19 | /// <summary> | ||
20 | /// Gets or sets the value of the extension argument passed to heat. | ||
21 | /// </summary> | ||
22 | /// <value>The extension argument.</value> | ||
23 | public string ExtensionArgument { get; set; } | ||
24 | |||
25 | /// <summary> | ||
26 | /// Gets or sets the value of the root directory that is being harvested. | ||
27 | /// </summary> | ||
28 | /// <value>The root directory being harvested.</value> | ||
29 | public string RootDirectory { get; set; } | ||
30 | |||
31 | /// <summary> | ||
32 | /// Create an identifier based on passed file name | ||
33 | /// </summary> | ||
34 | /// <param name="filename">File name to generate identifer from</param> | ||
35 | /// <returns></returns> | ||
36 | public string CreateIdentifierFromFilename(string filename) | ||
37 | { | ||
38 | return this.ParseHelper.CreateIdentifierFromFilename(filename).Id; | ||
39 | } | ||
40 | |||
41 | /// <summary> | ||
42 | /// Generate an identifier by hashing data from the row. | ||
43 | /// </summary> | ||
44 | /// <param name="prefix">Three letter or less prefix for generated row identifier.</param> | ||
45 | /// <param name="args">Information to hash.</param> | ||
46 | /// <returns>The generated identifier.</returns> | ||
47 | public string GenerateIdentifier(string prefix, params string[] args) | ||
48 | { | ||
49 | return this.ParseHelper.CreateIdentifier(prefix, args).Id; | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Resolves a file's path if the Wix.File.Source value starts with "SourceDir\". | ||
54 | /// </summary> | ||
55 | /// <param name="fileSource">The Wix.File.Source value with "SourceDir\".</param> | ||
56 | /// <returns>The full path of the file.</returns> | ||
57 | public string ResolveFilePath(string fileSource) | ||
58 | { | ||
59 | if (fileSource.StartsWith("SourceDir\\", StringComparison.Ordinal)) | ||
60 | { | ||
61 | string file = Path.GetFullPath(this.RootDirectory); | ||
62 | if (File.Exists(file)) | ||
63 | { | ||
64 | return file; | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | fileSource = fileSource.Substring(10); | ||
69 | fileSource = Path.Combine(Path.GetFullPath(this.RootDirectory), fileSource); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return fileSource; | ||
74 | } | ||
75 | } | ||
76 | } | ||