mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using Microsoft.WindowsAPICodePack.Dialogs;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Media.Imaging;
|
|
using Wabbajack.Common;
|
|
|
|
namespace Wabbajack.Lib
|
|
{
|
|
public static class UIUtils
|
|
{
|
|
public static BitmapImage BitmapImageFromResource(string name) => BitmapImageFromStream(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Wabbajack;component/" + name)).Stream);
|
|
|
|
public static BitmapImage BitmapImageFromStream(Stream stream)
|
|
{
|
|
var img = new BitmapImage();
|
|
img.BeginInit();
|
|
img.StreamSource = stream;
|
|
img.EndInit();
|
|
return img;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
public static string OpenFileDialog(string filter, string initialDirectory = null)
|
|
{
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
ofd.Filter = filter;
|
|
ofd.InitialDirectory = initialDirectory;
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
return ofd.FileName;
|
|
return null;
|
|
}
|
|
}
|
|
}
|