diff options
Diffstat (limited to 'src/samples/Dtf/Inventory/msiutils.cs')
-rw-r--r-- | src/samples/Dtf/Inventory/msiutils.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/samples/Dtf/Inventory/msiutils.cs b/src/samples/Dtf/Inventory/msiutils.cs new file mode 100644 index 00000000..a345e194 --- /dev/null +++ b/src/samples/Dtf/Inventory/msiutils.cs | |||
@@ -0,0 +1,46 @@ | |||
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 | using System; | ||
4 | using System.Collections; | ||
5 | using WixToolset.Dtf.WindowsInstaller; | ||
6 | |||
7 | |||
8 | namespace WixToolset.Dtf.Samples.Inventory | ||
9 | { | ||
10 | public class MsiUtils | ||
11 | { | ||
12 | private static Hashtable productCodesToNames = new Hashtable(); | ||
13 | private static Hashtable productNamesToCodes = new Hashtable(); | ||
14 | |||
15 | public static string GetProductName(string productCode) | ||
16 | { | ||
17 | string productName = (string) productCodesToNames[productCode]; | ||
18 | if(productName == null) | ||
19 | { | ||
20 | productName = new ProductInstallation(productCode).ProductName; | ||
21 | productName = productName.Replace('\\', ' '); | ||
22 | if(productNamesToCodes.Contains(productName)) | ||
23 | { | ||
24 | string modifiedProductName = null; | ||
25 | for(int i = 2; i < Int32.MaxValue; i++) | ||
26 | { | ||
27 | modifiedProductName = productName + " [" + i + "]"; | ||
28 | if(!productNamesToCodes.Contains(modifiedProductName)) break; | ||
29 | } | ||
30 | productName = modifiedProductName; | ||
31 | } | ||
32 | productCodesToNames[productCode] = productName; | ||
33 | productNamesToCodes[productName] = productCode; | ||
34 | } | ||
35 | return productName; | ||
36 | } | ||
37 | |||
38 | // Assumes GetProductName() has already been called for this product. | ||
39 | public static string GetProductCode(string productName) | ||
40 | { | ||
41 | return (string) productNamesToCodes[productName]; | ||
42 | } | ||
43 | |||
44 | private MsiUtils() { } | ||
45 | } | ||
46 | } | ||