Skip to content

Commit

Permalink
Add default icon for Speaker and Microphone.
Browse files Browse the repository at this point in the history
Used in case it can't be extacted from the DLL or that the path can't be parsed.
Fixes #23
  • Loading branch information
Antoine Aflalo committed Sep 2, 2015
1 parent e2c45ef commit 91bc736
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
20 changes: 20 additions & 0 deletions SoundSwitch/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions SoundSwitch/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@
<data name="Settings" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\cog.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MicDefaultIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MicDefaultIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SpeakerDefaultIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SpeakerDefaultIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added SoundSwitch/Resources/MicDefaultIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SoundSwitch/Resources/SpeakerDefaultIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions SoundSwitch/SoundSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="Resources\MicDefaultIcon.png" />
<None Include="Resources\SpeakerDefaultIcon.png" />
<None Include="Resources\page-bottom.png" />
<None Include="Resources\tick.png" />
<None Include="Resources\arrow-switch-16.png" />
Expand Down
1 change: 1 addition & 0 deletions SoundSwitch/UI/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using SoundSwitch.Framework.Configuration;
using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.Util;

namespace SoundSwitch.UI.Forms
{
Expand Down
33 changes: 27 additions & 6 deletions SoundSwitch/Util/AudioDeviceIconExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
* GNU General Public License for more details.
********************************************************************/

using System;
using System.Collections.Generic;
using System.Drawing;
using AudioEndPointControllerWrapper;
using SoundSwitch.Util;
using SoundSwitch.Framework;
using SoundSwitch.Properties;

namespace SoundSwitch.Framework
namespace SoundSwitch.Util
{
internal class AudioDeviceIconExtractor
{
Expand All @@ -36,10 +38,29 @@ public static Icon ExtractIconFromAudioDevice(IAudioDevice audioDevice, bool lar
{
return ico;
}
var iconInfo = audioDevice.DeviceClassIconPath.Split(',');
var dllPath = iconInfo[0];
var iconIndex = int.Parse(iconInfo[1]);
ico = IconExtractor.Extract(dllPath, iconIndex, largeIcon);
try
{
var iconInfo = audioDevice.DeviceClassIconPath.Split(',');
var dllPath = iconInfo[0];
var iconIndex = int.Parse(iconInfo[1]);
ico = IconExtractor.Extract(dllPath, iconIndex, largeIcon);
}
catch (Exception e)
{
AppLogger.Log.Error($"Can't extract icon from {audioDevice.DeviceClassIconPath}\n Ex: ", e);
switch (audioDevice.Type)
{
case AudioDeviceType.Playback:
ico = Icon.FromHandle(Resources.SpeakerDefaultIcon.GetHicon());
break;
case AudioDeviceType.Recording:
ico = Icon.FromHandle(Resources.MicDefaultIcon.GetHicon());
break;
default:
throw new ArgumentOutOfRangeException();
}
}

IconCache.Add(audioDevice.DeviceClassIconPath, ico);
return ico;
}
Expand Down

0 comments on commit 91bc736

Please sign in to comment.