1
0
mirror of synced 2024-11-28 01:10:51 +01:00

Fixes for batch bflim

This commit is contained in:
KillzXGaming 2019-06-25 21:23:00 -04:00
parent 5e0790ab8e
commit 7ad04eedad
8 changed files with 70 additions and 3 deletions

Binary file not shown.

View File

@ -194,7 +194,7 @@ namespace FirstPlugin
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = Utils.GetAllFilters(typeof(BFLIM));
ofd.Filter = Utils.GetAllFilters(new Type[] { typeof(BFLIM), typeof(SARC) });
if (ofd.ShowDialog() == DialogResult.OK)
{
@ -203,7 +203,7 @@ namespace FirstPlugin
{
foreach (string file in ofd.FileNames)
{
var FileFormat = STFileLoader.OpenFileFormat(file);
var FileFormat = STFileLoader.OpenFileFormat(file, new Type[] { typeof(BFLIM), typeof(SARC) });
if (FileFormat == null)
continue;
@ -220,7 +220,7 @@ namespace FirstPlugin
{
foreach (var file in ((SARC)FileFormat).Files)
{
var archiveFile = STFileLoader.OpenFileFormat(file.FullName, file.Data);
var archiveFile = STFileLoader.OpenFileFormat(file.FullName, new Type[] { typeof(BFLIM) , typeof(SARC) }, file.Data);
if (archiveFile == null)
continue;

View File

@ -1,5 +1,6 @@
using Syroot.BinaryData;
using System.IO;
using System;
using System.IO.Compression;
using OpenTK;
using System.Windows.Forms;
@ -29,6 +30,45 @@ namespace Switch_Toolbox.Library.IO
else
return null;
}
public static IFileFormat OpenFileFormat(string FileName, Type[] FileType, byte[] data = null)
{
Stream stream;
if (data != null)
stream = new MemoryStream(data);
else
stream = File.OpenRead(FileName);
foreach (IFileFormat fileFormat in FileManager.GetFileFormats())
{
foreach (Type type in FileType)
{
if (fileFormat.GetType() == type)
return OpenFileFormat(FileName, data);
}
}
return null;
}
public static IFileFormat OpenFileFormat(string FileName, Type FileType, byte[] data = null)
{
Stream stream;
if (data != null)
stream = new MemoryStream(data);
else
stream = File.OpenRead(FileName);
foreach (IFileFormat fileFormat in FileManager.GetFileFormats())
{
if (fileFormat.GetType() == FileType)
return OpenFileFormat(FileName, data);
}
return null;
}
/// <summary>
/// Gets the <see cref="IFileFormat"/> from a file or byte array.
/// </summary>

View File

@ -194,6 +194,28 @@ namespace Switch_Toolbox.Library
return Guid.NewGuid().ToString();
}
public static string GetAllFilters(Type[] Types)
{
string Filter = "All Supported Files|";
List<string> FilterEach = new List<string>();
foreach (var type in Types)
{
Object instance = Activator.CreateInstance(type);
IFileFormat f = (IFileFormat)instance;
for (int i = 0; i < f.Extension.Length; i++)
{
Filter += $"{f.Extension[i]};";
FilterEach.Add($"{f.Description[0]} ({f.Extension[i]}) |{f.Extension[i]}|");
}
}
Filter += "|";
Filter += string.Join("", FilterEach.ToArray());
Filter += "All files(*.*)|*.*";
return Filter;
}
public static string GetAllFilters(Type type)
{
Object instance = Activator.CreateInstance(type);
@ -244,5 +266,10 @@ namespace Switch_Toolbox.Library
Filter += "All files(*.*)|*.*";
return Filter;
}
private static void AddCompressionExtensions()
{
}
}
}