diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:36:37 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:36:37 -0700 |
| commit | 3f583916719eeef598d10a5d4e14ef14f008243b (patch) | |
| tree | 3d528e0ddb5c0550954217c97059d2f19cd6152a /src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs | |
| parent | 2e5ab696b8b4666d551b2a0532b95fb7fe6dbe03 (diff) | |
| download | wix-3f583916719eeef598d10a5d4e14ef14f008243b.tar.gz wix-3f583916719eeef598d10a5d4e14ef14f008243b.tar.bz2 wix-3f583916719eeef598d10a5d4e14ef14f008243b.zip | |
Merge Dtf
Diffstat (limited to 'src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs')
| -rw-r--r-- | src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs new file mode 100644 index 00000000..644f1988 --- /dev/null +++ b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerUtils.cs | |||
| @@ -0,0 +1,174 @@ | |||
| 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.Dtf.Test | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Text; | ||
| 8 | using WixToolset.Dtf.WindowsInstaller; | ||
| 9 | |||
| 10 | public class WindowsInstallerUtils | ||
| 11 | { | ||
| 12 | public static void InitializeProductDatabase(Database db) | ||
| 13 | { | ||
| 14 | InitializeProductDatabase(db, false); | ||
| 15 | } | ||
| 16 | |||
| 17 | public static void InitializeProductDatabase(Database db, bool sixtyFourBit) | ||
| 18 | { | ||
| 19 | db.SummaryInfo.CodePage = (short) Encoding.Default.CodePage; | ||
| 20 | db.SummaryInfo.Title = "Windows Installer Test"; | ||
| 21 | db.SummaryInfo.Subject = db.SummaryInfo.Title; | ||
| 22 | db.SummaryInfo.Author = typeof(WindowsInstallerUtils).Assembly.FullName; | ||
| 23 | db.SummaryInfo.CreatingApp = db.SummaryInfo.Author; | ||
| 24 | db.SummaryInfo.Comments = typeof(WindowsInstallerUtils).FullName + ".CreateBasicDatabase()"; | ||
| 25 | db.SummaryInfo.Keywords = "Installer,MSI,Database"; | ||
| 26 | db.SummaryInfo.PageCount = 300; | ||
| 27 | db.SummaryInfo.WordCount = 0; | ||
| 28 | db.SummaryInfo.RevisionNumber = Guid.NewGuid().ToString("B").ToUpper(); | ||
| 29 | db.SummaryInfo.Template = (sixtyFourBit ? "x64" : "Intel") + ";0"; | ||
| 30 | |||
| 31 | foreach (TableInfo tableInfo in Schema.Tables) | ||
| 32 | { | ||
| 33 | db.Execute(tableInfo.SqlCreateString); | ||
| 34 | } | ||
| 35 | |||
| 36 | db.Execute("INSERT INTO `Directory` (`Directory`, `DefaultDir`) VALUES ('TARGETDIR', 'SourceDir')"); | ||
| 37 | db.Execute("INSERT INTO `Directory` (`Directory`, `Directory_Parent`, `DefaultDir`) VALUES ('ProgramFilesFolder', 'TARGETDIR', '.')"); | ||
| 38 | |||
| 39 | foreach (Action action in Sequence.InstallExecute) | ||
| 40 | { | ||
| 41 | db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Sequence`) VALUES ('{0}', {1})", | ||
| 42 | action.Name, action.Sequence); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | public const string UpgradeCode = "{05955FE8-005F-4695-A81F-D559338065BB}"; | ||
| 47 | |||
| 48 | public static void CreateTestProduct(Database db) | ||
| 49 | { | ||
| 50 | Guid productGuid = Guid.NewGuid(); | ||
| 51 | |||
| 52 | string[] properties = new string[] | ||
| 53 | { | ||
| 54 | "ProductCode", productGuid.ToString("B").ToUpper(), | ||
| 55 | "UpgradeCode", UpgradeCode, | ||
| 56 | "ProductName", "Windows Installer Test Product " + productGuid.ToString("P").ToUpper(), | ||
| 57 | "ProductVersion", "1.0.0.0000", | ||
| 58 | }; | ||
| 59 | |||
| 60 | using (View view = db.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES (?, ?)")) | ||
| 61 | { | ||
| 62 | using (Record rec = new Record(2)) | ||
| 63 | { | ||
| 64 | for (int i = 0; i < properties.Length; i += 2) | ||
| 65 | { | ||
| 66 | rec[1] = properties[i]; | ||
| 67 | rec[2] = properties[i + 1]; | ||
| 68 | view.Execute(rec); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | int randomId = new Random().Next(10000); | ||
| 74 | string productDir = "TestDir" + randomId; | ||
| 75 | db.Execute( | ||
| 76 | "INSERT INTO `Directory` (`Directory`, `Directory_Parent`, `DefaultDir`) " + | ||
| 77 | "VALUES ('TestDir', 'ProgramFilesFolder', 'TestDir|{0}:.')", productDir); | ||
| 78 | |||
| 79 | string compId = Guid.NewGuid().ToString("B").ToUpper(); | ||
| 80 | db.Execute( | ||
| 81 | "INSERT INTO `Component` " + | ||
| 82 | "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " + | ||
| 83 | "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')", | ||
| 84 | "TestRegComp1", | ||
| 85 | compId, | ||
| 86 | "TestDir", | ||
| 87 | (int) ComponentAttributes.RegistryKeyPath, | ||
| 88 | "TestReg1"); | ||
| 89 | |||
| 90 | string productReg = "TestReg" + randomId; | ||
| 91 | db.Execute( | ||
| 92 | "INSERT INTO `Registry` (`Registry`, `Root`, `Key`, `Component_`) VALUES ('{0}', {1}, '{2}', '{3}')", | ||
| 93 | "TestReg1", | ||
| 94 | -1, | ||
| 95 | @"Software\Microsoft\Windows Installer Test\" + productReg, | ||
| 96 | "TestRegComp1"); | ||
| 97 | |||
| 98 | db.Execute( | ||
| 99 | "INSERT INTO `Feature` (`Feature`, `Title`, `Level`, `Attributes`) VALUES ('{0}', '{1}', {2}, {3})", | ||
| 100 | "TestFeature1", | ||
| 101 | "Test Feature 1", | ||
| 102 | 1, | ||
| 103 | (int) FeatureAttributes.None); | ||
| 104 | |||
| 105 | db.Execute( | ||
| 106 | "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')", | ||
| 107 | "TestFeature1", | ||
| 108 | "TestRegComp1"); | ||
| 109 | } | ||
| 110 | |||
| 111 | public static void AddFeature(Database db, string featureName) | ||
| 112 | { | ||
| 113 | db.Execute( | ||
| 114 | "INSERT INTO `Feature` (`Feature`, `Title`, `Level`, `Attributes`) VALUES ('{0}', '{1}', {2}, {3})", | ||
| 115 | featureName, | ||
| 116 | featureName, | ||
| 117 | 1, | ||
| 118 | (int) FeatureAttributes.None); | ||
| 119 | } | ||
| 120 | |||
| 121 | public static void AddRegistryComponent(Database db, | ||
| 122 | string featureName, string compName, string compId, | ||
| 123 | string keyName, string keyValueName, string value) | ||
| 124 | { | ||
| 125 | db.Execute( | ||
| 126 | "INSERT INTO `Component` " + | ||
| 127 | "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " + | ||
| 128 | "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')", | ||
| 129 | compName, | ||
| 130 | compId, | ||
| 131 | "TestDir", | ||
| 132 | (int) ComponentAttributes.RegistryKeyPath, | ||
| 133 | compName + "Reg1"); | ||
| 134 | db.Execute( | ||
| 135 | "INSERT INTO `Registry` (`Registry`, `Root`, `Key`, `Name`, `Value`, `Component_`) VALUES ('{0}', {1}, '{2}', '{3}', '{4}', '{5}')", | ||
| 136 | compName + "Reg1", | ||
| 137 | -1, | ||
| 138 | @"Software\Microsoft\Windows Installer Test\" + keyName, | ||
| 139 | keyValueName, | ||
| 140 | value, | ||
| 141 | compName); | ||
| 142 | db.Execute( | ||
| 143 | "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')", | ||
| 144 | featureName, | ||
| 145 | compName); | ||
| 146 | } | ||
| 147 | |||
| 148 | public static void AddFileComponent(Database db, | ||
| 149 | string featureName, string compName, string compId, | ||
| 150 | string fileKey, string fileName) | ||
| 151 | { | ||
| 152 | db.Execute( | ||
| 153 | "INSERT INTO `Component` " + | ||
| 154 | "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " + | ||
| 155 | "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')", | ||
| 156 | compName, | ||
| 157 | compId, | ||
| 158 | "TestDir", | ||
| 159 | (int) ComponentAttributes.None, | ||
| 160 | fileKey); | ||
| 161 | db.Execute( | ||
| 162 | "INSERT INTO `File` " + | ||
| 163 | "(`File`, `Component_`, `FileName`, `FileSize`, `Attributes`, `Sequence`) " + | ||
| 164 | "VALUES ('{0}', '{1}', '{2}', 1, 0, 1)", | ||
| 165 | fileKey, | ||
| 166 | compName, | ||
| 167 | fileName); | ||
| 168 | db.Execute( | ||
| 169 | "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')", | ||
| 170 | featureName, | ||
| 171 | compName); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | } | ||
