public static string GetMsiProductCode(string msiName) // Enumerates the MSIs present in the system. If 'msiName' // exists, it returns its product code. If not, it returns // the empty string. { const int GUID_LEN = 39; const int BUF_LEN = 128; int err; int len; StringBuilder productCode = new StringBuilder(GUID_LEN, GUID_LEN); StringBuilder productName = new StringBuilder(BUF_LEN, BUF_LEN); Trace.WriteLine( "Checking if \'" + msiName + "\' is present in system.." ); for (int i = 0; (err = Msi.MsiEnumProducts(i, productCode)) == WinError.ERROR_SUCCESS; ++i) { len = BUF_LEN; // Get ProductName from Product GUID err = Msi.MsiGetProductInfo( productCode.ToString(), Msi.INSTALLPROPERTY.INSTALLEDPRODUCTNAME, productName, ref len ); if (err != WinError.ERROR_SUCCESS) { Trace.WriteLine("Failed to read the name of msi " + productCode.ToString()); continue; } if (msiName.Equals( productName.ToString(), StringComparison.OrdinalIgnoreCase)) { Trace.WriteLine( "Product found; Code: \'" + productCode.ToString() + "\'" ); return(productCode.ToString()); } } if (err == WinError.ERROR_NO_MORE_ITEMS) { Trace.WriteLine("Product not found"); return(""); } else { Win32Error.Set("MsiEnumProducts", err); throw new Exception(Win32Error.GetFullErrMsg()); } }
void AssociatedObject_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { if (e.DeltaManipulation.Scale.X == 0 && e.DeltaManipulation.Scale.Y == 0) { // No scaling took place (i.e. no multi touch) // 'Simply' calculate a new view point origin Msi.ViewportOrigin = new Point { X = MsiOrigin.X - (e.CumulativeManipulation.Translation.X / Msi.ActualWidth * Msi.ViewportWidth), Y = MsiOrigin.Y - (e.CumulativeManipulation.Translation.Y / Msi.ActualHeight * Msi.ViewportWidth), }; } else { // Multi touch - choose to interpretet this either as zoom or pinch var zoomscale = (e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y) / 2; // Calculate a new 'logical point' - the MSI has its own 'coordinate system' var logicalPoint = Msi.ElementToLogicalPoint( new Point { X = ManipulationOrigin.X - e.CumulativeManipulation.Translation.X, Y = ManipulationOrigin.Y - e.CumulativeManipulation.Translation.Y } ); Msi.ZoomAboutLogicalPoint(zoomscale, logicalPoint.X, logicalPoint.Y); if (Msi.ViewportWidth > 1) { Msi.ViewportWidth = 1; } } }
protected override void Write(LogEventInfo logEvent) { if (_msiHandle.HasValue) { var message = Layout.Render(logEvent); using (Msi.Install msi = Msi.CustomActionHandle(_msiHandle.Value)) { using (Msi.Record record = new Msi.Record(100)) { record.SetString(0, "LOG: [1]"); record.SetString(1, message); msi.ProcessMessage(Msi.InstallMessage.Info, record); } } } }
private YamlDefinition CreateFromMsi(string filePath) { var msiProps = new Msi().GetProperties(filePath); var yamlDefinition = new YamlDefinition { Name = msiProps.TryGetValue("ProductName", out var pn) ? pn : null, Version = msiProps.TryGetValue("ProductVersion", out var pv) ? pv : null, Publisher = msiProps.TryGetValue("Manufacturer", out var pm) ? pm : null, Description = msiProps.TryGetValue("ARPCOMMENTS", out var arpc) ? arpc : null, License = msiProps.TryGetValue("ARPCONTACT", out var arpcont) ? arpcont : null, LicenseUrl = msiProps.TryGetValue("ARPURLINFOABOUT", out var arpurl) || msiProps.TryGetValue("ARPHELPLINK", out arpurl) ? arpurl : null, // Language = msiProps.TryGetValue("ProductLanguage", out var pl) ? pl : null, Installers = new List <YamlInstaller> { new YamlInstaller { InstallerType = YamlInstallerType.msi, Scope = msiProps.TryGetValue("ALLUSERS", out var allusers) && allusers == "1" ? YamlScope.machine : YamlScope.none, Arch = msiProps.TryGetValue("Template", out var template) && (template.IndexOf("Intel64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("x64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("amd64", StringComparison.OrdinalIgnoreCase) != -1) ? YamlArchitecture.x64 : YamlArchitecture.x86, } } }; if (yamlDefinition.License != null) { yamlDefinition.License = yamlDefinition.License.Trim(); if (string.IsNullOrWhiteSpace(yamlDefinition.License)) { yamlDefinition.License = null; } yamlDefinition.License = yamlDefinition.License.Trim(); if (string.IsNullOrWhiteSpace(yamlDefinition.LicenseUrl)) { yamlDefinition.LicenseUrl = null; } } return(yamlDefinition); }
private YamlManifest CreateFromMsi(string filePath) { var msiProps = new Msi().GetProperties(filePath); var lcid = msiProps.TryGetValue("ProductLanguage", out var language) ? language : null; var yamlDefinition = new YamlManifest { PackageName = msiProps.TryGetValue("ProductName", out var name) ? name : null, PackageVersion = msiProps.TryGetValue("ProductVersion", out var version) ? version : null, Publisher = msiProps.TryGetValue("Manufacturer", out var publisher) ? publisher : null, ShortDescription = msiProps.TryGetValue("ARPCOMMENTS", out var comments) ? comments : null, PublisherUrl = msiProps.TryGetValue("ARPCONTACT", out var contactUrl) ? contactUrl : null, CopyrightUrl = msiProps.TryGetValue("ARPURLINFOABOUT", out var url) ? url : null, PublisherSupportUrl = msiProps.TryGetValue("ARPHELPLINK", out var supportUrl) ? supportUrl : null, Installers = new List <YamlInstaller> { new YamlInstaller { InstallerType = YamlInstallerType.Msi, Scope = msiProps.TryGetValue("ALLUSERS", out var allUsers) && allUsers == "1" ? YamlScope.Machine : YamlScope.None, Architecture = msiProps.TryGetValue("Template", out var template) && (template.IndexOf("Intel64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("x64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("amd64", StringComparison.OrdinalIgnoreCase) != -1) ? YamlArchitecture.X64 : YamlArchitecture.X86, Platform = new List <YamlPlatform>() { YamlPlatform.WindowsDesktop }, ProductCode = msiProps.TryGetValue("ProductCode", out var productCode) ? productCode : null, // InstallModes = new List<YamlInstallMode> {YamlInstallMode.Interactive, YamlInstallMode.Silent, YamlInstallMode.SilentWithProgress }, } } }; if (lcid != null && int.TryParse(lcid, out var lcidCode)) { try { var culture = CultureInfo.GetCultureInfo(lcid); yamlDefinition.PackageLocale = culture.Name.ToLowerInvariant(); yamlDefinition.Installers[0].InstallerLocale = culture.Name.ToLowerInvariant(); } catch { // could not get culture by LCID. } } if (yamlDefinition.Copyright != null) { yamlDefinition.Copyright = yamlDefinition.Copyright.Trim(); if (string.IsNullOrWhiteSpace(yamlDefinition.Copyright)) { yamlDefinition.Copyright = null; } yamlDefinition.Copyright = yamlDefinition.Copyright.Trim(); if (string.IsNullOrWhiteSpace(yamlDefinition.CopyrightUrl)) { yamlDefinition.CopyrightUrl = null; } } return(yamlDefinition); }
private static List <MsiColumnDefinition> ReadColumnDefinitions(IntPtr viewHandle) { List <MsiColumnDefinition> columnDefinitions = new List <MsiColumnDefinition>(); Msi.ViewExecute(viewHandle, IntPtr.Zero); IntPtr recordHande; // Get column names Msi.ViewGetColumnInfo(viewHandle, Msi.MsiColInfoType_Names, out recordHande); try { uint columnCount = Msi.RecordGetFieldCount(recordHande); for (int i = 0; i < columnCount; i++) { MsiColumnDefinition columnDefinition = new MsiColumnDefinition(); columnDefinition.Name = Msi.RecordGetString(recordHande, (uint)(i + 1)); columnDefinitions.Add(columnDefinition); } } finally { Msi.CloseHandle(recordHande); } // Get column types Msi.ViewGetColumnInfo(viewHandle, Msi.MsiColInfoType_Types, out recordHande); try { uint columnCount = Msi.RecordGetFieldCount(recordHande); for (int i = 0; i < columnCount; i++) { string columnTypeDescriptor = Msi.RecordGetString(recordHande, (uint)(i + 1)); char columnTypeIndicator = columnTypeDescriptor[0]; switch (Char.ToLower(columnTypeIndicator)) { case 'i': // Integer case 'j': // Temporary integer columnDefinitions[i].DataType = MsiColumnDataType.Integer; break; case 's': // String case 'g': // Temporary string case 'l': columnDefinitions[i].DataType = MsiColumnDataType.String; break; case 'v': // Binary Stream case 'o': // Undocumented. columnDefinitions[i].DataType = MsiColumnDataType.Binary; break; default: throw new NotImplementedException(string.Format("Unexpected column type: '{0}'.", columnTypeDescriptor)); } } } finally { Msi.CloseHandle(recordHande); } return(columnDefinitions); }
private static DataTable ReadTable(IntPtr databaseHandle, string tableName) { string query = string.Format("SELECT * FROM {0}", tableName); IntPtr viewHandle; Msi.DatabaseOpenView(databaseHandle, query, out viewHandle); try { List <MsiColumnDefinition> columnDefinitions = ReadColumnDefinitions(viewHandle); // Write columns to data table DataTable dataTable = new DataTable(tableName); for (int i = 0; i < columnDefinitions.Count; i++) { Type columnType; switch (columnDefinitions[i].DataType) { case MsiColumnDataType.String: columnType = typeof(string); break; case MsiColumnDataType.Integer: columnType = typeof(int); break; case MsiColumnDataType.Binary: columnType = typeof(byte[]); break; default: throw new NotImplementedException(String.Format("Unexpected column type: '{0}'", columnDefinitions[i].DataType)); } dataTable.Columns.Add(columnDefinitions[i].Name, columnType); } // Read rows IntPtr recordHande = IntPtr.Zero; try { while (Msi.ViewFetch(viewHandle, ref recordHande)) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < columnDefinitions.Count; i++) { uint column = (uint)(i + 1); if (Msi.RecordIsNull(recordHande, column)) { dataRow[i] = DBNull.Value; } else if (columnDefinitions[i].DataType == MsiColumnDataType.Integer) { int value = Msi.RecordGetInteger(recordHande, column); dataRow[i] = value; } else if (columnDefinitions[i].DataType == MsiColumnDataType.String) { dataRow[i] = Msi.RecordGetString(recordHande, column); } else if (columnDefinitions[i].DataType == MsiColumnDataType.Binary) { dataRow[i] = Msi.RecordReadStream(recordHande, column); } } dataTable.Rows.Add(dataRow); } } finally { if (recordHande != IntPtr.Zero) { Msi.CloseHandle(recordHande); } } return(dataTable); } finally { Msi.CloseHandle(viewHandle); } }
private static void ReadAllTables(DataContext dataContext, string pathToMsiFile) { IntPtr databaseHandle; int openFlags = Msi.MsiDbPersistMode_ReadOnly; if (Path.GetExtension(pathToMsiFile).Equals(".msp", StringComparison.InvariantCultureIgnoreCase)) { openFlags += Msi.MsiDbPersistMode_PatchFile; } Msi.OpenDatabase(pathToMsiFile, openFlags, out databaseHandle); try { // Read table metadata table. DataTable tableDataTable = ReadTable(databaseHandle, "_Tables"); // NOTE: The metadata table itself is not listed in _Tables. dataContext.Tables.Add(tableDataTable); foreach (DataRow row in tableDataTable.Rows) { string tableName = (string)row["Name"]; DataTable table = ReadTable(databaseHandle, tableName); dataContext.Tables.Add(table); } // Add relations as described in the _Validation metadata table. DataTableBinding validationTableBinding = (DataTableBinding)dataContext.Tables["_Validation"]; if (validationTableBinding != null) { foreach (DataRow dataRow in validationTableBinding.DataTable.Rows) { if (dataRow.IsNull("KeyTable")) { continue; } string tableName = (string)dataRow["Table"]; string columnName = (string)dataRow["Column"]; string[] keyTablesNames = ((string)dataRow["KeyTable"]).Split(';'); int keyColumnNumber = (int)dataRow["KeyColumn"]; foreach (string keyTableName in keyTablesNames) { if (dataContext.Tables[tableName] != null) { TableBinding keyTable = dataContext.Tables[keyTableName]; if (keyTable != null && keyColumnNumber >= 1 && keyColumnNumber <= keyTable.Columns.Count) { string keyColumnName = keyTable.Columns[keyColumnNumber - 1].Name; dataContext.TableRelations.Add(tableName, new string[] { columnName }, keyTableName, new string[] { keyColumnName }); } } } } } } finally { Msi.CloseHandle(databaseHandle); } }