aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs19
-rw-r--r--src/api/wix/WixToolset.Extensibility/Services/ILayoutServices.cs30
-rw-r--r--src/wix/WixToolset.Core/ExtensibilityServices/BackendHelper.cs62
-rw-r--r--src/wix/WixToolset.Core/ExtensibilityServices/LayoutServices.cs74
-rw-r--r--src/wix/WixToolset.Core/WixToolsetServiceProvider.cs1
5 files changed, 108 insertions, 78 deletions
diff --git a/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs
index 5c4d9a68..29b8f8e6 100644
--- a/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs
+++ b/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs
@@ -12,7 +12,7 @@ namespace WixToolset.Extensibility.Services
12 /// <summary> 12 /// <summary>
13 /// Interface provided to help backend extensions. 13 /// Interface provided to help backend extensions.
14 /// </summary> 14 /// </summary>
15 public interface IBackendHelper 15 public interface IBackendHelper : ILayoutServices
16 { 16 {
17 /// <summary> 17 /// <summary>
18 /// Creates a file facade from a <c>FileSymbol</c> and possible <c>AssemblySymbol</c>. 18 /// Creates a file facade from a <c>FileSymbol</c> and possible <c>AssemblySymbol</c>.
@@ -37,15 +37,6 @@ namespace WixToolset.Extensibility.Services
37 IFileFacade CreateFileFacadeFromMergeModule(FileSymbol fileSymbol); 37 IFileFacade CreateFileFacadeFromMergeModule(FileSymbol fileSymbol);
38 38
39 /// <summary> 39 /// <summary>
40 /// Creates a file transfer and marks it redundant if the source and destination are identical.
41 /// </summary>
42 /// <param name="source">Source for the file transfer.</param>
43 /// <param name="destination">Destination for the file transfer.</param>
44 /// <param name="move">Indicates whether to move or copy the source file.</param>
45 /// <param name="sourceLineNumbers">Optional source line numbers that requested the file transfer.</param>
46 IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null);
47
48 /// <summary>
49 /// Creates a MSI compatible GUID. 40 /// Creates a MSI compatible GUID.
50 /// </summary> 41 /// </summary>
51 /// <returns>Creates an uppercase GUID with braces.</returns> 42 /// <returns>Creates an uppercase GUID with braces.</returns>
@@ -171,13 +162,5 @@ namespace WixToolset.Extensibility.Services
171 /// Thus the returned array will always be of length 4. 162 /// Thus the returned array will always be of length 4.
172 /// </remarks> 163 /// </remarks>
173 string[] SplitMsiFileName(string value); 164 string[] SplitMsiFileName(string value);
174
175 /// <summary>
176 /// Creates a tracked file.
177 /// </summary>
178 /// <param name="path">Destination path for the build output.</param>
179 /// <param name="type">Type of tracked file to create.</param>
180 /// <param name="sourceLineNumbers">Optional source line numbers that requested the tracked file.</param>
181 ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null);
182 } 165 }
183} 166}
diff --git a/src/api/wix/WixToolset.Extensibility/Services/ILayoutServices.cs b/src/api/wix/WixToolset.Extensibility/Services/ILayoutServices.cs
new file mode 100644
index 00000000..79f89d29
--- /dev/null
+++ b/src/api/wix/WixToolset.Extensibility/Services/ILayoutServices.cs
@@ -0,0 +1,30 @@
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
3namespace WixToolset.Extensibility.Services
4{
5 using WixToolset.Data;
6 using WixToolset.Extensibility.Data;
7
8 /// <summary>
9 /// Interface provided to track files for use by layout later.
10 /// </summary>
11 public interface ILayoutServices
12 {
13 /// <summary>
14 /// Creates a file transfer and marks it redundant if the source and destination are identical.
15 /// </summary>
16 /// <param name="source">Source for the file transfer.</param>
17 /// <param name="destination">Destination for the file transfer.</param>
18 /// <param name="move">Indicates whether to move or copy the source file.</param>
19 /// <param name="sourceLineNumbers">Optional source line numbers that requested the file transfer.</param>
20 IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null);
21
22 /// <summary>
23 /// Creates a tracked file.
24 /// </summary>
25 /// <param name="path">Destination path for the build output.</param>
26 /// <param name="type">Type of tracked file to create.</param>
27 /// <param name="sourceLineNumbers">Optional source line numbers that requested the tracked file.</param>
28 ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null);
29 }
30}
diff --git a/src/wix/WixToolset.Core/ExtensibilityServices/BackendHelper.cs b/src/wix/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
index cfa78623..9d657e1a 100644
--- a/src/wix/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
+++ b/src/wix/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
@@ -4,7 +4,6 @@ namespace WixToolset.Core.ExtensibilityServices
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO;
8 using WixToolset.Core.Bind; 7 using WixToolset.Core.Bind;
9 using WixToolset.Data; 8 using WixToolset.Data;
10 using WixToolset.Data.Symbols; 9 using WixToolset.Data.Symbols;
@@ -12,17 +11,12 @@ namespace WixToolset.Core.ExtensibilityServices
12 using WixToolset.Extensibility.Data; 11 using WixToolset.Extensibility.Data;
13 using WixToolset.Extensibility.Services; 12 using WixToolset.Extensibility.Services;
14 13
15 internal class BackendHelper : IBackendHelper 14 internal class BackendHelper : LayoutServices, IBackendHelper
16 { 15 {
17 private static readonly string[] ReservedFileNames = { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" }; 16 public BackendHelper(IServiceProvider serviceProvider) : base(serviceProvider)
18
19 public BackendHelper(IServiceProvider serviceProvider)
20 { 17 {
21 this.Messaging = serviceProvider.GetService<IMessaging>();
22 } 18 }
23 19
24 private IMessaging Messaging { get; }
25
26 public IFileFacade CreateFileFacade(FileSymbol file, AssemblySymbol assembly) 20 public IFileFacade CreateFileFacade(FileSymbol file, AssemblySymbol assembly)
27 { 21 {
28 return new FileFacade(file, assembly); 22 return new FileFacade(file, assembly);
@@ -38,22 +32,6 @@ namespace WixToolset.Core.ExtensibilityServices
38 return new FileFacade(true, fileSymbol); 32 return new FileFacade(true, fileSymbol);
39 } 33 }
40 34
41 public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null)
42 {
43 var sourceFullPath = this.GetValidatedFullPath(sourceLineNumbers, source);
44
45 var destinationFullPath = this.GetValidatedFullPath(sourceLineNumbers, destination);
46
47 return (String.IsNullOrEmpty(sourceFullPath) || String.IsNullOrEmpty(destinationFullPath)) ? null : new FileTransfer
48 {
49 Source = sourceFullPath,
50 Destination = destinationFullPath,
51 Move = move,
52 SourceLineNumbers = sourceLineNumbers,
53 Redundant = String.Equals(sourceFullPath, destinationFullPath, StringComparison.OrdinalIgnoreCase)
54 };
55 }
56
57 public string CreateGuid() 35 public string CreateGuid()
58 { 36 {
59 return Common.GenerateGuid(); 37 return Common.GenerateGuid();
@@ -112,11 +90,6 @@ namespace WixToolset.Core.ExtensibilityServices
112 return Common.GetNames(value); 90 return Common.GetNames(value);
113 } 91 }
114 92
115 public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null)
116 {
117 return new TrackedFile(path, type, sourceLineNumbers);
118 }
119
120 public bool IsValidBinderVariable(string variable) 93 public bool IsValidBinderVariable(string variable)
121 { 94 {
122 return Common.IsValidBinderVariable(variable); 95 return Common.IsValidBinderVariable(variable);
@@ -141,36 +114,5 @@ namespace WixToolset.Core.ExtensibilityServices
141 { 114 {
142 return Common.IsValidShortFilename(filename, allowWildcards); 115 return Common.IsValidShortFilename(filename, allowWildcards);
143 } 116 }
144
145 private string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path)
146 {
147 try
148 {
149 var result = Path.GetFullPath(path);
150
151 var filename = Path.GetFileName(result);
152
153 foreach (var reservedName in ReservedFileNames)
154 {
155 if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase))
156 {
157 this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
158 return null;
159 }
160 }
161
162 return result;
163 }
164 catch (ArgumentException)
165 {
166 this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
167 }
168 catch (PathTooLongException)
169 {
170 this.Messaging.Write(ErrorMessages.PathTooLong(sourceLineNumbers, path));
171 }
172
173 return null;
174 }
175 } 117 }
176} 118}
diff --git a/src/wix/WixToolset.Core/ExtensibilityServices/LayoutServices.cs b/src/wix/WixToolset.Core/ExtensibilityServices/LayoutServices.cs
new file mode 100644
index 00000000..84b43892
--- /dev/null
+++ b/src/wix/WixToolset.Core/ExtensibilityServices/LayoutServices.cs
@@ -0,0 +1,74 @@
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
3namespace WixToolset.Core.ExtensibilityServices
4{
5 using System;
6 using System.IO;
7 using WixToolset.Data;
8 using WixToolset.Extensibility.Data;
9 using WixToolset.Extensibility.Services;
10
11 internal class LayoutServices : ILayoutServices
12 {
13 private static readonly string[] ReservedFileNames = { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
14
15 public LayoutServices(IServiceProvider serviceProvider)
16 {
17 this.Messaging = serviceProvider.GetService<IMessaging>();
18 }
19
20 protected IMessaging Messaging { get; }
21
22 public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null)
23 {
24 var sourceFullPath = this.GetValidatedFullPath(sourceLineNumbers, source);
25
26 var destinationFullPath = this.GetValidatedFullPath(sourceLineNumbers, destination);
27
28 return (String.IsNullOrEmpty(sourceFullPath) || String.IsNullOrEmpty(destinationFullPath)) ? null : new FileTransfer
29 {
30 Source = sourceFullPath,
31 Destination = destinationFullPath,
32 Move = move,
33 SourceLineNumbers = sourceLineNumbers,
34 Redundant = String.Equals(sourceFullPath, destinationFullPath, StringComparison.OrdinalIgnoreCase)
35 };
36 }
37
38 public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null)
39 {
40 return new TrackedFile(path, type, sourceLineNumbers);
41 }
42
43 protected string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path)
44 {
45 try
46 {
47 var result = Path.GetFullPath(path);
48
49 var filename = Path.GetFileName(result);
50
51 foreach (var reservedName in ReservedFileNames)
52 {
53 if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase))
54 {
55 this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
56 return null;
57 }
58 }
59
60 return result;
61 }
62 catch (ArgumentException)
63 {
64 this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
65 }
66 catch (PathTooLongException)
67 {
68 this.Messaging.Write(ErrorMessages.PathTooLong(sourceLineNumbers, path));
69 }
70
71 return null;
72 }
73 }
74}
diff --git a/src/wix/WixToolset.Core/WixToolsetServiceProvider.cs b/src/wix/WixToolset.Core/WixToolsetServiceProvider.cs
index 5d700ba0..de89bb73 100644
--- a/src/wix/WixToolset.Core/WixToolsetServiceProvider.cs
+++ b/src/wix/WixToolset.Core/WixToolsetServiceProvider.cs
@@ -23,6 +23,7 @@ namespace WixToolset.Core
23 this.AddService((provider, singletons) => AddSingleton<ISymbolDefinitionCreator>(singletons, new SymbolDefinitionCreator(provider))); 23 this.AddService((provider, singletons) => AddSingleton<ISymbolDefinitionCreator>(singletons, new SymbolDefinitionCreator(provider)));
24 this.AddService((provider, singletons) => AddSingleton<IParseHelper>(singletons, new ParseHelper(provider))); 24 this.AddService((provider, singletons) => AddSingleton<IParseHelper>(singletons, new ParseHelper(provider)));
25 this.AddService((provider, singletons) => AddSingleton<IPreprocessHelper>(singletons, new PreprocessHelper(provider))); 25 this.AddService((provider, singletons) => AddSingleton<IPreprocessHelper>(singletons, new PreprocessHelper(provider)));
26 this.AddService((provider, singletons) => AddSingleton<ILayoutServices>(singletons, new LayoutServices(provider)));
26 this.AddService((provider, singletons) => AddSingleton<IBackendHelper>(singletons, new BackendHelper(provider))); 27 this.AddService((provider, singletons) => AddSingleton<IBackendHelper>(singletons, new BackendHelper(provider)));
27 this.AddService((provider, singletons) => AddSingleton<IPathResolver>(singletons, new PathResolver())); 28 this.AddService((provider, singletons) => AddSingleton<IPathResolver>(singletons, new PathResolver()));
28 this.AddService((provider, singletons) => AddSingleton<IWixBranding>(singletons, new WixBranding())); 29 this.AddService((provider, singletons) => AddSingleton<IWixBranding>(singletons, new WixBranding()));