From 7d302ba01db5b2a9e255cfade17b1c3d687fdee2 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 19 Oct 2018 02:57:04 -0700 Subject: Minor code cleanup/reorganization --- src/WixToolset.Core.WindowsInstaller/Decompiler.cs | 2 +- .../CommandLine/ParseCommandLine.cs | 22 +++--- src/WixToolset.Core/Decompiler.cs | 7 -- .../ExtensibilityServices/FileTransfer.cs | 20 ++++++ .../ExtensibilityServices/TrackedFile.cs | 26 +++++++ src/WixToolset.Core/ExtensibilityServices/Uuid.cs | 82 ++++++++++++++++++++++ src/WixToolset.Core/FileTransfer.cs | 20 ------ src/WixToolset.Core/TrackedFile.cs | 26 ------- src/WixToolset.Core/Uuid.cs | 82 ---------------------- src/WixToolset.Core/WixToolsetServiceProvider.cs | 2 +- 10 files changed, 144 insertions(+), 145 deletions(-) create mode 100644 src/WixToolset.Core/ExtensibilityServices/FileTransfer.cs create mode 100644 src/WixToolset.Core/ExtensibilityServices/TrackedFile.cs create mode 100644 src/WixToolset.Core/ExtensibilityServices/Uuid.cs delete mode 100644 src/WixToolset.Core/FileTransfer.cs delete mode 100644 src/WixToolset.Core/TrackedFile.cs delete mode 100644 src/WixToolset.Core/Uuid.cs (limited to 'src') diff --git a/src/WixToolset.Core.WindowsInstaller/Decompiler.cs b/src/WixToolset.Core.WindowsInstaller/Decompiler.cs index 8136bf00..c5d68db3 100644 --- a/src/WixToolset.Core.WindowsInstaller/Decompiler.cs +++ b/src/WixToolset.Core.WindowsInstaller/Decompiler.cs @@ -1,6 +1,6 @@ // 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 +namespace WixToolset.Core.WindowsInstaller { using System; using System.Collections; diff --git a/src/WixToolset.Core/CommandLine/ParseCommandLine.cs b/src/WixToolset.Core/CommandLine/ParseCommandLine.cs index 7d0dcbd8..3cf6e032 100644 --- a/src/WixToolset.Core/CommandLine/ParseCommandLine.cs +++ b/src/WixToolset.Core/CommandLine/ParseCommandLine.cs @@ -25,11 +25,14 @@ namespace WixToolset.Core.CommandLine this.ErrorArgument = errorArgument; } - public bool IsSwitch(string arg) => !String.IsNullOrEmpty(arg) && ('/' == arg[0] || '-' == arg[0]); + public bool IsSwitch(string arg) + { + return !String.IsNullOrEmpty(arg) && ('/' == arg[0] || '-' == arg[0]); + } public void GetArgumentAsFilePathOrError(string argument, string fileType, IList paths) { - foreach (var path in GetFiles(argument, fileType)) + foreach (var path in this.GetFiles(argument, fileType)) { paths.Add(path); } @@ -60,7 +63,7 @@ namespace WixToolset.Core.CommandLine public string GetNextArgumentAsDirectoryOrError(string commandLineSwitch) { - if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) + if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) { return directory; } @@ -71,7 +74,7 @@ namespace WixToolset.Core.CommandLine public bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList directories) { - if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) + if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) { directories.Add(directory); return true; @@ -96,7 +99,7 @@ namespace WixToolset.Core.CommandLine { if (this.TryGetNextNonSwitchArgumentOrError(out var arg)) { - foreach (var path in GetFiles(arg, fileType)) + foreach (var path in this.GetFiles(arg, fileType)) { paths.Add(path); } @@ -125,7 +128,10 @@ namespace WixToolset.Core.CommandLine return result; } - private static bool IsValidArg(string arg) => !(String.IsNullOrEmpty(arg) || '/' == arg[0] || '-' == arg[0]); + private static bool IsValidArg(string arg) + { + return !(String.IsNullOrEmpty(arg) || '/' == arg[0] || '-' == arg[0]); + } private static bool TryDequeue(Queue q, out string arg) { @@ -194,8 +200,8 @@ namespace WixToolset.Core.CommandLine } // Convert alternate directory separators to the standard one. - string filePath = searchPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - int lastSeparator = filePath.LastIndexOf(Path.DirectorySeparatorChar); + var filePath = searchPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + var lastSeparator = filePath.LastIndexOf(Path.DirectorySeparatorChar); var files = new string[0]; try diff --git a/src/WixToolset.Core/Decompiler.cs b/src/WixToolset.Core/Decompiler.cs index 5f14dfca..45cfbea0 100644 --- a/src/WixToolset.Core/Decompiler.cs +++ b/src/WixToolset.Core/Decompiler.cs @@ -3,7 +3,6 @@ namespace WixToolset.Core { using System; - using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -18,12 +17,6 @@ namespace WixToolset.Core this.ServiceProvider = serviceProvider; } - public OutputType DecompileType { get; set; } - - public string IntermediateFolder { get; set; } - - public string OutputPath { get; set; } - public IServiceProvider ServiceProvider { get; } public BindResult Decompile(IDecompileContext context) diff --git a/src/WixToolset.Core/ExtensibilityServices/FileTransfer.cs b/src/WixToolset.Core/ExtensibilityServices/FileTransfer.cs new file mode 100644 index 00000000..2cad7cce --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/FileTransfer.cs @@ -0,0 +1,20 @@ +// 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.Core.ExtensibilityServices +{ + using WixToolset.Data; + using WixToolset.Extensibility.Data; + + internal class FileTransfer : IFileTransfer + { + public string Source { get; set; } + + public string Destination { get; set; } + + public bool Move { get; set; } + + public SourceLineNumber SourceLineNumbers { get; set; } + + public bool Redundant { get; set; } + } +} diff --git a/src/WixToolset.Core/ExtensibilityServices/TrackedFile.cs b/src/WixToolset.Core/ExtensibilityServices/TrackedFile.cs new file mode 100644 index 00000000..028cddbf --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/TrackedFile.cs @@ -0,0 +1,26 @@ +// 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.Core.ExtensibilityServices +{ + using WixToolset.Data; + using WixToolset.Extensibility.Data; + + internal class TrackedFile : ITrackedFile + { + public TrackedFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers) + { + this.Path = path; + this.Type = type; + this.SourceLineNumbers = sourceLineNumbers; + this.Clean = (type == TrackedFileType.Intermediate || type == TrackedFileType.Final); + } + + public bool Clean { get; set; } + + public string Path { get; set; } + + public SourceLineNumber SourceLineNumbers { get; set; } + + public TrackedFileType Type { get; set; } + } +} diff --git a/src/WixToolset.Core/ExtensibilityServices/Uuid.cs b/src/WixToolset.Core/ExtensibilityServices/Uuid.cs new file mode 100644 index 00000000..a5692b71 --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/Uuid.cs @@ -0,0 +1,82 @@ +// 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.Core.ExtensibilityServices +{ + using System; + using System.Net; + using System.Security.Cryptography; + using System.Text; + + /// + /// Implementation of RFC 4122 - A Universally Unique Identifier (UUID) URN Namespace. + /// + internal static class Uuid + { + /// + /// Creates a version 3 name-based UUID. + /// + /// The namespace UUID. + /// The value. + /// Flag to say to use MD5 instead of better SHA1. + /// The UUID for the given namespace and value. + public static Guid NewUuid(Guid namespaceGuid, string value) + { + byte[] namespaceBytes = namespaceGuid.ToByteArray(); + short uuidVersion = (short)0x5000; + + // get the fields of the guid which are in host byte ordering + int timeLow = BitConverter.ToInt32(namespaceBytes, 0); + short timeMid = BitConverter.ToInt16(namespaceBytes, 4); + short timeHiAndVersion = BitConverter.ToInt16(namespaceBytes, 6); + + // convert to network byte ordering + timeLow = IPAddress.HostToNetworkOrder(timeLow); + timeMid = IPAddress.HostToNetworkOrder(timeMid); + timeHiAndVersion = IPAddress.HostToNetworkOrder(timeHiAndVersion); + + // get the bytes from the value + byte[] valueBytes = Encoding.Unicode.GetBytes(value); + + // fill-in the hash input buffer + byte[] buffer = new byte[namespaceBytes.Length + valueBytes.Length]; + Buffer.BlockCopy(BitConverter.GetBytes(timeLow), 0, buffer, 0, 4); + Buffer.BlockCopy(BitConverter.GetBytes(timeMid), 0, buffer, 4, 2); + Buffer.BlockCopy(BitConverter.GetBytes(timeHiAndVersion), 0, buffer, 6, 2); + Buffer.BlockCopy(namespaceBytes, 8, buffer, 8, 8); + Buffer.BlockCopy(valueBytes, 0, buffer, 16, valueBytes.Length); + + // perform the appropriate hash of the namespace and value + byte[] hash; + using (SHA1 sha1 = SHA1.Create()) + { + hash = sha1.ComputeHash(buffer); + } + + // get the fields of the hash which are in network byte ordering + timeLow = BitConverter.ToInt32(hash, 0); + timeMid = BitConverter.ToInt16(hash, 4); + timeHiAndVersion = BitConverter.ToInt16(hash, 6); + + // convert to network byte ordering + timeLow = IPAddress.NetworkToHostOrder(timeLow); + timeMid = IPAddress.NetworkToHostOrder(timeMid); + timeHiAndVersion = IPAddress.NetworkToHostOrder(timeHiAndVersion); + + // set the version and variant bits + timeHiAndVersion &= 0x0FFF; + timeHiAndVersion += uuidVersion; + hash[8] &= 0x3F; + hash[8] |= 0x80; + + // put back the converted values into a 128-bit value + byte[] guidBits = new byte[16]; + Buffer.BlockCopy(hash, 0, guidBits, 0, 16); + + Buffer.BlockCopy(BitConverter.GetBytes(timeLow), 0, guidBits, 0, 4); + Buffer.BlockCopy(BitConverter.GetBytes(timeMid), 0, guidBits, 4, 2); + Buffer.BlockCopy(BitConverter.GetBytes(timeHiAndVersion), 0, guidBits, 6, 2); + + return new Guid(guidBits); + } + } +} diff --git a/src/WixToolset.Core/FileTransfer.cs b/src/WixToolset.Core/FileTransfer.cs deleted file mode 100644 index 7f9ed0f3..00000000 --- a/src/WixToolset.Core/FileTransfer.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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.Core -{ - using WixToolset.Data; - using WixToolset.Extensibility.Data; - - internal class FileTransfer : IFileTransfer - { - public string Source { get; set; } - - public string Destination { get; set; } - - public bool Move { get; set; } - - public SourceLineNumber SourceLineNumbers { get; set; } - - public bool Redundant { get; set; } - } -} diff --git a/src/WixToolset.Core/TrackedFile.cs b/src/WixToolset.Core/TrackedFile.cs deleted file mode 100644 index 312b09f4..00000000 --- a/src/WixToolset.Core/TrackedFile.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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.Core -{ - using WixToolset.Data; - using WixToolset.Extensibility.Data; - - internal class TrackedFile : ITrackedFile - { - public TrackedFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers) - { - this.Path = path; - this.Type = type; - this.SourceLineNumbers = sourceLineNumbers; - this.Clean = (type == TrackedFileType.Intermediate || type == TrackedFileType.Final); - } - - public bool Clean { get; set; } - - public string Path { get; set; } - - public SourceLineNumber SourceLineNumbers { get; set; } - - public TrackedFileType Type { get; set; } - } -} diff --git a/src/WixToolset.Core/Uuid.cs b/src/WixToolset.Core/Uuid.cs deleted file mode 100644 index c93d134d..00000000 --- a/src/WixToolset.Core/Uuid.cs +++ /dev/null @@ -1,82 +0,0 @@ -// 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 -{ - using System; - using System.Net; - using System.Security.Cryptography; - using System.Text; - - /// - /// Implementation of RFC 4122 - A Universally Unique Identifier (UUID) URN Namespace. - /// - internal static class Uuid - { - /// - /// Creates a version 3 name-based UUID. - /// - /// The namespace UUID. - /// The value. - /// Flag to say to use MD5 instead of better SHA1. - /// The UUID for the given namespace and value. - public static Guid NewUuid(Guid namespaceGuid, string value) - { - byte[] namespaceBytes = namespaceGuid.ToByteArray(); - short uuidVersion = (short)0x5000; - - // get the fields of the guid which are in host byte ordering - int timeLow = BitConverter.ToInt32(namespaceBytes, 0); - short timeMid = BitConverter.ToInt16(namespaceBytes, 4); - short timeHiAndVersion = BitConverter.ToInt16(namespaceBytes, 6); - - // convert to network byte ordering - timeLow = IPAddress.HostToNetworkOrder(timeLow); - timeMid = IPAddress.HostToNetworkOrder(timeMid); - timeHiAndVersion = IPAddress.HostToNetworkOrder(timeHiAndVersion); - - // get the bytes from the value - byte[] valueBytes = Encoding.Unicode.GetBytes(value); - - // fill-in the hash input buffer - byte[] buffer = new byte[namespaceBytes.Length + valueBytes.Length]; - Buffer.BlockCopy(BitConverter.GetBytes(timeLow), 0, buffer, 0, 4); - Buffer.BlockCopy(BitConverter.GetBytes(timeMid), 0, buffer, 4, 2); - Buffer.BlockCopy(BitConverter.GetBytes(timeHiAndVersion), 0, buffer, 6, 2); - Buffer.BlockCopy(namespaceBytes, 8, buffer, 8, 8); - Buffer.BlockCopy(valueBytes, 0, buffer, 16, valueBytes.Length); - - // perform the appropriate hash of the namespace and value - byte[] hash; - using (SHA1 sha1 = SHA1.Create()) - { - hash = sha1.ComputeHash(buffer); - } - - // get the fields of the hash which are in network byte ordering - timeLow = BitConverter.ToInt32(hash, 0); - timeMid = BitConverter.ToInt16(hash, 4); - timeHiAndVersion = BitConverter.ToInt16(hash, 6); - - // convert to network byte ordering - timeLow = IPAddress.NetworkToHostOrder(timeLow); - timeMid = IPAddress.NetworkToHostOrder(timeMid); - timeHiAndVersion = IPAddress.NetworkToHostOrder(timeHiAndVersion); - - // set the version and variant bits - timeHiAndVersion &= 0x0FFF; - timeHiAndVersion += uuidVersion; - hash[8] &= 0x3F; - hash[8] |= 0x80; - - // put back the converted values into a 128-bit value - byte[] guidBits = new byte[16]; - Buffer.BlockCopy(hash, 0, guidBits, 0, 16); - - Buffer.BlockCopy(BitConverter.GetBytes(timeLow), 0, guidBits, 0, 4); - Buffer.BlockCopy(BitConverter.GetBytes(timeMid), 0, guidBits, 4, 2); - Buffer.BlockCopy(BitConverter.GetBytes(timeHiAndVersion), 0, guidBits, 6, 2); - - return new Guid(guidBits); - } - } -} diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs index 83b9356d..0337f771 100644 --- a/src/WixToolset.Core/WixToolsetServiceProvider.cs +++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs @@ -92,7 +92,7 @@ namespace WixToolset.Core public void AddService(Func, T> creationFunction) where T : class { - AddService(typeof(T), creationFunction); + this.AddService(typeof(T), creationFunction); } private static T AddSingleton(Dictionary singletons, T service) -- cgit v1.2.3-55-g6feb