-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from jannikbecker/staging
Version 0.6.0
- Loading branch information
Showing
20 changed files
with
325 additions
and
49 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
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
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
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,75 @@ | ||
using Leibit.Core.Common; | ||
using Leibit.Entities; | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Leibit.BLL | ||
{ | ||
public class SoftwareInfoBLL : BLLBase | ||
{ | ||
|
||
#region - Public methods - | ||
|
||
#region [GetSoftwareInfo] | ||
public OperationResult<SoftwareInfo> GetSoftwareInfo(string softwareName) | ||
{ | ||
try | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
return OperationResult<SoftwareInfo>.Ok(new SoftwareInfo { IsInstalled = false }); | ||
|
||
var key = __Search(Registry.CurrentUser, softwareName); | ||
|
||
if (key == null) | ||
key = __Search(Registry.LocalMachine, softwareName); | ||
|
||
if (key == null) | ||
return OperationResult<SoftwareInfo>.Ok(new SoftwareInfo { IsInstalled = false }); | ||
|
||
var result = new SoftwareInfo(); | ||
result.IsInstalled = true; | ||
result.DisplayName = key.GetValue("DisplayName")?.ToString(); | ||
result.DisplayVersion = key.GetValue("DisplayVersion")?.ToString(); | ||
result.InstallLocation = key.GetValue("InstallLocation")?.ToString(); | ||
return OperationResult<SoftwareInfo>.Ok(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return OperationResult<SoftwareInfo>.Fail(ex.ToString()); | ||
} | ||
} | ||
#endregion | ||
|
||
#endregion | ||
|
||
#region - Private helpers - | ||
|
||
#region [__Search] | ||
private RegistryKey __Search(RegistryKey key, string softwareName) | ||
{ | ||
var baseKey = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); | ||
|
||
foreach (var subKeyName in baseKey.GetSubKeyNames()) | ||
{ | ||
var candidate = baseKey.OpenSubKey(subKeyName); | ||
var displayName = candidate.GetValue("DisplayName")?.ToString(); | ||
|
||
if (displayName == null) | ||
continue; | ||
|
||
displayName = displayName.Replace(" ", string.Empty).Replace("-", string.Empty); | ||
softwareName = softwareName.Replace(" ", string.Empty).Replace("-", string.Empty); | ||
|
||
if (displayName.Contains(softwareName)) | ||
return candidate; | ||
} | ||
|
||
return null; | ||
} | ||
#endregion | ||
|
||
#endregion | ||
|
||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
Oops, something went wrong.