@@ -122,45 +122,43 @@ private static void EnumerateFolderBookmark(JsonElement folderElement, ICollecti
122
122
123
123
private void LoadFaviconsFromDb ( string dbPath , List < Bookmark > bookmarks )
124
124
{
125
+ // Use a copy to avoid lock issues with the original file
126
+ var tempDbPath = Path . Combine ( _faviconCacheDir , $ "tempfavicons_{ Guid . NewGuid ( ) } .db") ;
127
+
125
128
try
126
129
{
127
- // Use a copy to avoid lock issues with the original file
128
- var tempDbPath = Path . Combine ( _faviconCacheDir , $ "tempfavicons_{ Guid . NewGuid ( ) } .db") ;
130
+ File . Copy ( dbPath , tempDbPath , true ) ;
131
+ }
132
+ catch ( Exception ex )
133
+ {
134
+ Main . _context . API . LogException ( ClassName , $ "Failed to copy favicon DB: { dbPath } ", ex ) ;
135
+ return ;
136
+ }
137
+ finally
138
+ {
139
+ File . Delete ( tempDbPath ) ;
140
+ }
129
141
130
- try
131
- {
132
- File . Copy ( dbPath , tempDbPath , true ) ;
133
- }
134
- catch ( Exception ex )
135
- {
136
- Main . _context . API . LogException ( ClassName , $ "Failed to copy favicon DB: { dbPath } ", ex ) ;
137
- return ;
138
- }
139
- finally
140
- {
141
- File . Delete ( tempDbPath ) ;
142
- }
142
+ try
143
+ {
144
+ using var connection = new SqliteConnection ( $ "Data Source={ tempDbPath } ") ;
145
+ connection . Open ( ) ;
143
146
144
- try
147
+ foreach ( var bookmark in bookmarks )
145
148
{
146
- using var connection = new SqliteConnection ( $ "Data Source={ tempDbPath } ") ;
147
- connection . Open ( ) ;
148
-
149
- foreach ( var bookmark in bookmarks )
149
+ try
150
150
{
151
- try
152
- {
153
- var url = bookmark . Url ;
154
- if ( string . IsNullOrEmpty ( url ) ) continue ;
151
+ var url = bookmark . Url ;
152
+ if ( string . IsNullOrEmpty ( url ) ) continue ;
155
153
156
- // Extract domain from URL
157
- if ( ! Uri . TryCreate ( url , UriKind . Absolute , out Uri uri ) )
158
- continue ;
154
+ // Extract domain from URL
155
+ if ( ! Uri . TryCreate ( url , UriKind . Absolute , out Uri uri ) )
156
+ continue ;
159
157
160
- var domain = uri . Host ;
158
+ var domain = uri . Host ;
161
159
162
- using var cmd = connection . CreateCommand ( ) ;
163
- cmd . CommandText = @"
160
+ using var cmd = connection . CreateCommand ( ) ;
161
+ cmd . CommandText = @"
164
162
SELECT f.id, b.image_data
165
163
FROM favicons f
166
164
JOIN favicon_bitmaps b ON f.id = b.icon_id
@@ -169,51 +167,46 @@ WHERE m.page_url LIKE @url
169
167
ORDER BY b.width DESC
170
168
LIMIT 1" ;
171
169
172
- cmd . Parameters . AddWithValue ( "@url" , $ "%{ domain } %") ;
170
+ cmd . Parameters . AddWithValue ( "@url" , $ "%{ domain } %") ;
173
171
174
- using var reader = cmd . ExecuteReader ( ) ;
175
- if ( ! reader . Read ( ) || reader . IsDBNull ( 1 ) )
176
- continue ;
172
+ using var reader = cmd . ExecuteReader ( ) ;
173
+ if ( ! reader . Read ( ) || reader . IsDBNull ( 1 ) )
174
+ continue ;
177
175
178
- var iconId = reader . GetInt64 ( 0 ) . ToString ( ) ;
179
- var imageData = ( byte [ ] ) reader [ "image_data" ] ;
176
+ var iconId = reader . GetInt64 ( 0 ) . ToString ( ) ;
177
+ var imageData = ( byte [ ] ) reader [ "image_data" ] ;
180
178
181
- if ( imageData is not { Length : > 0 } )
182
- continue ;
179
+ if ( imageData is not { Length : > 0 } )
180
+ continue ;
183
181
184
- var faviconPath = Path . Combine ( _faviconCacheDir , $ "chromium_{ domain } _{ iconId } .png") ;
185
- SaveBitmapData ( imageData , faviconPath ) ;
182
+ var faviconPath = Path . Combine ( _faviconCacheDir , $ "chromium_{ domain } _{ iconId } .png") ;
183
+ SaveBitmapData ( imageData , faviconPath ) ;
186
184
187
- bookmark . FaviconPath = faviconPath ;
188
- }
189
- catch ( Exception ex )
190
- {
191
- Main . _context . API . LogException ( ClassName , $ "Failed to extract bookmark favicon: { bookmark . Url } ", ex ) ;
192
- }
185
+ bookmark . FaviconPath = faviconPath ;
186
+ }
187
+ catch ( Exception ex )
188
+ {
189
+ Main . _context . API . LogException ( ClassName , $ "Failed to extract bookmark favicon: { bookmark . Url } ", ex ) ;
193
190
}
194
-
195
- // https://github.com/dotnet/efcore/issues/26580
196
- SqliteConnection . ClearPool ( connection ) ;
197
- connection . Close ( ) ;
198
- }
199
- catch ( Exception ex )
200
- {
201
- Main . _context . API . LogException ( ClassName , $ "Failed to connect to SQLite: { tempDbPath } ", ex ) ;
202
191
}
203
192
204
- // Delete temporary file
205
- try
206
- {
207
- File . Delete ( tempDbPath ) ;
208
- }
209
- catch ( Exception ex )
210
- {
211
- Main . _context . API . LogException ( ClassName , $ "Failed to delete temporary favicon DB: { tempDbPath } ", ex ) ;
212
- }
193
+ // https://github.com/dotnet/efcore/issues/26580
194
+ SqliteConnection . ClearPool ( connection ) ;
195
+ connection . Close ( ) ;
196
+ }
197
+ catch ( Exception ex )
198
+ {
199
+ Main . _context . API . LogException ( ClassName , $ "Failed to connect to SQLite: { tempDbPath } ", ex ) ;
200
+ }
201
+
202
+ // Delete temporary file
203
+ try
204
+ {
205
+ File . Delete ( tempDbPath ) ;
213
206
}
214
207
catch ( Exception ex )
215
208
{
216
- Main . _context . API . LogException ( ClassName , $ "Failed to load favicon DB: { dbPath } ", ex ) ;
209
+ Main . _context . API . LogException ( ClassName , $ "Failed to delete temporary favicon DB: { tempDbPath } ", ex ) ;
217
210
}
218
211
}
219
212
0 commit comments