12
12
* GNU General Public License for more details.
13
13
********************************************************************/
14
14
15
+ #nullable enable
15
16
using System ;
16
17
using Microsoft . Extensions . Caching . Memory ;
17
18
using NAudio . CoreAudioApi ;
18
19
using Serilog ;
19
- using SoundSwitch . Common . Framework . Icon ;
20
20
using SoundSwitch . Common . Properties ;
21
21
22
22
namespace SoundSwitch . Common . Framework . Audio . Icon
@@ -28,7 +28,7 @@ public class AudioDeviceIconExtractor
28
28
29
29
private static readonly IMemoryCache IconCache = new MemoryCache ( new MemoryCacheOptions
30
30
{
31
- SizeLimit = 5120
31
+ SizeLimit = 3200
32
32
} ) ;
33
33
34
34
private static string GetKey ( MMDevice audioDevice , bool largeIcon )
@@ -45,7 +45,7 @@ private static string GetKey(MMDevice audioDevice, bool largeIcon)
45
45
/// <returns></returns>
46
46
public static System . Drawing . Icon ExtractIconFromPath ( string path , DataFlow dataFlow , bool largeIcon )
47
47
{
48
- System . Drawing . Icon ExtractAssociatedIcon ( )
48
+ System . Drawing . Icon ? ExtractAssociatedIcon ( )
49
49
{
50
50
if ( path . EndsWith ( ".ico" ) )
51
51
{
@@ -55,20 +55,24 @@ System.Drawing.Icon ExtractAssociatedIcon()
55
55
var iconInfo = path . Split ( ',' ) ;
56
56
var dllPath = iconInfo [ 0 ] ;
57
57
var iconIndex = int . Parse ( iconInfo [ 1 ] ) ;
58
- return IconExtractor . Extract ( dllPath , iconIndex , largeIcon ) ;
58
+ return System . Drawing . Icon . ExtractIcon ( dllPath , iconIndex , ! largeIcon ) ;
59
59
}
60
60
61
61
var key = $ "{ path } -${ largeIcon } ";
62
62
63
63
if ( IconCache . TryGetValue < System . Drawing . Icon > ( key , out var icon ) )
64
- return icon ;
64
+ return icon ! ;
65
65
66
66
try
67
67
{
68
68
icon = ExtractAssociatedIcon ( ) ;
69
+ if ( icon == null )
70
+ {
71
+ throw new ArgumentException ( "Can't find icon" ) ;
72
+ }
69
73
using var entry = IconCache . CreateEntry ( key ) ;
70
74
entry . SetValue ( icon )
71
- . SetSize ( icon . Size . Height * icon . Size . Width )
75
+ . SetSize ( icon . Size . Height )
72
76
. SetSlidingExpiration ( TimeSpan . FromMinutes ( 30 ) )
73
77
. SetPriority ( largeIcon ? CacheItemPriority . High : CacheItemPriority . Low )
74
78
. RegisterPostEvictionCallback ( ( o , value , reason , state ) =>
0 commit comments