mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Slideshow ModlistImage made into a derivative OaPH
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Splat;
|
using Splat;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -48,6 +48,9 @@ namespace Wabbajack
|
|||||||
private BitmapImage _Image;
|
private BitmapImage _Image;
|
||||||
public BitmapImage Image { get => _Image; set => this.RaiseAndSetIfChanged(ref _Image, value); }
|
public BitmapImage Image { get => _Image; set => this.RaiseAndSetIfChanged(ref _Image, value); }
|
||||||
|
|
||||||
|
private readonly ObservableAsPropertyHelper<BitmapImage> _ModlistImage;
|
||||||
|
public BitmapImage ModlistImage => _ModlistImage.Value;
|
||||||
|
|
||||||
private string _ModName = "Wabbajack";
|
private string _ModName = "Wabbajack";
|
||||||
public string ModName { get => _ModName; set => this.RaiseAndSetIfChanged(ref _ModName, value); }
|
public string ModName { get => _ModName; set => this.RaiseAndSetIfChanged(ref _ModName, value); }
|
||||||
|
|
||||||
@ -89,53 +92,48 @@ namespace Wabbajack
|
|||||||
})
|
})
|
||||||
.DisposeWith(this.CompositeDisposable);
|
.DisposeWith(this.CompositeDisposable);
|
||||||
|
|
||||||
// Update splashscreen when modlist changes
|
this._ModlistImage = Observable.CombineLatest(
|
||||||
Observable.CombineLatest(
|
this.WhenAny(x => x.Installer.ModList),
|
||||||
(this).WhenAny(x => x.Installer.ModList),
|
this.WhenAny(x => x.Installer.ModListPath),
|
||||||
(this).WhenAny(x => x.Installer.ModListPath),
|
(modList, modListPath) => (modList, modListPath))
|
||||||
(this).WhenAny(x => x.Enable),
|
|
||||||
(modList, modListPath, enabled) => (modList, modListPath, enabled))
|
|
||||||
// Do any potential unzipping on a background thread
|
|
||||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||||
.Select(u =>
|
.Select(u =>
|
||||||
{
|
{
|
||||||
if (u.enabled
|
if (u.modList == null
|
||||||
&& u.modList != null
|
|| u.modListPath == null
|
||||||
&& u.modListPath != null
|
|| !File.Exists(u.modListPath)
|
||||||
&& File.Exists(u.modListPath)
|
|| string.IsNullOrEmpty(u.modList.Image)
|
||||||
&& !string.IsNullOrEmpty(u.modList.Image)
|
|| u.modList.Image.Length != 36)
|
||||||
&& u.modList.Image.Length == 36)
|
|
||||||
{
|
{
|
||||||
try
|
return default(BitmapImage);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var fs = new FileStream(u.modListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var fs = new FileStream(u.modListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
var entry = ar.GetEntry(u.modList.Image);
|
||||||
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
using (var e = entry.Open())
|
||||||
using (var ms = new MemoryStream())
|
e.CopyTo(ms);
|
||||||
{
|
var image = new BitmapImage();
|
||||||
var entry = ar.GetEntry(u.modList.Image);
|
image.BeginInit();
|
||||||
using (var e = entry.Open())
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
e.CopyTo(ms);
|
image.StreamSource = ms;
|
||||||
var image = new BitmapImage();
|
image.EndInit();
|
||||||
image.BeginInit();
|
image.Freeze();
|
||||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
|
||||||
image.StreamSource = ms;
|
|
||||||
image.EndInit();
|
|
||||||
image.Freeze();
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
this.Log().Warn(ex, "Error loading splash image.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.WabbajackLogo;
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.Log().Warn(ex, "Error loading modlist splash image.");
|
||||||
|
return default(BitmapImage);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.ObserveOn(RxApp.MainThreadScheduler)
|
.ObserveOnGuiThread()
|
||||||
.StartWith(this.WabbajackLogo)
|
.ToProperty(this, nameof(this.ModlistImage));
|
||||||
.Subscribe(bitmap => this.Image = bitmap)
|
|
||||||
.DisposeWith(this.CompositeDisposable);
|
|
||||||
|
|
||||||
/// Wire slideshow updates
|
/// Wire slideshow updates
|
||||||
// Merge all the sources that trigger a slideshow update
|
// Merge all the sources that trigger a slideshow update
|
||||||
|
Reference in New Issue
Block a user