@joebigelow / wix-1 / commits / d0d48599

Incorporate refactoring of WixToolset.Core assemblies

Rob Mensching committed Oct 18, 2017 at 15:10 UTC d0d48599caf5b5f018b9fdd4ea8f6064d76d2e8b
8 files changed +257 -25
src/WixToolset.Data/Bind/BindResult.cs new
+19
@@ -0,0 +1,19 @@
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.Data.Bind
4 +{
5 + using System.Collections.Generic;
6 +
7 + public class BindResult
8 + {
9 + public BindResult(IEnumerable<FileTransfer> fileTransfers, IEnumerable<string> contentFilePaths)
10 + {
11 + this.FileTransfers = fileTransfers;
12 + this.ContentFilePaths = contentFilePaths;
13 + }
14 +
15 + public IEnumerable<FileTransfer> FileTransfers { get; }
16 +
17 + public IEnumerable<string> ContentFilePaths { get; }
18 + }
19 +}
\ No newline at end of file
src/WixToolset.Data/Bind/BindStage.cs new
+27
@@ -0,0 +1,27 @@
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.Data.Bind
4 +{
5 + /// <summary>
6 + /// Bind stage of a file.. The reason we need this is to change the ResolveFile behavior based on if
7 + /// dynamic bindpath plugin is desirable. We cannot change the signature of ResolveFile since it might
8 + /// break existing implementers which derived from BinderFileManager
9 + /// </summary>
10 + public enum BindStage
11 + {
12 + /// <summary>
13 + /// Normal binding
14 + /// </summary>
15 + Normal,
16 +
17 + /// <summary>
18 + /// Bind the file path of the target build file
19 + /// </summary>
20 + Target,
21 +
22 + /// <summary>
23 + /// Bind the file path of the updated build file
24 + /// </summary>
25 + Updated,
26 + }
27 +}
src/WixToolset.Data/Bind/FileTransfer.cs new
+111
@@ -0,0 +1,111 @@
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.Data.Bind
4 +{
5 + using System;
6 + using System.IO;
7 +
8 + /// <summary>
9 + /// Structure used for all file transfer information.
10 + /// </summary>
11 + public class FileTransfer
12 + {
13 + /// <summary>Source path to file.</summary>
14 + public string Source { get; set; }
15 +
16 + /// <summary>Destination path for file.</summary>
17 + public string Destination { get; set; }
18 +
19 + /// <summary>Flag if file should be moved (optimal).</summary>
20 + public bool Move { get; set; }
21 +
22 + /// <summary>Optional source line numbers where this file transfer orginated.</summary>
23 + public SourceLineNumber SourceLineNumbers { get; set; }
24 +
25 + /// <summary>Optional type of file this transfer is moving or copying.</summary>
26 + public string Type { get; set; }
27 +
28 + /// <summary>Indicates whether the file transer was a built by this build or copied from other some build.</summary>
29 + public bool Built { get; set; }
30 +
31 + /// <summary>Set during layout of media when the file transfer when the source and target resolve to the same path.</summary>
32 + public bool Redundant { get; set; }
33 +
34 + /// <summary>
35 + /// Prefer the TryCreate() method to create FileTransfer objects.
36 + /// </summary>
37 + /// <param name="source">Source path to file.</param>
38 + /// <param name="destination">Destination path for file.</param>
39 + /// <param name="move">File if file should be moved (optimal).</param>
40 + /// <param name="type">Optional type of file this transfer is transferring.</param>
41 + /// <param name="sourceLineNumbers">Optional source line numbers wher this transfer originated.</param>
42 + public FileTransfer(string source, string destination, bool move, string type = null, SourceLineNumber sourceLineNumbers = null)
43 + {
44 + this.Source = source;
45 + this.Destination = destination;
46 + this.Move = move;
47 +
48 + this.Type = type;
49 + this.SourceLineNumbers = sourceLineNumbers;
50 + }
51 +
52 + /// <summary>
53 + /// Creates a file transfer if the source and destination are different.
54 + /// </summary>
55 + /// <param name="source">Source path to file.</param>
56 + /// <param name="destination">Destination path for file.</param>
57 + /// <param name="move">File if file should be moved (optimal).</param>
58 + /// <param name="type">Optional type of file this transfer is transferring.</param>
59 + /// <param name="sourceLineNumbers">Optional source line numbers where this transfer originated.</param>
60 + /// <returns>true if the source and destination are the different, false if no file transfer is created.</returns>
61 + public static bool TryCreate(string source, string destination, bool move, string type, SourceLineNumber sourceLineNumbers, out FileTransfer transfer)
62 + {
63 + string sourceFullPath = GetValidatedFullPath(sourceLineNumbers, source);
64 +
65 + string fileLayoutFullPath = GetValidatedFullPath(sourceLineNumbers, destination);
66 +
67 + // if the current source path (where we know that the file already exists) and the resolved
68 + // path as dictated by the Directory table are not the same, then propagate the file. The
69 + // image that we create may have already been done by some other process other than the linker, so
70 + // there is no reason to copy the files to the resolved source if they are already there.
71 + if (String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase))
72 + {
73 + transfer = null;
74 + return false;
75 + }
76 +
77 + transfer = new FileTransfer(source, destination, move, type, sourceLineNumbers);
78 + return true;
79 + }
80 +
81 + private static string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path)
82 + {
83 + string result;
84 +
85 + try
86 + {
87 + result = Path.GetFullPath(path);
88 +
89 + string filename = Path.GetFileName(result);
90 +
91 + foreach (string reservedName in Common.ReservedFileNames)
92 + {
93 + if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase))
94 + {
95 + throw new WixException(WixDataErrors.InvalidFileName(sourceLineNumbers, path));
96 + }
97 + }
98 + }
99 + catch (System.ArgumentException)
100 + {
101 + throw new WixException(WixDataErrors.InvalidFileName(sourceLineNumbers, path));
102 + }
103 + catch (System.IO.PathTooLongException)
104 + {
105 + throw new WixException(WixDataErrors.PathTooLong(sourceLineNumbers, path));
106 + }
107 +
108 + return result;
109 + }
110 + }
111 +}
src/WixToolset.Data/BindPath.cs new
+60
@@ -0,0 +1,60 @@
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.Data
4 +{
5 + using System;
6 + using WixToolset.Data.Bind;
7 +
8 + /// <summary>
9 + /// Bind path representation.
10 + /// </summary>
11 + public class BindPath
12 + {
13 + /// <summary>
14 + /// Creates an unnamed bind path.
15 + /// </summary>
16 + /// <param name="path">Path for the bind path.</param>
17 + public BindPath(string path) : this(String.Empty, path, BindStage.Normal)
18 + {
19 + }
20 +
21 + /// <summary>
22 + /// Creates a named bind path.
23 + /// </summary>
24 + /// <param name="name">Name of the bind path.</param>
25 + /// <param name="path">Path for the bind path.</param>
26 + /// <param name="stage">Stage for the bind path.</param>
27 + public BindPath(string name, string path, BindStage stage = BindStage.Normal)
28 + {
29 + this.Name = name;
30 + this.Path = path;
31 + this.Stage = stage;
32 + }
33 +
34 + /// <summary>
35 + /// Name of the bind path or String.Empty if the path is unnamed.
36 + /// </summary>
37 + public string Name { get; set; }
38 +
39 + /// <summary>
40 + /// Path for the bind path.
41 + /// </summary>
42 + public string Path { get; set; }
43 +
44 + /// <summary>
45 + /// Stage for the bind path.
46 + /// </summary>
47 + public BindStage Stage { get; set; }
48 +
49 + /// <summary>
50 + /// Parses a normal bind path from its string representation
51 + /// </summary>
52 + /// <param name="bindPath">String representation of bind path that looks like: [name=]path</param>
53 + /// <returns>Parsed normal bind path.</returns>
54 + public static BindPath Parse(string bindPath)
55 + {
56 + string[] namedPath = bindPath.Split(new char[] { '=' }, 2);
57 + return (1 == namedPath.Length) ? new BindPath(namedPath[0]) : new BindPath(namedPath[0], namedPath[1]);
58 + }
59 + }
60 +}
src/WixToolset.Data/Common.cs
+2
@@ -15,6 +15,8 @@ namespace WixToolset.Data
15
16 internal static readonly XNamespace W3SchemaPrefix = "http://www.w3.org/";
17
18 + internal 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" };
19 +
20 private static readonly Regex LegalIdentifierCharacters = new Regex(@"^[_A-Za-z][0-9A-Za-z_\.]*$", RegexOptions.Compiled);
21
22 internal static string GetFileHash(FileInfo fileInfo)
src/WixToolset.Data/ILibraryBinaryFileResolver.cs deleted
-9
@@ -1,9 +0,0 @@
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.Data
4 -{
5 - public interface ILibraryBinaryFileResolver
6 - {
7 - string Resolve(SourceLineNumber sourceLineNumber, string table, string path);
8 - }
9 -}
src/WixToolset.Data/Identifier.cs new
+28
@@ -0,0 +1,28 @@
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.Data
4 +{
5 + /// <summary>
6 + /// Class to define the identifier and access for a row.
7 + /// </summary>
8 + public class Identifier
9 + {
10 + public static Identifier Invalid = new Identifier(null, AccessModifier.Private);
11 +
12 + public Identifier(string id, AccessModifier access)
13 + {
14 + this.Id = id;
15 + this.Access = access;
16 + }
17 +
18 + /// <summary>
19 + /// Access modifier for a row.
20 + /// </summary>
21 + public AccessModifier Access { get; }
22 +
23 + /// <summary>
24 + /// Identifier for the row.
25 + /// </summary>
26 + public string Id { get; }
27 + }
28 +}
src/WixToolset.Data/LocalizedControl.cs
+10 -16
@@ -18,30 +18,27 @@ namespace WixToolset.Data
18 this.Text = text;
19 }
20
21 - public string Dialog { get; set; }
21 + public string Dialog { get; }
22
23 - public string Control { get; set; }
23 + public string Control { get; }
24
25 - public int X { get; private set; }
25 + public int X { get; }
26
27 - public int Y { get; private set; }
27 + public int Y { get; }
28
29 - public int Width { get; private set; }
29 + public int Width { get; }
30
31 - public int Height { get; private set; }
31 + public int Height { get; }
32
33 - public int Attributes { get; private set; }
33 + public int Attributes { get; }
34
35 - public string Text { get; private set; }
35 + public string Text { get; }
36
37 /// <summary>
38 /// Get key for a localized control.
39 /// </summary>
40 /// <returns>The localized control id.</returns>
41 - public string GetKey()
42 - {
43 - return LocalizedControl.GetKey(this.Dialog, this.Control);
44 - }
41 + public string GetKey() => LocalizedControl.GetKey(this.Dialog, this.Control);
42
43 /// <summary>
44 /// Get key for a localized control.
@@ -49,9 +46,6 @@ namespace WixToolset.Data
46 /// <param name="dialog">The optional id of the control's dialog.</param>
47 /// <param name="control">The id of the control.</param>
48 /// <returns>The localized control id.</returns>
52 - public static string GetKey(string dialog, string control)
53 - {
54 - return String.Concat(String.IsNullOrEmpty(dialog) ? String.Empty : dialog, "/", String.IsNullOrEmpty(control) ? String.Empty : control);
55 - }
49 + public static string GetKey(string dialog, string control) => String.Concat(dialog, "/", control);
50 }
51 }