From 2d457ad12d2efa6d955c0410d7c54ac74bf760a0 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Thu, 28 May 2020 22:09:39 -0600 Subject: [PATCH] Add favicons to login manager --- Wabbajack.Common/Paths.cs | 1 + .../Downloaders/BethesdaNetDownloader.cs | 2 +- Wabbajack.Lib/Downloaders/TESAllDownloader.cs | 4 +- .../View Models/Settings/LoginManagerVM.cs | 40 +++++++++++++++++++ Wabbajack/Views/Settings/LoginItemView.xaml | 14 +++++-- .../Views/Settings/LoginItemView.xaml.cs | 5 +++ 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/Wabbajack.Common/Paths.cs b/Wabbajack.Common/Paths.cs index 3b51aad9..ea8df171 100644 --- a/Wabbajack.Common/Paths.cs +++ b/Wabbajack.Common/Paths.cs @@ -556,6 +556,7 @@ namespace Wabbajack.Common public static AbsolutePath RelativeTo(this string str, AbsolutePath path) { + if (Path.IsPathRooted(str)) return (AbsolutePath)str; return ((RelativePath)str).RelativeTo(path); } diff --git a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs index d35958a2..60a76337 100644 --- a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs +++ b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs @@ -38,7 +38,7 @@ namespace Wabbajack.Lib.Downloaders public string SiteName => "Bethesda.NET"; public IObservable MetaInfo => Observable.Return(""); //"Wabbajack will start the game, then exit once you enter the Mods page"; public Uri SiteURL => new Uri("https://bethesda.net"); - public Uri? IconUri { get; } + public Uri? IconUri => new Uri("https://bethesda.net/favicon.ico"); public BethesdaNetDownloader() { diff --git a/Wabbajack.Lib/Downloaders/TESAllDownloader.cs b/Wabbajack.Lib/Downloaders/TESAllDownloader.cs index 8530e400..39dc57de 100644 --- a/Wabbajack.Lib/Downloaders/TESAllDownloader.cs +++ b/Wabbajack.Lib/Downloaders/TESAllDownloader.cs @@ -7,8 +7,8 @@ namespace Wabbajack.Lib.Downloaders { #region INeedsDownload public override string SiteName => "TESALL"; - public override Uri SiteURL => new Uri("http://tesall.ru"); - public override Uri IconUri => new Uri("http://tesall.ru/favicon.ico"); + public override Uri SiteURL => new Uri("https://tesall.ru"); + public override Uri IconUri => new Uri("https://tesall.ru/favicon.ico"); #endregion public TESAllDownloader() : base(new Uri("https://tesall.ru/index.php?app=core&module=global§ion=login"), diff --git a/Wabbajack/View Models/Settings/LoginManagerVM.cs b/Wabbajack/View Models/Settings/LoginManagerVM.cs index e7ad9745..fa0a03ee 100644 --- a/Wabbajack/View Models/Settings/LoginManagerVM.cs +++ b/Wabbajack/View Models/Settings/LoginManagerVM.cs @@ -1,12 +1,20 @@ using System; using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Threading; +using Microsoft.WindowsAPICodePack.Shell.PropertySystem; using ReactiveUI; +using ReactiveUI.Fody.Helpers; using Wabbajack.Lib; using Wabbajack.Lib.Downloaders; @@ -21,6 +29,7 @@ namespace Wabbajack { Downloaders = DownloadDispatcher.Downloaders .OfType() + .OrderBy(x => x.SiteName) .Select(x => new LoginTargetVM(x)) .ToList(); } @@ -37,10 +46,16 @@ namespace Wabbajack public ReactiveCommand TriggerCredentialsLogin; + private ImageSource _favicon = null; + + public ImageSource Favicon { get => _favicon; set => RaiseAndSetIfChanged(ref _favicon, value); } + public LoginTargetVM(INeedsLogin login) { Login = login; + LoadImage(); + if (login is INeedsLoginCredentials loginWithCredentials) { UsesCredentials = true; @@ -62,5 +77,30 @@ namespace Wabbajack loginWindow.Show(); }, LoginWithCredentials.IsLoggedIn.Select(b => !b).ObserveOnGuiThread()); } + + private void LoadImage() + { + Task.Run(async () => + { + if (Login.IconUri == null) return; + + using var img = await new Common.Http.Client().GetAsync(Login.IconUri, errorsAsExceptions:false); + if (!img.IsSuccessStatusCode) return; + + var icoData = new MemoryStream(await img.Content.ReadAsByteArrayAsync()); + + var data = new Icon(icoData); + var ms = new MemoryStream(); + data.ToBitmap().Save(ms, ImageFormat.Png); + ms.Position = 0; + + var source = new BitmapImage(); + source.BeginInit(); + source.StreamSource = ms; + source.EndInit(); + source.Freeze(); + Favicon = source; + }); + } } } diff --git a/Wabbajack/Views/Settings/LoginItemView.xaml b/Wabbajack/Views/Settings/LoginItemView.xaml index d1c3c916..60e42df1 100644 --- a/Wabbajack/Views/Settings/LoginItemView.xaml +++ b/Wabbajack/Views/Settings/LoginItemView.xaml @@ -12,28 +12,34 @@ mc:Ignorable="d"> + +