public void SeekRecordThenTryFormatString() { string dbFile = "SeekRecordThenTryFormatString.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string parameterFormatString = "[1]"; string[] properties = new string[] { "SonGoku", "Over 9000", }; string query = "SELECT `Property`, `Value` FROM `Property`"; using (View view = db.OpenView(query)) { using (Record rec = new Record(2)) { rec[1] = properties[0]; rec[2] = properties[1]; rec.FormatString = parameterFormatString; Console.WriteLine("Record fields before seeking: " + rec[0] + " " + rec[1] + " " + rec[2]); view.Seek(rec); //TODO: Why does view.Seek remove the record fields? Console.WriteLine("Record fields after seeking: " + rec[0] + " " + rec[1] + " " + rec[2]); // After inserting, the format string is invalid. Assert.AreEqual(String.Empty, rec.ToString()); } } } }
public static void AddListBoxEntry(Session session, string propertyName, int order, string value, string text) { Record newEntry = new Record(4); newEntry[0] = propertyName; newEntry[1] = order; newEntry[2] = value; newEntry[3] = text; try { Microsoft.Deployment.WindowsInstaller.View listBoxView = session.Database.OpenView("SELECT * FROM ComboBox"); //`Property`, `Order`, `Value`, `Text` listBoxView.Execute(); listBoxView.Modify(ViewModifyMode.InsertTemporary, newEntry); listBoxView.Close(); } catch (InstallerException ix) { //RecurseLogInstallerException(session, ix, 0); session.Log(ix.Message); } }
/// <summary> /// Query an MSI table for all records /// </summary> /// <param name="msi">The path to an MSI</param> /// <param name="sql">An MSI query</param> /// <returns>A list of records is returned</returns> /// <remarks>Uses DTF</remarks> public static List <DTF.Record> QueryAllRecords(string msi, string query) { List <DTF.Record> result = new List <DTF.Record>(); using (DTF.Database database = new DTF.Database(msi, DTF.DatabaseOpenMode.ReadOnly)) { using (DTF.View view = database.OpenView(query, null)) { view.Execute(); DTF.Record record = null; while (null != (record = view.Fetch())) { // Copy record created by Fetch to record created manually to remove View reference DTF.Record copyRecord = new DTF.Record(record.FieldCount); for (int i = 0; i <= record.FieldCount; i++) { copyRecord[i] = record[i]; } record.Close(); result.Add(copyRecord); } } } return(result); }
public void DeleteRecord() { string dbFile = "DeleteRecord.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string query = "SELECT `Property`, `Value` FROM `Property` WHERE `Property` = 'UpgradeCode'"; using (View view = db.OpenView(query)) { view.Execute(); Record rec = view.Fetch(); Console.WriteLine("Calling ToString() : " + rec); view.Delete(rec); } Assert.AreEqual(0, db.ExecuteStringQuery(query).Count); } }
private static List <DataBasePathTO> GetCustomTableDataBasePaths(Session session, bool isCustomActionData) { try { List <DataBasePathTO> listPaths; if (isCustomActionData) { listPaths = session.CustomActionData.GetObject <List <DataBasePathTO> >("DATABASE_PATHS"); } else { listPaths = new List <DataBasePathTO>(); DataBasePathTO path; string sPath; using (Microsoft.Deployment.WindowsInstaller.View v = session.Database.OpenView ("SELECT * FROM `TABLE_DATABASE_PATHS`")) { if (v != null) { v.Execute(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { sPath = r.GetString(3); if (string.IsNullOrWhiteSpace(sPath)) { sPath = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); } path = new DataBasePathTO() { Name = r.GetString(1), Description = r.GetString(2), Path = sPath }; listPaths.Add(path); r.Dispose(); } } } } if (listPaths == null || listPaths.Count == 0) { throw new InstallerException("No installation paths configured"); } return(listPaths); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception, GetCustomTableDataBasePaths", ex, true); throw; } }
private static ActionResult EnumSqlServersIntoComboBox(Session session, IEnumerable <DataRow> rows) { try { //Debugger.Break(); session.Log("EnumSQLServers: Begin"); View view = session.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DATABASE_SERVER'"); view.Execute(); view = session.Database.OpenView("SELECT * FROM ComboBox"); view.Execute(); Int32 index = 1; session.Log("EnumSQLServers: Enumerating SQL servers"); foreach (DataRow row in rows) { String serverName = row["Name"].ToString(); // Create a record for this web site. All I care about is // the name so use it for fields three and four. session.Log("EnumSQLServers: Processing SQL server: {0}", serverName); Record record = session.Database.CreateRecord(4); record.SetString(1, "DATABASE_SERVER"); record.SetInteger(2, index); record.SetString(3, serverName); record.SetString(4, serverName); session.Log("EnumSQLServers: Adding record"); view.Modify(ViewModifyMode.InsertTemporary, record); index++; } view.Close(); session.Log("EnumSQLServers: End"); } catch (Exception ex) { session.Log("EnumSQLServers: exception: {0}", ex.Message); throw; } return(ActionResult.Success); }
public static ActionResult FillDBServerNameAction(Session xiSession) { Microsoft.Deployment.WindowsInstaller.View lView = xiSession.Database.OpenView("SELECT * FROM ComboBox"); lView.Execute(); int lIndex = 1; string HostName = Dns.GetHostName(); ServiceController[] services = ServiceController.GetServices(); //从机器服务列表中找到本机的SqlServer引擎 foreach (ServiceController s in services) { if (s.Status != ServiceControllerStatus.Running) { continue; } if (s.ServiceName.ToLower().IndexOf("mssql$") != -1) { Record lRecord = xiSession.Database.CreateRecord(4); lRecord.SetString(1, "DBSERVER"); lRecord.SetInteger(2, lIndex); lRecord.SetString(3, HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1)); // Use lWebsiteName only if you want to look up the site by name. lRecord.SetString(3, HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1)); lView.Modify(ViewModifyMode.InsertTemporary, lRecord); if (lIndex == 1) { xiSession["DBSERVER"] = HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1); } lIndex++; } else if (s.ServiceName.ToLower() == "mssqlserver") { Record lRecord = xiSession.Database.CreateRecord(4); lRecord.SetString(1, "DBSERVER"); lRecord.SetInteger(2, lIndex); lRecord.SetString(3, HostName); // Use lWebsiteName only if you want to look up the site by name. lRecord.SetString(3, HostName); lView.Modify(ViewModifyMode.InsertTemporary, lRecord); if (lIndex == 1) { xiSession["DBSERVER"] = HostName; } lIndex++; } } lView.Close(); return(ActionResult.Success); }
public void InstallerViewTables() { string dbFile = "InstallerViewTables.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); db.Commit(); using (View view1 = db.OpenView("SELECT `Property`, `Value` FROM `Property` WHERE `Value` IS NOT NULL")) { IList <TableInfo> viewTables = view1.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view2 = db.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES ('TestViewTables', 1)")) { IList <TableInfo> viewTables = view2.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view3 = db.OpenView("UPDATE `Property` SET `Value` = 2 WHERE `Property` = 'TestViewTables'")) { IList <TableInfo> viewTables = view3.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view4 = db.OpenView("alter table Property hold")) { IList <TableInfo> viewTables = view4.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } } }
public static ActionResult PopulateRegistrarList(Session session) { string wixProperty = "REGISTRAR_REGISTRAR"; string logPrefix = "UDDNSQuery.PopulateRegistrarList: "; session.Log(logPrefix + "Method begin."); // Nuke the combobox and initialize the View. Microsoft.Deployment.WindowsInstaller.View comboBoxView = session.Database.OpenView( "DELETE FROM ComboBox WHERE ComboBox.Property = '{0}'", new string[] { wixProperty, } ); comboBoxView.Execute(); comboBoxView = session.Database.OpenView("SELECT * FROM ComboBox"); comboBoxView.Execute(); session.Log(logPrefix + String.Format("ComboBox {0} purged.", wixProperty)); // Populate the combobox. http://msdn.microsoft.com/en-us/library/windows/desktop/aa367872(v=vs.85).aspx int i = 0; Record comboBoxItem; string entry; foreach (string name in QueryAPIIndex.I.Registrars.Keys) { i++; entry = String.Format("{0} ({1})", name, QueryAPIIndex.I.Registrars[name]); comboBoxItem = session.Database.CreateRecord(4); comboBoxItem.SetString(1, wixProperty); // Property name. comboBoxItem.SetInteger(2, i); // Order. comboBoxItem.SetString(3, name); // Value of item. comboBoxItem.SetString(4, entry); // Text to represent item. comboBoxView.Modify(ViewModifyMode.InsertTemporary, comboBoxItem); session.Log(logPrefix + String.Format("ComboBox {0} new entry: {1}", wixProperty, entry)); } session.Log(logPrefix + "Method end."); return(ActionResult.Success); }
public void InsertRecordThenTryFormatString() { string dbFile = "InsertRecordThenTryFormatString.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string parameterFormatString = "[1]"; string[] properties = new string[] { "SonGoku", "Over 9000", }; string query = "SELECT `Property`, `Value` FROM `Property`"; using (View view = db.OpenView(query)) { using (Record rec = new Record(2)) { rec[1] = properties[0]; rec[2] = properties[1]; rec.FormatString = parameterFormatString; Console.WriteLine("Format String before inserting: " + rec.FormatString); view.Insert(rec); Console.WriteLine("Format String after inserting: " + rec.FormatString); // After inserting, the format string is invalid. Assert.AreEqual(String.Empty, rec.ToString()); // Setting the format string manually makes it valid again. rec.FormatString = parameterFormatString; Assert.AreEqual(properties[0], rec.ToString()); } } } }
private static ActionResult GetScriptFilesFromMsiDatabase(Session session, int elevated, string XmlDataProperty, string installAction) { Database db = session.Database; const string tableName = "PowerShellFiles"; if (!db.Tables.Contains(tableName)) { return(ActionResult.Success); } try { XDocument doc; using (View view = db.OpenView(string.Format("SELECT `Id`, `File`, `Arguments`, `IgnoreErrors`, `InstallAction` FROM `{0}` WHERE `Elevated` = {1}", tableName, elevated))) { view.Execute(); doc = new XDocument(new XDeclaration("1.0", "utf-16", "yes"), new XElement("r")); foreach (Record row in view) { var args = session.Format(row["Arguments"].ToString()); var instAction = session.Format(row["InstallAction"].ToString()); var IgnoreErrors = session.Format(row["IgnoreErrors"].ToString()); session.Log("args '{0}'", args); session.Log("InstallAction '{0}'", installAction); session.Log("InstallAction in file '{0}'", instAction); if (instAction == installAction) { session.Log("Adding InstallAction in file '{0}'", instAction); doc.Root.Add(new XElement("d", new XAttribute("Id", row["Id"]), new XAttribute("file", session.Format(row["File"].ToString())), new XAttribute("args", args), new XAttribute("IgnoreErrors", IgnoreErrors), new XAttribute("InstallAction", instAction))); } } } var cad = new CustomActionData { { "xml", doc.ToString() } }; session[XmlDataProperty] = cad.ToString(); // Tell the installer to increase the value of the final total // length of the progress bar by the total number of ticks in // the custom action. MessageResult iResult; using (var hProgressRec = new Record(2)) { hProgressRec[1] = 3; hProgressRec[2] = TotalTicks; iResult = session.Message(InstallMessage.Progress, hProgressRec); } if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } return(ActionResult.Success); } catch (Exception ex) { session.Log(ex.Message); return(ActionResult.Failure); } finally { db.Close(); } }
private static ActionResult GetScriptsFromMsiDatabase(Session session, int elevated, string XmlDataProperty, string installAction) { Database db = session.Database; if (!db.Tables.Contains("PowerShellScripts")) { return(ActionResult.Success); } try { CustomActionData data; using (View view = db.OpenView(string.Format("SELECT `Id`, `Script` FROM `PowerShellScripts` WHERE `Elevated` = {0}", elevated))) { view.Execute(); data = new CustomActionData(); Record row = view.Fetch(); while (row != null) { string script = Encoding.Unicode.GetString(Convert.FromBase64String(row["Script"].ToString())); script = session.Format(script); script = Convert.ToBase64String(Encoding.Unicode.GetBytes(script)); data.Add(row["Id"].ToString(), script); session.Log("Adding {0} to CustomActionData", row["Id"]); row = view.Fetch(); } } session[XmlDataProperty] = data.ToString(); // Tell the installer to increase the value of the final total // length of the progress bar by the total number of ticks in // the custom action. MessageResult iResult; using (var hProgressRec = new Record(2)) { hProgressRec[1] = 3; hProgressRec[2] = TotalTicks; iResult = session.Message(InstallMessage.Progress, hProgressRec); } if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } return(ActionResult.Success); } catch (Exception ex) { session.Log(ex.ToString()); return(ActionResult.Failure); } finally { db.Close(); } }
private static ActionResult FilesImmediate(Session session, int elevated, string deferredProperty) { Database db = session.Database; const string tableName = "PowerShellFiles"; if (!db.Tables.Contains(tableName)) { return(ActionResult.Success); } try { XDocument doc; using (View view = db.OpenView(string.Format("SELECT `Id`, `File`, `Arguments`, `IgnoreErrors`, `Condition` FROM `{0}` WHERE `Elevated` = {1} ORDER BY `Order`", tableName, elevated))) { view.Execute(); doc = new XDocument(new XDeclaration("1.0", "utf-16", "yes"), new XElement("r")); foreach (Record row in view) { string condition = row["Condition"]?.ToString(); if (!string.IsNullOrEmpty(condition) && !session.EvaluateCondition(condition)) { session.Log($"Condition evaluated to false. Skip PS file {row["Id"]?.ToString()}"); continue; } var args = session.Format(row["Arguments"].ToString()); var IgnoreErrors = session.Format(row["IgnoreErrors"].ToString()); session.Log("args '{0}'", args); doc.Root.Add(new XElement("d", new XAttribute("Id", row["Id"]), new XAttribute("file", session.Format(row["File"].ToString())), new XAttribute("args", args), new XAttribute("IgnoreErrors", IgnoreErrors))); } } var cad = new CustomActionData { { "xml", doc.ToString() } }; session[deferredProperty] = cad.ToString(); // Tell the installer to increase the value of the final total // length of the progress bar by the total number of ticks in // the custom action. MessageResult iResult; using (var hProgressRec = new Record(2)) { hProgressRec[1] = 3; hProgressRec[2] = TotalTicks; iResult = session.Message(InstallMessage.Progress, hProgressRec); } if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } return(ActionResult.Success); } catch (Exception ex) { session.Log(ex.Message); return(ActionResult.Failure); } finally { db.Close(); } }
private static ActionResult ScriptsImmediate(Session session, int elevated, string deferredProperty) { Database db = session.Database; if (!db.Tables.Contains("PowerShellScripts")) { return(ActionResult.Success); } try { List <ScriptActionData> scripts = new List <ScriptActionData>(); using (View view = db.OpenView(string.Format("SELECT `Id`, `Script`, `IgnoreErrors`, `Condition` FROM `PowerShellScripts` WHERE `Elevated` = {0} ORDER BY `Order`", elevated))) { view.Execute(); Record row; while ((row = view.Fetch()) != null) { string condition = row["Condition"]?.ToString(); if (!string.IsNullOrEmpty(condition) && !session.EvaluateCondition(condition)) { session.Log($"Condition evaluated to false. Skip PS script {row["Id"]?.ToString()}"); continue; } string script = Encoding.Unicode.GetString(Convert.FromBase64String(row["Script"].ToString())); script = session.Format(script); script = Convert.ToBase64String(Encoding.Unicode.GetBytes(script)); ScriptActionData data = new ScriptActionData() { Id = row["Id"].ToString(), Script = script, IgnoreErrors = row["IgnoreErrors"].ToString() == "1" }; scripts.Add(data); session.Log("Adding {0} to CustomActionData", data.Id); } } XmlSerializer srlz = new XmlSerializer(scripts.GetType()); using (StringWriter sw = new StringWriter()) { srlz.Serialize(sw, scripts); session[deferredProperty] = sw.ToString(); } // Tell the installer to increase the value of the final total // length of the progress bar by the total number of ticks in // the custom action. MessageResult iResult; using (var hProgressRec = new Record(2)) { hProgressRec[1] = 3; hProgressRec[2] = TotalTicks; iResult = session.Message(InstallMessage.Progress, hProgressRec); } if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } return(ActionResult.Success); } catch (Exception ex) { session.Log(ex.ToString()); return(ActionResult.Failure); } finally { db.Close(); } }
private static void StoreWebSiteDataInAvailableWebSitesTable(DirectoryEntry webSite, View availableWSView) { //Get Ip, Port and Header from server bindings string[] serverBindings = ((string)webSite.Properties["ServerBindings"].Value).Split(':'); string ip = serverBindings[0]; string port = serverBindings[1]; string header = serverBindings[2]; Record newFoundWebSiteRecord = new Record(5); newFoundWebSiteRecord[1] = webSite.Name; newFoundWebSiteRecord[2] = webSite.Properties["ServerComment"].Value; newFoundWebSiteRecord[3] = port; newFoundWebSiteRecord[4] = ip; newFoundWebSiteRecord[5] = header; availableWSView.Modify(ViewModifyMode.InsertTemporary, newFoundWebSiteRecord); }
/// <summary> /// Returns data from the MSI tables: `FeatureComponents`, `Feature`, `Component`, `File`. /// We filter to just get the files that end in (*.SQL). /// </summary> /// <param name="session">Windows Installer Session.</param> /// <param name="listFeatureNames">List list with names to be installed.</param> /// <returns>Returns scripts database files to be installed.</returns> private static List <FeatureInstallTO> GetFeatureScriptDataBase(Session session, List <string> listFeatureNames) { try { List <FeatureInstallTO> listFeatures; string sLevel = session["INSTALLLEVEL"]; listFeatures = new List <FeatureInstallTO>(); FeatureInstallTO f; int i; string sFileName; string sQuery = "SELECT `Feature`.`Feature`, `Feature`.`Title`, `Feature`.`Display`, " + " `Component`.`Directory_`, `File`.`FileName` " + " FROM `FeatureComponents`, `Feature`, `Component`, `File` " + " WHERE `FeatureComponents`.`Feature_` = `Feature`.`Feature` " + " AND `FeatureComponents`.`Component_` = `Component`.`Component` " + " AND `File`.`Component_` = `Component`.`Component` " + " AND `Feature`.`RuntimeLevel` > 0 AND `Feature`.`Level` > 0 " + // " AND `Feature`.`Level` <= " + sLevel + " ORDER BY `Feature`.`Display`"; using (View v = session.Database.OpenView(sQuery)) { if (v != null) { v.Execute(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { if (listFeatureNames.Contains(r.GetString("Feature")) && r.GetString("FileName").ToUpper().EndsWith(".SQL")) { i = r.GetString("FileName").IndexOf("|", StringComparison.Ordinal); if (i > 0) { sFileName = r.GetString("FileName").Substring(i + 1); } else { sFileName = r.GetString("FileName"); } f = new FeatureInstallTO { Feature = r.GetString("Feature"), Title = r.GetString("Title"), DisplayOrder = r.GetInteger("Display"), FileName = sFileName, DirectoryPath = session.GetTargetPath(r.GetString("Directory_")) }; listFeatures.Add(f); } r.Dispose(); } } } return(listFeatures); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception, ReadFeactureScriptDataBase", ex, true); throw; } }
private static List <FeactureInstallTO> GetFeactureScriptDataBase(Session session, List <string> listFeactureNames) { string sFileName = string.Empty; try { List <FeactureInstallTO> listF; string sLevel = session["INSTALLLEVEL"]; listF = new List <FeactureInstallTO>(); FeactureInstallTO f; int i; string sQuery = "SELECT `Feature`.`Feature`, `Feature`.`Title`, `Feature`.`Display`, " + " `Component`.`Directory_`, `File`.`FileName` " + " FROM `FeatureComponents`, `Feature`, `Component`, `File` " + " WHERE `FeatureComponents`.`Feature_` = `Feature`.`Feature` " + " AND `FeatureComponents`.`Component_` = `Component`.`Component` " + " AND `File`.`Component_` = `Component`.`Component` " + " AND `Feature`.`RuntimeLevel` > 0 AND `Feature`.`Level` > 0 " + // " AND `Feature`.`Level` <= " + sLevel + " ORDER BY `Feature`.`Display`"; using (Microsoft.Deployment.WindowsInstaller.View v = session.Database.OpenView(sQuery)) { if (v != null) { v.Execute(); //var str = string.Empty; //foreach (var fea in listFeactureNames) // str += fea.ToString(); //MessageBox.Show(str); //str = string.Empty ; //var frm = new FeatureList( session,v,listFeactureNames); //frm.ShowDialog(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { if (listFeactureNames.Contains(r.GetString("Feature")) && r.GetString("FileName").ToUpper().EndsWith(".SQL")) { i = r.GetString("FileName").IndexOf("|"); if (i > 0) { sFileName = r.GetString("FileName").Substring(i + 1); } else { sFileName = r.GetString("FileName"); } f = new FeactureInstallTO() { Feature = r.GetString("Feature"), Title = r.GetString("Title"), DisplayOrder = r.GetInteger("Display"), FileName = sFileName, DirectoryPath = session.GetTargetPath(r.GetString("Directory_")) }; listF.Add(f); } r.Dispose(); } } } return(listF); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Fail to Read Feature Script", ex, true); throw; } }
private static void StoreWebSiteDataInListBoxTable(DirectoryEntry webSite, int order, View listBoxView) { Record newListBoxRecord = new Record(4); newListBoxRecord[1] = "WEBSITE"; newListBoxRecord[2] = order; newListBoxRecord[3] = webSite.Name; newListBoxRecord[4] = webSite.Properties["ServerComment"].Value; listBoxView.Modify(ViewModifyMode.InsertTemporary, newListBoxRecord); }
private object[][] GetComponentRegistryRows(string productCode, string componentCode, Session session, bool includeComponent) { ArrayList rows = new ArrayList(); string componentPath = new ComponentInstallation(componentCode, productCode).Path; string componentKey = (string)session.Database.ExecuteScalar( "SELECT `Component` FROM `Component` WHERE `ComponentId` = '{0}'", componentCode); if (componentKey == null) { return(null); } int attributes = Convert.ToInt32(session.Database.ExecuteScalar( "SELECT `Attributes` FROM `Component` WHERE `Component` = '{0}'", componentKey)); bool registryKeyPath = (attributes & (int)ComponentAttributes.RegistryKeyPath) != 0; if (!registryKeyPath && componentPath.Length > 0) { componentPath = Path.GetDirectoryName(componentPath); } string keyPath = (string)session.Database.ExecuteScalar( "SELECT `KeyPath` FROM `Component` WHERE `Component` = '{0}'", componentKey); using (View view = session.Database.OpenView("SELECT `Registry`, `Root`, `Key`, `Name`, " + "`Value` FROM `Registry` WHERE `Component_` = '{0}'", componentKey)) { view.Execute(); foreach (Record rec in view) { using (rec) { string regName = (string)rec["Name"]; if (regName == "-") { continue; // Don't list deleted keys } string regTableKey = (string)rec["Registry"]; bool isKey = registryKeyPath && keyPath == regTableKey; string regPath = this.GetRegistryPath(session, (RegistryRoot)Convert.ToInt32(rec["Root"]), (string)rec["Key"], (string)rec["Name"]); string dbValue; using (Record formatRec = new Record(0)) { formatRec[0] = rec["Value"]; dbValue = session.FormatRecord(formatRec); } string installedValue = this.GetRegistryValue(regPath); bool exists = installedValue != null; if (!exists) { installedValue = ""; } bool match = installedValue == dbValue; object[] row; if (includeComponent) { row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match, componentCode } } ; else { row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match } }; rows.Add(row); } } } return((object[][])rows.ToArray(typeof(object[]))); }
private object[][] GetComponentFilesRows(string productCode, string componentCode, Session session, bool includeComponent) { ArrayList rows = new ArrayList(); string componentPath = new ComponentInstallation(componentCode, productCode).Path; string componentKey = (string)session.Database.ExecuteScalar( "SELECT `Component` FROM `Component` WHERE `ComponentId` = '{0}'", componentCode); if (componentKey == null) { return(null); } int attributes = Convert.ToInt32(session.Database.ExecuteScalar( "SELECT `Attributes` FROM `Component` WHERE `Component` = '{0}'", componentKey)); bool registryKeyPath = (attributes & (int)ComponentAttributes.RegistryKeyPath) != 0; if (!registryKeyPath && componentPath.Length > 0) { componentPath = Path.GetDirectoryName(componentPath); } string keyPath = (string)session.Database.ExecuteScalar( "SELECT `KeyPath` FROM `Component` WHERE `Component` = '{0}'", componentKey); using (View view = session.Database.OpenView("SELECT `File`, `FileName`, `Version`, `Language`, " + "`Attributes` FROM `File` WHERE `Component_` = '{0}'", componentKey)) { view.Execute(); foreach (Record rec in view) { using (rec) { string fileKey = (string)rec["File"]; bool isKey = !registryKeyPath && keyPath == fileKey; string dbVersion = (string)rec["Version"]; bool versionedFile = dbVersion.Length != 0; if (versionedFile) { string language = (string)rec["Language"]; if (language.Length > 0) { dbVersion = dbVersion + " (" + language + ")"; } } else if (session.Database.Tables.Contains("MsiFileHash")) { IList <int> hash = session.Database.ExecuteIntegerQuery("SELECT `HashPart1`, `HashPart2`, " + "`HashPart3`, `HashPart4` FROM `MsiFileHash` WHERE `File_` = '{0}'", fileKey); if (hash != null && hash.Count == 4) { dbVersion = this.GetFileHashString(hash); } } string filePath = GetLongFileName((string)rec["FileName"]); bool exists = false; bool installedMatch = false; string installedVersion = ""; if (!registryKeyPath && componentPath.Length > 0) { filePath = Path.Combine(componentPath, filePath); if (File.Exists(filePath)) { exists = true; if (versionedFile) { installedVersion = Installer.GetFileVersion(filePath); string language = Installer.GetFileLanguage(filePath); if (language.Length > 0) { installedVersion = installedVersion + " (" + language + ")"; } } else { int[] hash = new int[4]; Installer.GetFileHash(filePath, hash); installedVersion = this.GetFileHashString(hash); } installedMatch = installedVersion == dbVersion; } } object[] row; if (includeComponent) { row = new object[] { isKey, fileKey, filePath, exists, dbVersion, installedVersion, installedMatch, componentCode } } ; else { row = new object[] { isKey, fileKey, filePath, exists, dbVersion, installedVersion, installedMatch } }; rows.Add(row); } } } return((object[][])rows.ToArray(typeof(object[]))); }