mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 06:20:24 +00:00
Fix exporting opened and saved file formats from archives
This commit is contained in:
parent
217f53a148
commit
08cfbd99c9
3 changed files with 33 additions and 24 deletions
|
@ -182,7 +182,7 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
SaveFileDialog sfd = new SaveFileDialog();
|
SaveFileDialog sfd = new SaveFileDialog();
|
||||||
sfd.Filter = "Supported Formats|*.dae;*.json;";
|
sfd.Filter = "Supported Formats|*.dae;*.json;";
|
||||||
sfd.FileName = Text;
|
sfd.FileName = Path.GetFileNameWithoutExtension(Text);
|
||||||
sfd.DefaultExt = "dae";
|
sfd.DefaultExt = "dae";
|
||||||
if (sfd.ShowDialog() == DialogResult.OK)
|
if (sfd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace FirstPlugin
|
||||||
|
|
||||||
public static byte[] CreateVertexDataBuffer(STGenericObject mesh, List<int> SkinningIndices, IList<MeshAttribute> attributes)
|
public static byte[] CreateVertexDataBuffer(STGenericObject mesh, List<int> SkinningIndices, IList<MeshAttribute> attributes)
|
||||||
{
|
{
|
||||||
|
var stride = GetTotalBufferStride(attributes);
|
||||||
|
|
||||||
var mem = new System.IO.MemoryStream();
|
var mem = new System.IO.MemoryStream();
|
||||||
using (var writer = new FileWriter(mem))
|
using (var writer = new FileWriter(mem))
|
||||||
|
@ -35,6 +36,8 @@ namespace FirstPlugin
|
||||||
//Generate a buffer based on the attributes used
|
//Generate a buffer based on the attributes used
|
||||||
for (int v = 0; v < mesh.vertices.Count; v++)
|
for (int v = 0; v < mesh.vertices.Count; v++)
|
||||||
{
|
{
|
||||||
|
writer.SeekBegin(v * stride);
|
||||||
|
|
||||||
for (int a = 0; a < attributes.Count; a++)
|
for (int a = 0; a < attributes.Count; a++)
|
||||||
{
|
{
|
||||||
uint numAttributes = attributes[a].ElementCount;
|
uint numAttributes = attributes[a].ElementCount;
|
||||||
|
@ -51,7 +54,7 @@ namespace FirstPlugin
|
||||||
values.Add(mesh.vertices[v].nrm.X);
|
values.Add(mesh.vertices[v].nrm.X);
|
||||||
values.Add(mesh.vertices[v].nrm.Y);
|
values.Add(mesh.vertices[v].nrm.Y);
|
||||||
values.Add(mesh.vertices[v].nrm.Z);
|
values.Add(mesh.vertices[v].nrm.Z);
|
||||||
values.Add(0);
|
values.Add(mesh.vertices[v].normalW);
|
||||||
// values.Add(((GFLXMesh.GFLXVertex)mesh.vertices[v]).NormalW);
|
// values.Add(((GFLXMesh.GFLXVertex)mesh.vertices[v]).NormalW);
|
||||||
break;
|
break;
|
||||||
case VertexType.Color1:
|
case VertexType.Color1:
|
||||||
|
@ -128,12 +131,12 @@ namespace FirstPlugin
|
||||||
return mem.ToArray();
|
return mem.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint GetTotalBufferStride(Mesh mesh)
|
public static uint GetTotalBufferStride(IList<MeshAttribute> attributes)
|
||||||
{
|
{
|
||||||
uint VertBufferStride = 0;
|
uint VertBufferStride = 0;
|
||||||
for (int i = 0; i < mesh.Attributes?.Count; i++)
|
for (int i = 0; i < attributes?.Count; i++)
|
||||||
{
|
{
|
||||||
var attribute = mesh.Attributes[i];
|
var attribute = attributes[i];
|
||||||
switch ((VertexType)attribute.VertexType)
|
switch ((VertexType)attribute.VertexType)
|
||||||
{
|
{
|
||||||
case VertexType.Position:
|
case VertexType.Position:
|
||||||
|
@ -210,7 +213,7 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
List<Vertex> Vertices = new List<Vertex>();
|
List<Vertex> Vertices = new List<Vertex>();
|
||||||
|
|
||||||
uint VertBufferStride = GetTotalBufferStride(mesh);
|
uint VertBufferStride = GetTotalBufferStride(mesh.Attributes);
|
||||||
|
|
||||||
using (var reader = new FileReader(mesh.Data.ToArray()))
|
using (var reader = new FileReader(mesh.Data.ToArray()))
|
||||||
{
|
{
|
||||||
|
@ -417,9 +420,9 @@ namespace FirstPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void WriteBuffer(FileWriter writer, uint ElementCount, float[] value, BufferFormat Format, VertexType AttributeType)
|
private static void WriteBuffer(FileWriter writer, uint elementCount, float[] value, BufferFormat Format, VertexType AttributeType)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ElementCount; i++)
|
for (int i = 0; i < elementCount; i++)
|
||||||
{
|
{
|
||||||
switch (Format)
|
switch (Format)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,18 +93,25 @@ namespace Toolbox.Library
|
||||||
var Collection = TreeViewExtensions.Collect(Nodes);
|
var Collection = TreeViewExtensions.Collect(Nodes);
|
||||||
|
|
||||||
int Curfile = 0;
|
int Curfile = 0;
|
||||||
foreach (TreeNode file in Collection)
|
foreach (TreeNode node in Collection)
|
||||||
{
|
{
|
||||||
if (file is ArchiveFileWrapper)
|
ArchiveFileInfo file = null;
|
||||||
|
|
||||||
|
if (node.Tag != null && node.Tag is ArchiveFileInfo)
|
||||||
|
file = (ArchiveFileInfo)node.Tag;
|
||||||
|
else if (node is ArchiveFileWrapper)
|
||||||
|
file = ((ArchiveFileWrapper)node).ArchiveFileInfo;
|
||||||
|
|
||||||
|
if (file != null)
|
||||||
{
|
{
|
||||||
string FilePath = ((ArchiveFileWrapper)file).ArchiveFileInfo.FileName;
|
string FilePath = file.FileName;
|
||||||
string FolderPath = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
|
string FolderPath = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
|
||||||
string FolderPathDir = Path.Combine(overridePath, FolderPath);
|
string FolderPathDir = Path.Combine(overridePath, FolderPath);
|
||||||
|
|
||||||
if (!Directory.Exists(FolderPathDir))
|
if (!Directory.Exists(FolderPathDir))
|
||||||
Directory.CreateDirectory(FolderPathDir);
|
Directory.CreateDirectory(FolderPathDir);
|
||||||
|
|
||||||
string FileName = file.Text.RemoveIllegaleFileNameCharacters();
|
string FileName = Path.GetFileName(file.FileName).RemoveIllegaleFileNameCharacters();
|
||||||
|
|
||||||
FilePath = Path.Combine(FolderPath, FileName);
|
FilePath = Path.Combine(FolderPath, FileName);
|
||||||
|
|
||||||
|
@ -118,19 +125,18 @@ namespace Toolbox.Library
|
||||||
progressBar.Refresh();
|
progressBar.Refresh();
|
||||||
CreateDirectoryIfExists($"{path}");
|
CreateDirectoryIfExists($"{path}");
|
||||||
|
|
||||||
if (file is ArchiveFileWrapper)
|
filesExtracted.Add($"{path}");
|
||||||
{
|
|
||||||
filesExtracted.Add($"{path}");
|
|
||||||
|
|
||||||
if (((ArchiveFileWrapper)file).ArchiveFileInfo.FileDataStream != null)
|
if (file.FileFormat != null && file.FileFormat.CanSave)
|
||||||
{
|
file.SaveFileFormat();
|
||||||
((ArchiveFileWrapper)file).ArchiveFileInfo.FileDataStream.ExportToFile(path);
|
|
||||||
}
|
if (file.FileDataStream != null)
|
||||||
else
|
{
|
||||||
{
|
file.FileDataStream.ExportToFile(path);
|
||||||
File.WriteAllBytes($"{path}",
|
}
|
||||||
((ArchiveFileWrapper)file).ArchiveFileInfo.FileData);
|
else
|
||||||
}
|
{
|
||||||
|
File.WriteAllBytes($"{path}", file.FileData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue