2022-02-06 03:29:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
2022-02-13 14:15:13 +00:00
|
|
|
|
using System.IO;
|
2022-02-13 22:46:59 +00:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2022-02-06 03:29:03 +00:00
|
|
|
|
|
2022-02-13 14:15:13 +00:00
|
|
|
|
using Ionic.Zip;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ScrapModLoader;
|
|
|
|
|
|
|
|
|
|
internal static class Utils
|
2022-02-06 03:29:03 +00:00
|
|
|
|
{
|
2022-02-13 14:15:13 +00:00
|
|
|
|
public static String GetFolderDialog()
|
2022-02-06 03:29:03 +00:00
|
|
|
|
{
|
2022-02-13 14:15:13 +00:00
|
|
|
|
using System.Windows.Forms.FolderBrowserDialog? dialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
|
|
|
|
|
return dialog.SelectedPath;
|
|
|
|
|
}
|
2022-02-06 03:29:03 +00:00
|
|
|
|
|
2022-02-13 14:15:13 +00:00
|
|
|
|
public static List<String> StringCollectionToList(StringCollection collection)
|
|
|
|
|
{
|
|
|
|
|
List<String> list = new List<String>();
|
|
|
|
|
foreach (String? item in collection)
|
2022-02-06 03:29:03 +00:00
|
|
|
|
{
|
2022-02-13 14:15:13 +00:00
|
|
|
|
if (item != null)
|
|
|
|
|
list.Add(item);
|
2022-02-06 03:29:03 +00:00
|
|
|
|
}
|
2022-02-13 14:15:13 +00:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Byte[] ExtractFromZip(ZipFile zip, String entry_path)
|
|
|
|
|
{
|
|
|
|
|
ZipEntry? entry = zip[entry_path];
|
|
|
|
|
if (entry == null)
|
|
|
|
|
throw new FileFormatException($"No '{entry_path}' in {zip.Name} found");
|
|
|
|
|
|
2022-02-13 22:46:59 +00:00
|
|
|
|
Byte[] buffer = new Byte[entry.UncompressedSize];
|
|
|
|
|
using (MemoryStream zipStream = new MemoryStream(buffer))
|
2022-02-13 14:15:13 +00:00
|
|
|
|
entry.Extract(zipStream);
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BitmapImage LoadImage(Byte[] buffer)
|
|
|
|
|
{
|
2022-02-13 22:46:59 +00:00
|
|
|
|
using MemoryStream sourceStream = new MemoryStream(buffer);
|
2022-02-13 14:15:13 +00:00
|
|
|
|
|
2022-02-13 22:46:59 +00:00
|
|
|
|
BitmapImage? image = new BitmapImage();
|
2022-02-13 14:15:13 +00:00
|
|
|
|
|
|
|
|
|
image.BeginInit();
|
|
|
|
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
|
|
image.StreamSource = sourceStream;
|
|
|
|
|
image.EndInit();
|
|
|
|
|
|
|
|
|
|
return image;
|
2022-02-06 03:29:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-13 14:15:13 +00:00
|
|
|
|
|