2019-10-07 17:33:34 +00:00
|
|
|
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
|
|
|
|
using System;
|
2019-10-16 03:17:27 +00:00
|
|
|
|
using System.IO;
|
2019-09-18 21:37:32 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-09-27 04:07:54 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-10-16 03:17:27 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-09-18 21:37:32 +00:00
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib
|
2019-09-18 21:37:32 +00:00
|
|
|
|
{
|
|
|
|
|
public static class UIUtils
|
|
|
|
|
{
|
2019-11-29 23:56:56 +00:00
|
|
|
|
public static BitmapImage BitmapImageFromResource(string name) => BitmapImageFromStream(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Wabbajack;component/" + name)).Stream);
|
2019-10-25 04:26:29 +00:00
|
|
|
|
|
|
|
|
|
public static BitmapImage BitmapImageFromStream(Stream stream)
|
2019-09-27 04:07:54 +00:00
|
|
|
|
{
|
|
|
|
|
var img = new BitmapImage();
|
|
|
|
|
img.BeginInit();
|
2019-12-15 19:09:07 +00:00
|
|
|
|
img.CacheOption = BitmapCacheOption.OnLoad;
|
2019-10-25 04:26:29 +00:00
|
|
|
|
img.StreamSource = stream;
|
2019-09-27 04:07:54 +00:00
|
|
|
|
img.EndInit();
|
2019-12-15 19:09:07 +00:00
|
|
|
|
img.Freeze();
|
2019-09-27 04:07:54 +00:00
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 04:26:29 +00:00
|
|
|
|
public static bool TryGetBitmapImageFromFile(string path, out BitmapImage bitmapImage)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
bitmapImage = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bitmapImage = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
bitmapImage = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public static string OpenFileDialog(string filter, string initialDirectory = null)
|
2019-09-27 04:07:54 +00:00
|
|
|
|
{
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
ofd.Filter = filter;
|
2019-11-06 03:22:38 +00:00
|
|
|
|
ofd.InitialDirectory = initialDirectory;
|
2019-09-27 04:07:54 +00:00
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
return ofd.FileName;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-09-18 21:37:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|