Skip to content

Commit

Permalink
Fix for Issue #54 - Assign default icon for device if one does not ex…
Browse files Browse the repository at this point in the history
…ists
  • Loading branch information
nikhilogic committed Feb 8, 2016
1 parent c345a3f commit 8cdc8b8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Classes/DeviceIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using System.Windows.Forms;
using AudioSwitch.Properties;
using System.IO;

namespace AudioSwitch.Classes
{
Expand Down Expand Up @@ -57,16 +58,22 @@ internal static Icon GetIcon(string iconPath)
var path = is64bit ? iconPath.ToLower().Replace("\\system32\\", "\\sysnative\\") : iconPath;
path = Environment.ExpandEnvironmentVariables(path);
var iconAdr = path.Split(',');

Icon icon;
if (iconAdr.Length > 1)
Icon icon = null;
if (File.Exists(iconAdr[0]))
{
var hIconEx = new IntPtr[1];
ExtractIconEx(iconAdr[0], int.Parse(iconAdr[1]), hIconEx, null, 1);
icon = Icon.FromHandle(hIconEx[0]);
if (iconAdr.Length > 1)
{
var hIconEx = new IntPtr[1];
ExtractIconEx(iconAdr[0], int.Parse(iconAdr[1]), hIconEx, null, 1);
icon = Icon.FromHandle(hIconEx[0]);
}
else
icon = new Icon(iconAdr[0], NormalIcons.ImageSize.Width, NormalIcons.ImageSize.Height);
}
else
icon = new Icon(iconAdr[0], NormalIcons.ImageSize.Width, NormalIcons.ImageSize.Height);
{
icon = SystemIcons.Warning;
}
return icon;
}

Expand Down

0 comments on commit 8cdc8b8

Please sign in to comment.