@@ -17,7 +17,7 @@ namespace SourceGit.Models
17
17
{
18
18
public interface IAvatarHost
19
19
{
20
- void OnAvatarResourceChanged ( string email ) ;
20
+ void OnAvatarResourceChanged ( string email , Bitmap image ) ;
21
21
}
22
22
23
23
public partial class AvatarManager
@@ -119,7 +119,7 @@ public void Start()
119
119
Dispatcher . UIThread . InvokeAsync ( ( ) =>
120
120
{
121
121
_resources [ email ] = img ;
122
- NotifyResourceChanged ( email ) ;
122
+ NotifyResourceChanged ( email , img ) ;
123
123
} ) ;
124
124
}
125
125
@@ -151,7 +151,7 @@ public Bitmap Request(string email, bool forceRefetch)
151
151
if ( File . Exists ( localFile ) )
152
152
File . Delete ( localFile ) ;
153
153
154
- NotifyResourceChanged ( email ) ;
154
+ NotifyResourceChanged ( email , null ) ;
155
155
}
156
156
else
157
157
{
@@ -186,6 +186,37 @@ public Bitmap Request(string email, bool forceRefetch)
186
186
return null ;
187
187
}
188
188
189
+ public void SetFromLocal ( string email , string file )
190
+ {
191
+ try
192
+ {
193
+ Bitmap image = null ;
194
+
195
+ using ( var stream = File . OpenRead ( file ) )
196
+ {
197
+ image = Bitmap . DecodeToWidth ( stream , 128 ) ;
198
+ }
199
+
200
+ if ( image == null )
201
+ return ;
202
+
203
+ if ( _resources . ContainsKey ( email ) )
204
+ _resources [ email ] = image ;
205
+ else
206
+ _resources . Add ( email , image ) ;
207
+
208
+ _requesting . Remove ( email ) ;
209
+
210
+ var store = Path . Combine ( _storePath , GetEmailHash ( email ) ) ;
211
+ File . Copy ( file , store , true ) ;
212
+ NotifyResourceChanged ( email , image ) ;
213
+ }
214
+ catch
215
+ {
216
+ // ignore
217
+ }
218
+ }
219
+
189
220
private void LoadDefaultAvatar ( string key , string img )
190
221
{
191
222
var icon = AssetLoader . Open ( new Uri ( $ "avares://SourceGit/Resources/Images/{ img } ", UriKind . RelativeOrAbsolute ) ) ;
@@ -203,12 +234,10 @@ private string GetEmailHash(string email)
203
234
return builder . ToString ( ) ;
204
235
}
205
236
206
- private void NotifyResourceChanged ( string email )
237
+ private void NotifyResourceChanged ( string email , Bitmap image )
207
238
{
208
239
foreach ( var avatar in _avatars )
209
- {
210
- avatar . OnAvatarResourceChanged ( email ) ;
211
- }
240
+ avatar . OnAvatarResourceChanged ( email , image ) ;
212
241
}
213
242
}
214
243
}
0 commit comments