-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac98727
Showing
10 changed files
with
976 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# bin and obj directories | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# VisualStudio's *.suo files | ||
*.suo |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace updater_cli | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var list = detection.DetectorRegistry.detect(); | ||
foreach (var item in list) | ||
{ | ||
Console.WriteLine("\"" + item.displayName + "\", version \"" + item.displayVersion + "\""); | ||
Console.WriteLine(" Install: \"" + item.installPath + "\""); | ||
Console.WriteLine(); | ||
} | ||
|
||
list = detection.DetectorMSI.detect(); | ||
foreach (var item in list) | ||
{ | ||
Console.WriteLine("\"" + item.displayName + "\", version \"" + item.displayVersion + "\""); | ||
Console.WriteLine(" Install: \"" + item.installPath + "\""); | ||
Console.WriteLine(); | ||
} | ||
} //Main | ||
} //class | ||
} //namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// Allgemeine Informationen über eine Assembly werden über die folgenden | ||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, | ||
// die mit einer Assembly verknüpft sind. | ||
[assembly: AssemblyTitle("updater-cli")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("updater-cli")] | ||
[assembly: AssemblyCopyright("Copyright © 2016 Dirk Stolle")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar | ||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von | ||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. | ||
[assembly: ComVisible(false)] | ||
|
||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird | ||
[assembly: Guid("6e49750a-0093-491c-8506-d0e885981c22")] | ||
|
||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: | ||
// | ||
// Hauptversion | ||
// Nebenversion | ||
// Buildnummer | ||
// Revision | ||
// | ||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern | ||
// übernehmen, indem Sie "*" eingeben: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("0.1.0.0")] | ||
[assembly: AssemblyFileVersion("0.1.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace updater_cli.detection | ||
{ | ||
public class DetectorMSI | ||
{ | ||
[DllImport("msi.dll", CharSet = CharSet.Unicode)] | ||
static extern Int32 MsiGetProductInfo(string product, string property, | ||
[Out] StringBuilder valueBuf, ref Int32 len); | ||
|
||
[DllImport("msi.dll", SetLastError = true)] | ||
static extern int MsiEnumProducts(int iProductIndex, | ||
StringBuilder lpProductBuf); | ||
|
||
|
||
/// <summary> | ||
/// tries to get a list of installed software from the MSI cache | ||
/// </summary> | ||
/// <returns>Returns a list of installed software.</returns> | ||
public static List<Entry> detect() | ||
{ | ||
List<Entry> entries = new List<Entry>(); | ||
StringBuilder sbProductCode = new StringBuilder(39); | ||
int iIdx = 0; | ||
while (0 == MsiEnumProducts(iIdx++, sbProductCode)) | ||
{ | ||
Int32 productNameLen = 512; | ||
StringBuilder sbProductName = new StringBuilder(productNameLen); | ||
MsiGetProductInfo(sbProductCode.ToString(), "ProductName", sbProductName, ref productNameLen); | ||
Int32 installDirLen = 1024; | ||
StringBuilder sbInstallDir = new StringBuilder(installDirLen); | ||
MsiGetProductInfo(sbProductCode.ToString(), "InstallLocation", sbInstallDir, ref installDirLen); | ||
var e = new Entry(sbProductName.ToString(), null, sbInstallDir.ToString()); | ||
if (e.containsInformation()) | ||
entries.Add(e); | ||
} //while | ||
return entries; | ||
} | ||
} //class | ||
} //namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Win32; | ||
|
||
namespace updater_cli.detection | ||
{ | ||
public class DetectorRegistry | ||
{ | ||
/// <summary> | ||
/// tries to get a list of installed software from the registry | ||
/// </summary> | ||
/// <returns>Returns a list of installed software.</returns> | ||
public static List<Entry> detect() | ||
{ | ||
string keyName = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(keyName); | ||
if (null == rKey) | ||
return null; | ||
|
||
List<Entry> entries = new List<Entry>(); | ||
var subKeys = rKey.GetSubKeyNames(); | ||
foreach (var subName in subKeys) | ||
{ | ||
RegistryKey subKey = rKey.OpenSubKey(subName); | ||
if (null != subKey) | ||
{ | ||
Entry e = new Entry(); | ||
object dnObj = subKey.GetValue("DisplayName"); | ||
if (null != dnObj) | ||
e.displayName = dnObj.ToString().Trim(); | ||
object dvObj = subKey.GetValue("DisplayVersion"); | ||
if (null != dvObj) | ||
e.displayVersion = dvObj.ToString().Trim(); | ||
object ilObj = subKey.GetValue("InstallLocation"); | ||
if (null != ilObj) | ||
e.installPath = ilObj.ToString().Trim(); | ||
subKey.Close(); | ||
subKey = null; | ||
if (e.containsInformation()) | ||
entries.Add(e); | ||
} //if subKey was opened | ||
} //foreach | ||
subKeys = null; | ||
rKey.Close(); | ||
rKey = null; | ||
return entries; | ||
} | ||
} //class | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace updater_cli.detection | ||
{ | ||
/// <summary> | ||
/// struct that represents a detected software | ||
/// </summary> | ||
public struct Entry | ||
{ | ||
/// <summary> | ||
/// default constructor | ||
/// </summary> | ||
public Entry(string dispName = null, string dispVersion = null, string instPath = null) | ||
{ | ||
displayName = dispName; | ||
displayVersion = dispVersion; | ||
installPath = instPath; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// checks whether the entry contains some basic information | ||
/// </summary> | ||
/// <returns>Returns true, if at least the name of the software is set.</returns> | ||
public bool containsInformation() | ||
{ | ||
return !string.IsNullOrWhiteSpace(displayName); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// the displayed name of the software | ||
/// </summary> | ||
public string displayName; | ||
|
||
|
||
/// <summary> | ||
/// displayed version of the software | ||
/// </summary> | ||
public string displayVersion; | ||
|
||
|
||
/// <summary> | ||
/// path where the software is installed | ||
/// </summary> | ||
public string installPath; | ||
|
||
/* | ||
public int Compare(Entry other) | ||
{ | ||
int c = string.Compare(this.displayName, other.displayName); | ||
if (c != 0) | ||
return c; | ||
return string.Compare(this.displayVersion, other.displayVersion); | ||
*/ | ||
} //struct | ||
} //namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{6CE74677-6889-4E18-AF1A-C933AE211AB6}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>updater_cli</RootNamespace> | ||
<AssemblyName>updater-cli</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="detection\DetectorMSI.cs" /> | ||
<Compile Include="detection\Entry.cs" /> | ||
<Compile Include="detection\DetectorRegistry.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<WCFMetadata Include="Service References\" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual C# Express 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "updater-cli", "updater-cli.csproj", "{6CE74677-6889-4E18-AF1A-C933AE211AB6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6CE74677-6889-4E18-AF1A-C933AE211AB6}.Debug|x86.ActiveCfg = Debug|x86 | ||
{6CE74677-6889-4E18-AF1A-C933AE211AB6}.Debug|x86.Build.0 = Debug|x86 | ||
{6CE74677-6889-4E18-AF1A-C933AE211AB6}.Release|x86.ActiveCfg = Release|x86 | ||
{6CE74677-6889-4E18-AF1A-C933AE211AB6}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |