Files
BlenderSharp/CodeGenerator/BlendExt.cs
2025-05-08 18:02:42 +02:00

22 lines
1.1 KiB
C#

using System;
using System.CodeDom;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using Kaitai;
namespace CodeGenerator;
public static class BlendExt {
//TODO: Add an bool IsPrincipal extension method to kaitai structs lib
//A principal (or root) block is defined by having a two digit code and by the fact that its dna_index is always valid.
//If we have a pointer to a principal block, we can ignore the type of the pointer and use the block type.
//Subsidiary blocks are defined by having the code "DATA", which is ommited here. Their dna_index is not
// always correct and is only used when whichever field points to them has an "invalid" type (like void*).
public static bool IsPrincipal(this BlendFile.FileBlock block) {
string[] dataTypes = ["REND", "TEST", "GLOB", "DATA", "DNA1"];
bool isPrincipal = !dataTypes.Contains(block.Code);
if (isPrincipal && block.Count > 1)
throw new("Corrupt File detected. Principal block has more than one data type");
return isPrincipal;
}
}