main
cs 139 lines 4.75 KB
Raw
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.Core.ExtensibilityServices
4 {
5 using System;
6 using System.Collections.Generic;
7 using WixToolset.Core.Bind;
8 using WixToolset.Data;
9 using WixToolset.Extensibility.Data;
10 using WixToolset.Extensibility.Services;
11 using WixToolset.Versioning;
12
13 internal class BackendHelper : LayoutServices, IBackendHelper
14 {
15 public BackendHelper(IServiceProvider serviceProvider) : base(serviceProvider)
16 {
17 }
18
19 public string CreateGuid()
20 {
21 return Common.GenerateGuid();
22 }
23
24 public string CreateGuid(Guid namespaceGuid, string value)
25 {
26 return Uuid.NewUuid(namespaceGuid, value).ToString("B").ToUpperInvariant();
27 }
28
29 public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name)
30 {
31 return new ResolvedDirectory
32 {
33 DirectoryParent = directoryParent,
34 Name = name
35 };
36 }
37
38 public IReadOnlyList<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles)
39 {
40 var command = new ExtractEmbeddedFilesCommand(this, embeddedFiles);
41 command.Execute();
42
43 return command.TrackedFiles;
44 }
45
46 public string GenerateIdentifier(string prefix, params string[] args)
47 {
48 return Common.GenerateIdentifier(prefix, args);
49 }
50
51 public int GetValidCodePage(string value, bool allowNoChange = false, bool onlyAnsi = false, SourceLineNumber sourceLineNumbers = null)
52 {
53 return Common.GetValidCodePage(value, allowNoChange, onlyAnsi, sourceLineNumbers);
54 }
55
56 public string GetMsiFileName(string value, bool source, bool longName)
57 {
58 return Common.GetName(value, source, longName);
59 }
60
61 public void ResolveDelayedFields(IEnumerable<IDelayedField> delayedFields, Dictionary<string, string> variableCache)
62 {
63 var command = new ResolveDelayedFieldsCommand(this.Messaging, delayedFields, variableCache);
64 command.Execute();
65 }
66
67 public string[] SplitMsiFileName(string value)
68 {
69 return Common.GetNames(value);
70 }
71
72 public bool IsValidBinderVariable(string variable)
73 {
74 return Common.IsValidBinderVariable(variable);
75 }
76
77 public bool IsValidFourPartVersion(string version)
78 {
79 return Common.IsValidFourPartVersion(version);
80 }
81
82 public bool IsValidMsiProductVersion(string version)
83 {
84 return Common.IsValidMsiProductVersion(version);
85 }
86
87 public bool IsValidWixVersion(string version)
88 {
89 return WixVersion.TryParse(version, out _);
90 }
91
92 public bool IsValidIdentifier(string id)
93 {
94 return Common.IsIdentifier(id);
95 }
96
97 public bool IsValidLongFilename(string filename, bool allowWildcards, bool allowRelative)
98 {
99 return Common.IsValidLongFilename(filename, allowWildcards, allowRelative);
100 }
101
102 public bool IsValidShortFilename(string filename, bool allowWildcards)
103 {
104 return Common.IsValidShortFilename(filename, allowWildcards);
105 }
106
107 public bool TryParseFourPartVersion(string version, out string parsedVersion)
108 {
109 if (WixVersion.TryParse(version, out var wixVersion) && wixVersion.HasMajor && wixVersion.Major < 65536 && wixVersion.Minor < 65536 && wixVersion.Patch < 65536 && wixVersion.Revision < 65536)
110 {
111 parsedVersion = $"{wixVersion.Major}.{wixVersion.Minor}.{wixVersion.Patch}.{wixVersion.Revision}";
112 return true;
113 }
114
115 parsedVersion = null;
116 return false;
117 }
118
119 public bool TryParseMsiProductVersion(string version, bool strict, out string parsedVersion)
120 {
121 if (WixVersion.TryParse(version, out var wixVersion) && wixVersion.HasMajor && wixVersion.Major < 256 && wixVersion.Minor < 256 && wixVersion.Patch < 65536 && wixVersion.Labels == null && String.IsNullOrEmpty(wixVersion.Metadata))
122 {
123 if (strict)
124 {
125 parsedVersion = $"{wixVersion.Major}.{wixVersion.Minor}.{wixVersion.Patch}";
126 }
127 else
128 {
129 parsedVersion = wixVersion.Prefix.HasValue ? version.Substring(1) : version;
130 }
131
132 return true;
133 }
134
135 parsedVersion = null;
136 return false;
137 }
138 }
139 }