diff options
| author | Rob Mensching <rob@firegiant.com> | 2022-10-12 22:01:55 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2022-10-14 20:13:50 -0700 |
| commit | 07b3d459ea0a45cbef29b98d283edafbab26462a (patch) | |
| tree | 1e834882038ba3862f8acb7b60e7a4bfaef793fd /src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs | |
| parent | 5567239a9411aac769a34f2c65b80a523a577ad7 (diff) | |
| download | wix-07b3d459ea0a45cbef29b98d283edafbab26462a.tar.gz wix-07b3d459ea0a45cbef29b98d283edafbab26462a.tar.bz2 wix-07b3d459ea0a45cbef29b98d283edafbab26462a.zip | |
Normalize ToolsetTask implementation to call wix.exe and heat.exe
Share the ToolsetTask implementation that can find .NET Core and
.NET Framework with multiple architectures.
Fixes 6951
Diffstat (limited to 'src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs')
| -rw-r--r-- | src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs b/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs new file mode 100644 index 00000000..442fedd6 --- /dev/null +++ b/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs | |||
| @@ -0,0 +1,57 @@ | |||
| 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.BaseBuildTasks | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | |||
| 8 | /// <summary> | ||
| 9 | /// Contains helper methods on searching for files | ||
| 10 | /// </summary> | ||
| 11 | public static class FileSearchHelperMethods | ||
| 12 | { | ||
| 13 | /// <summary> | ||
| 14 | /// Searches for the existence of a file in multiple directories. | ||
| 15 | /// Search is satisfied if default file path is valid and exists. If not, | ||
| 16 | /// file name is extracted from default path and combined with each of the directories | ||
| 17 | /// looking to see if it exists. If not found, input default path is returned. | ||
| 18 | /// </summary> | ||
| 19 | /// <param name="directories">Array of directories to look in, without filenames in them</param> | ||
| 20 | /// <param name="defaultFullPath">Default path - to use if not found</param> | ||
| 21 | /// <returns>File path if file found. Empty string if not found</returns> | ||
| 22 | public static string SearchFilePaths(string[] directories, string defaultFullPath) | ||
| 23 | { | ||
| 24 | if (String.IsNullOrEmpty(defaultFullPath)) | ||
| 25 | { | ||
| 26 | return String.Empty; | ||
| 27 | } | ||
| 28 | |||
| 29 | if (File.Exists(defaultFullPath)) | ||
| 30 | { | ||
| 31 | return defaultFullPath; | ||
| 32 | } | ||
| 33 | |||
| 34 | if (directories == null) | ||
| 35 | { | ||
| 36 | return String.Empty; | ||
| 37 | } | ||
| 38 | |||
| 39 | var fileName = Path.GetFileName(defaultFullPath); | ||
| 40 | foreach (var currentPath in directories) | ||
| 41 | { | ||
| 42 | if (String.IsNullOrWhiteSpace(currentPath)) | ||
| 43 | { | ||
| 44 | continue; | ||
| 45 | } | ||
| 46 | |||
| 47 | var path = Path.Combine(currentPath, fileName); | ||
| 48 | if (File.Exists(path)) | ||
| 49 | { | ||
| 50 | return path; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | return String.Empty; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
