mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Cache favicons
This commit is contained in:
parent
83f49bab59
commit
843396f7c4
@ -102,6 +102,7 @@ namespace Wabbajack.Common
|
|||||||
public const string ModListExtensionString = ".wabbajack";
|
public const string ModListExtensionString = ".wabbajack";
|
||||||
public static Extension ModListExtension = new Extension(ModListExtensionString);
|
public static Extension ModListExtension = new Extension(ModListExtensionString);
|
||||||
public static AbsolutePath LocalAppDataPath => new AbsolutePath(Path.Combine(KnownFolders.LocalAppData.Path, "Wabbajack"));
|
public static AbsolutePath LocalAppDataPath => new AbsolutePath(Path.Combine(KnownFolders.LocalAppData.Path, "Wabbajack"));
|
||||||
|
public static AbsolutePath FaviconCacheFolderPath => LocalAppDataPath.Combine("favicons");
|
||||||
public static string MetricsKeyHeader => "x-metrics-key";
|
public static string MetricsKeyHeader => "x-metrics-key";
|
||||||
|
|
||||||
public static string WabbajackCacheLocation = "http://build.wabbajack.org/nexus_api_cache/";
|
public static string WabbajackCacheLocation = "http://build.wabbajack.org/nexus_api_cache/";
|
||||||
|
@ -15,6 +15,7 @@ using System.Windows.Threading;
|
|||||||
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
|
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
|
using Wabbajack.Common;
|
||||||
using Wabbajack.Lib;
|
using Wabbajack.Lib;
|
||||||
using Wabbajack.Lib.Downloaders;
|
using Wabbajack.Lib.Downloaders;
|
||||||
|
|
||||||
@ -84,22 +85,50 @@ namespace Wabbajack
|
|||||||
{
|
{
|
||||||
if (Login.IconUri == null) return;
|
if (Login.IconUri == null) return;
|
||||||
|
|
||||||
using var img = await new Wabbajack.Lib.Http.Client().GetAsync(Login.IconUri, errorsAsExceptions:false);
|
if(!Consts.FaviconCacheFolderPath.Exists)
|
||||||
if (!img.IsSuccessStatusCode) return;
|
Consts.FaviconCacheFolderPath.CreateDirectory();
|
||||||
|
|
||||||
var icoData = new MemoryStream(await img.Content.ReadAsByteArrayAsync());
|
var faviconIcon = Consts.FaviconCacheFolderPath.Combine($"{Login.SiteName}.ico");
|
||||||
|
if (faviconIcon.Exists)
|
||||||
|
{
|
||||||
|
await using var fs = await faviconIcon.OpenRead();
|
||||||
|
|
||||||
var data = new Icon(icoData);
|
var ms = new MemoryStream((int)fs.Length);
|
||||||
var ms = new MemoryStream();
|
await fs.CopyToAsync(ms);
|
||||||
data.ToBitmap().Save(ms, ImageFormat.Png);
|
ms.Position = 0;
|
||||||
ms.Position = 0;
|
|
||||||
|
|
||||||
var source = new BitmapImage();
|
var source = new BitmapImage();
|
||||||
source.BeginInit();
|
source.BeginInit();
|
||||||
source.StreamSource = ms;
|
source.StreamSource = ms;
|
||||||
source.EndInit();
|
source.EndInit();
|
||||||
source.Freeze();
|
source.Freeze();
|
||||||
Favicon = source;
|
Favicon = source;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using var img = await new Lib.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;
|
||||||
|
|
||||||
|
await using (var fs = await faviconIcon.Create())
|
||||||
|
{
|
||||||
|
await ms.CopyToAsync(fs);
|
||||||
|
ms.Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var source = new BitmapImage();
|
||||||
|
source.BeginInit();
|
||||||
|
source.StreamSource = ms;
|
||||||
|
source.EndInit();
|
||||||
|
source.Freeze();
|
||||||
|
Favicon = source;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user