main
cs 49 lines 1.68 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.WindowsInstaller.Bind
4 {
5 using System;
6 using System.IO;
7 using WixToolset.Data.WindowsInstaller;
8
9 internal class DataLoader
10 {
11 public static bool TryLoadWindowsInstallerData(string path, out WindowsInstallerData data)
12 {
13 return TryLoadWindowsInstallerData(path, false, out data);
14 }
15
16 public static bool TryLoadWindowsInstallerData(string path, bool suppressVersionCheck, out WindowsInstallerData data)
17 {
18 data = null;
19
20 var extension = Path.GetExtension(path);
21
22 // If the path is _not_ obviously a Windows Installer database, let's try opening it as
23 // our own data file format.
24 if (!extension.Equals(".msi", StringComparison.OrdinalIgnoreCase) && !extension.Equals(".msm", StringComparison.OrdinalIgnoreCase))
25 {
26 (data, _) = LoadWindowsInstallerDataSafely(path, suppressVersionCheck);
27 }
28
29 return data != null;
30 }
31
32 public static (WindowsInstallerData, Exception) LoadWindowsInstallerDataSafely(string path, bool suppressVersionCheck = false)
33 {
34 WindowsInstallerData data = null;
35 Exception exception = null;
36
37 try
38 {
39 data = WindowsInstallerData.Load(path, suppressVersionCheck);
40 }
41 catch (Exception e)
42 {
43 exception = e;
44 }
45
46 return (data, exception);
47 }
48 }
49 }