blob: 189d28a99c2b83d00d1812b7082f87744cab8d3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// 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.
using System;
using System.Collections;
using WixToolset.Dtf.WindowsInstaller;
namespace WixToolset.Dtf.Tools.Inventory
{
public class MsiUtils
{
private static Hashtable productCodesToNames = new Hashtable();
private static Hashtable productNamesToCodes = new Hashtable();
public static string GetProductName(string productCode)
{
string productName = (string) productCodesToNames[productCode];
if(productName == null)
{
productName = new ProductInstallation(productCode).ProductName;
productName = productName.Replace('\\', ' ');
if(productNamesToCodes.Contains(productName))
{
string modifiedProductName = null;
for(int i = 2; i < Int32.MaxValue; i++)
{
modifiedProductName = productName + " [" + i + "]";
if(!productNamesToCodes.Contains(modifiedProductName)) break;
}
productName = modifiedProductName;
}
productCodesToNames[productCode] = productName;
productNamesToCodes[productName] = productCode;
}
return productName;
}
// Assumes GetProductName() has already been called for this product.
public static string GetProductCode(string productName)
{
return (string) productNamesToCodes[productName];
}
private MsiUtils() { }
}
}
|