@@ -37,55 +37,16 @@ public static async Task InitializeAsync()
37
37
_storage = new BinaryStorage < List < ( string , bool ) > > ( "Image" ) ;
38
38
_hashGenerator = new ImageHashGenerator ( ) ;
39
39
40
- var usage = await LoadStorageToConcurrentDictionaryAsync ( ) ;
41
- _storage . ClearData ( ) ;
42
-
43
- ImageCache . Initialize ( usage ) ;
40
+ // Even though we no longer do image preloading and thus don't need _storage,
41
+ // for some reason MemoryPackSerializer exceptions appear when this is removed
42
+ await LoadStorageToConcurrentDictionaryAsync ( ) ;
44
43
45
44
foreach ( var icon in new [ ] { Constant . DefaultIcon , Constant . MissingImgIcon } )
46
45
{
47
46
ImageSource img = new BitmapImage ( new Uri ( icon ) ) ;
48
47
img . Freeze ( ) ;
49
48
ImageCache [ icon , false ] = img ;
50
49
}
51
-
52
- _ = Task . Run ( async ( ) =>
53
- {
54
- await Stopwatch . InfoAsync ( ClassName , "Preload images cost" , async ( ) =>
55
- {
56
- foreach ( var ( path , isFullImage ) in usage )
57
- {
58
- await LoadAsync ( path , isFullImage ) ;
59
- }
60
- } ) ;
61
- Log . Info ( ClassName , $ "Number of preload images is <{ ImageCache . CacheSize ( ) } >, Images Number: { ImageCache . CacheSize ( ) } , Unique Items { ImageCache . UniqueImagesInCache ( ) } ") ;
62
- } ) ;
63
- }
64
-
65
- public static async Task SaveAsync ( )
66
- {
67
- await storageLock . WaitAsync ( ) ;
68
-
69
- try
70
- {
71
- await _storage . SaveAsync ( ImageCache . EnumerateEntries ( )
72
- . Select ( x => x . Key )
73
- . ToList ( ) ) ;
74
- }
75
- catch ( System . Exception e )
76
- {
77
- Log . Exception ( ClassName , "Failed to save image cache to file" , e ) ;
78
- }
79
- finally
80
- {
81
- storageLock . Release ( ) ;
82
- }
83
- }
84
-
85
- public static async Task WaitSaveAsync ( )
86
- {
87
- await storageLock . WaitAsync ( ) ;
88
- storageLock . Release ( ) ;
89
50
}
90
51
91
52
private static async Task < List < ( string , bool ) > > LoadStorageToConcurrentDictionaryAsync ( )
@@ -276,6 +237,7 @@ public static bool TryGetValue(string path, bool loadFullImage, out ImageSource
276
237
277
238
public static async ValueTask < ImageSource > LoadAsync ( string path , bool loadFullImage = false , bool cacheImage = true )
278
239
{
240
+ path = path . ToLowerInvariant ( ) ;
279
241
var imageResult = await LoadInternalAsync ( path , loadFullImage ) ;
280
242
281
243
var img = imageResult . ImageSource ;
0 commit comments