@@ -17,7 +17,7 @@ namespace SourceGit.Models
1717{
1818 public interface IAvatarHost
1919 {
20- void OnAvatarResourceChanged ( string email ) ;
20+ void OnAvatarResourceChanged ( string email , Bitmap image ) ;
2121 }
2222
2323 public partial class AvatarManager
@@ -119,7 +119,7 @@ public void Start()
119119 Dispatcher . UIThread . InvokeAsync ( ( ) =>
120120 {
121121 _resources [ email ] = img ;
122- NotifyResourceChanged ( email ) ;
122+ NotifyResourceChanged ( email , img ) ;
123123 } ) ;
124124 }
125125
@@ -151,7 +151,7 @@ public Bitmap Request(string email, bool forceRefetch)
151151 if ( File . Exists ( localFile ) )
152152 File . Delete ( localFile ) ;
153153
154- NotifyResourceChanged ( email ) ;
154+ NotifyResourceChanged ( email , null ) ;
155155 }
156156 else
157157 {
@@ -186,6 +186,37 @@ public Bitmap Request(string email, bool forceRefetch)
186186 return null ;
187187 }
188188
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+
189220 private void LoadDefaultAvatar ( string key , string img )
190221 {
191222 var icon = AssetLoader . Open ( new Uri ( $ "avares://SourceGit/Resources/Images/{ img } ", UriKind . RelativeOrAbsolute ) ) ;
@@ -203,12 +234,10 @@ private string GetEmailHash(string email)
203234 return builder . ToString ( ) ;
204235 }
205236
206- private void NotifyResourceChanged ( string email )
237+ private void NotifyResourceChanged ( string email , Bitmap image )
207238 {
208239 foreach ( var avatar in _avatars )
209- {
210- avatar . OnAvatarResourceChanged ( email ) ;
211- }
240+ avatar . OnAvatarResourceChanged ( email , image ) ;
212241 }
213242 }
214243}
0 commit comments