mirror of
https://github.com/ckaczor/CreateInstallDescriptor.git
synced 2026-02-16 10:48:31 -05:00
Update to handle EXE and DLL files as well as MSI files
This commit is contained in:
58
Program.cs
58
Program.cs
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using WindowsInstaller;
|
using WindowsInstaller;
|
||||||
@@ -12,39 +13,58 @@ namespace CreateInstallDescriptor
|
|||||||
// Make sure we received two parameters
|
// Make sure we received two parameters
|
||||||
if (args.Length != 2)
|
if (args.Length != 2)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Must supply two parameters: <input MSI file> <output XML file>");
|
Console.WriteLine("Must supply two parameters: <input file> <output XML file>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the parameters
|
// Extract the parameters
|
||||||
string inputFile = args[0];
|
var inputFileName = args[0];
|
||||||
string outputFile = args[1];
|
var outputFileName = args[1];
|
||||||
|
|
||||||
// Get the type of the Windows Installer object
|
// Get the info for the input file
|
||||||
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
|
var inputFile = new FileInfo(inputFileName);
|
||||||
|
|
||||||
// Create the Windows Installer object
|
var extension = inputFile.Extension;
|
||||||
Installer installer = (Installer)Activator.CreateInstance(installerType);
|
|
||||||
|
|
||||||
// Open the MSI database in the input file
|
string version;
|
||||||
Database database = installer.OpenDatabase(inputFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
|
|
||||||
|
|
||||||
// Open a view on the Property table for the version property
|
if (extension.Equals(".msi", StringComparison.InvariantCultureIgnoreCase))
|
||||||
View view = database.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'");
|
{
|
||||||
|
// Get the type of the Windows Installer object
|
||||||
|
var installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
|
||||||
|
|
||||||
// Execute the view query
|
// Create the Windows Installer object
|
||||||
view.Execute(null);
|
var installer = (Installer) Activator.CreateInstance(installerType);
|
||||||
|
|
||||||
// Get the record from the view
|
// Open the MSI database in the input file
|
||||||
Record record = view.Fetch();
|
var database = installer.OpenDatabase(inputFileName, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
|
||||||
|
|
||||||
// Get the version from the data
|
// Open a view on the Property table for the version property
|
||||||
string version = record.get_StringData(2);
|
var view = database.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'");
|
||||||
|
|
||||||
|
// Execute the view query
|
||||||
|
view.Execute();
|
||||||
|
|
||||||
|
// Get the record from the view
|
||||||
|
var record = view.Fetch();
|
||||||
|
|
||||||
|
// Get the version from the data
|
||||||
|
version = record.StringData[2];
|
||||||
|
}
|
||||||
|
else if (extension.Equals(".exe", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".dll", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
// Just use the version info from the file
|
||||||
|
version = FileVersionInfo.GetVersionInfo(inputFileName).FileVersion;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Unsupported file extension");
|
||||||
|
}
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
// Create the XML writer
|
// Create the XML writer
|
||||||
XmlTextWriter xmlWriter = new XmlTextWriter(outputFile, null) { Formatting = Formatting.Indented };
|
var xmlWriter = new XmlTextWriter(outputFileName, null) { Formatting = Formatting.Indented };
|
||||||
|
|
||||||
// Write the root tag
|
// Write the root tag
|
||||||
xmlWriter.WriteStartElement("versionInformation");
|
xmlWriter.WriteStartElement("versionInformation");
|
||||||
@@ -56,7 +76,7 @@ namespace CreateInstallDescriptor
|
|||||||
|
|
||||||
// Write the installer name tag
|
// Write the installer name tag
|
||||||
xmlWriter.WriteStartElement("installFile");
|
xmlWriter.WriteStartElement("installFile");
|
||||||
xmlWriter.WriteValue(Path.GetFileName(inputFile));
|
xmlWriter.WriteValue(Path.GetFileName(inputFileName));
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
|
|
||||||
// Write the installer date tag
|
// Write the installer date tag
|
||||||
|
|||||||
Reference in New Issue
Block a user