aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/Common.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Data/Common.cs')
-rw-r--r--src/WixToolset.Data/Common.cs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/WixToolset.Data/Common.cs b/src/WixToolset.Data/Common.cs
new file mode 100644
index 00000000..f01b4591
--- /dev/null
+++ b/src/WixToolset.Data/Common.cs
@@ -0,0 +1,53 @@
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.Data
4{
5 using System;
6 using System.IO;
7 using System.Security.Cryptography;
8 using System.Text;
9 using System.Text.RegularExpressions;
10 using System.Xml.Linq;
11
12 internal static class Common
13 {
14 public const int IntegerNotSet = int.MinValue;
15
16 internal static readonly XNamespace W3SchemaPrefix = "http://www.w3.org/";
17
18 private static readonly Regex LegalIdentifierCharacters = new Regex(@"^[_A-Za-z][0-9A-Za-z_\.]*$", RegexOptions.Compiled);
19
20 internal static string GetFileHash(FileInfo fileInfo)
21 {
22 byte[] hashBytes;
23 using (SHA1Managed managed = new SHA1Managed())
24 {
25 using (FileStream stream = fileInfo.OpenRead())
26 {
27 hashBytes = managed.ComputeHash(stream);
28 }
29 }
30
31 StringBuilder sb = new StringBuilder();
32 for (int i = 0; i < hashBytes.Length; i++)
33 {
34 sb.AppendFormat("{0:X2}", hashBytes[i]);
35 }
36
37 return sb.ToString();
38 }
39
40 public static bool IsIdentifier(string value)
41 {
42 if (!String.IsNullOrEmpty(value))
43 {
44 if (LegalIdentifierCharacters.IsMatch(value))
45 {
46 return true;
47 }
48 }
49
50 return false;
51 }
52 }
53}