mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #85 from erri120/slideshow-logging
Added logging to file for slideshow
This commit is contained in:
commit
fadb0e6381
@ -62,6 +62,16 @@ namespace Wabbajack.Common
|
||||
_loggerFn?.Invoke(msg);
|
||||
}
|
||||
|
||||
public static void LogToFile(string msg)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
msg = $"{(DateTime.Now - _startTime).TotalSeconds:0.##} - {msg}";
|
||||
|
||||
File.AppendAllText(LogFile, msg + "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Status(string msg, int progress = 0)
|
||||
{
|
||||
_statusFn?.Invoke(msg, progress);
|
||||
|
@ -119,37 +119,45 @@ namespace Wabbajack.UI
|
||||
|
||||
private void CacheImage(Slide slide)
|
||||
{
|
||||
Utils.LogToFile($"Caching slide for {slide.ModName} at {slide.ImageURL}");
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
if (UseSync)
|
||||
try
|
||||
{
|
||||
if (UseSync)
|
||||
{
|
||||
_appState.dispatcher.Invoke(() =>
|
||||
{
|
||||
using (var stream = new HttpClient().GetStreamSync(slide.ImageURL))
|
||||
stream.CopyTo(ms);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
using (Task<Stream> stream = new HttpClient().GetStreamAsync(slide.ImageURL))
|
||||
{
|
||||
stream.Wait();
|
||||
stream.Result.CopyTo(ms);
|
||||
}
|
||||
}
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
_appState.dispatcher.Invoke(() =>
|
||||
{
|
||||
using (var stream = new HttpClient().GetStreamSync(slide.ImageURL))
|
||||
stream.CopyTo(ms);
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
|
||||
slide.Image = image;
|
||||
});
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
using (Task<Stream> stream = new HttpClient().GetStreamAsync(slide.ImageURL))
|
||||
{
|
||||
stream.Wait();
|
||||
stream.Result.CopyTo(ms);
|
||||
}
|
||||
Utils.LogToFile($"Exception while caching slide {slide.ModName} ({slide.ModID})\n{e.ExceptionToString()}");
|
||||
}
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
_appState.dispatcher.Invoke(() =>
|
||||
{
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
|
||||
slide.Image = image;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user