diff --git a/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/SegaFARC.uexml b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/Associations/SegaFARC.uexml
similarity index 88%
rename from CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/SegaFARC.uexml
rename to CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/Associations/SegaFARC.uexml
index 0a568503..faefa840 100644
--- a/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/SegaFARC.uexml
+++ b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/Associations/SegaFARC.uexml
@@ -24,7 +24,7 @@
-
+
diff --git a/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/DataFormats/SegaFARC.uexml b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/DataFormats/SegaFARC.uexml
new file mode 100644
index 00000000..b5bd619c
--- /dev/null
+++ b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/SEGA/DataFormats/SegaFARC.uexml
@@ -0,0 +1,65 @@
+
+
+
+
+
+ SEGA FARC archive
+
+
+
+
+
+
+
+
+ Compressed file entry
+
+
+
+
+
+
+
+
+
+
+ File entry
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj
index 10ec7dd7..eec25141 100644
--- a/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj
+++ b/CSharp/V5/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj
@@ -181,7 +181,7 @@
-
+
@@ -661,6 +661,9 @@
+
+
+
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormat.cs b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormat.cs
index 771d8a83..e83f6921 100644
--- a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormat.cs
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormat.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
+using UniversalEditor.IO;
namespace UniversalEditor
{
@@ -22,121 +23,11 @@ namespace UniversalEditor
IO.Reader br = base.Accessor.Reader;
foreach (CustomDataFormatItem cdfi in cdfr.Items)
{
+ object value = ReadObject(br, cdfi);
+
if (cdfi is CustomDataFormatItemField)
{
CustomDataFormatItemField fld = (cdfi as CustomDataFormatItemField);
- object value = null;
- switch (fld.DataType)
- {
- case "Boolean":
- {
- value = br.ReadBoolean();
- break;
- }
- case "Byte":
- {
- value = br.ReadByte();
- break;
- }
- case "Char":
- {
- value = br.ReadChar();
- break;
- }
- case "DateTime":
- {
- value = br.ReadDateTime();
- break;
- }
- case "Decimal":
- {
- value = br.ReadDecimal();
- break;
- }
- case "Double":
- {
- value = br.ReadDouble();
- break;
- }
- case "Guid":
- {
- value = br.ReadGuid();
- break;
- }
- case "Int16":
- {
- value = br.ReadInt16();
- break;
- }
- case "Int32":
- {
- value = br.ReadInt32();
- break;
- }
- case "Int64":
- {
- value = br.ReadInt64();
- break;
- }
- case "SByte":
- {
- value = br.ReadSByte();
- break;
- }
- case "Single":
- {
- value = br.ReadSingle();
- break;
- }
- case "String":
- {
- value = br.ReadLengthPrefixedString();
- break;
- }
- case "UInt16":
- {
- value = br.ReadUInt16();
- break;
- }
- case "UInt32":
- {
- value = br.ReadUInt32();
- break;
- }
- case "UInt64":
- {
- value = br.ReadUInt64();
- break;
- }
- case "TerminatedString":
- {
- IO.Encoding encoding = IO.Encoding.Default;
- if (fld.Encoding != null) encoding = fld.Encoding;
-
- if (fld.Length.HasValue)
- {
- value = br.ReadNullTerminatedString(fld.Length.Value, encoding);
- }
- else
- {
- value = br.ReadNullTerminatedString(encoding);
- }
- break;
- }
- case "FixedString":
- {
- IO.Encoding encoding = IO.Encoding.Default;
- if (fld.Encoding != null) encoding = fld.Encoding;
-
- if (!fld.Length.HasValue)
- {
- throw new InvalidOperationException();
- }
- value = br.ReadFixedLengthString(fld.Length.Value, encoding);
- break;
- }
- }
-
if (fld.Name != null)
{
string fldName = ReplaceVariables(fld.Name, localVariables);
@@ -156,12 +47,170 @@ namespace UniversalEditor
}
}
+ private object ReadObject(Reader reader, CustomDataFormatItem item)
+ {
+ object value = null;
+ if (item is CustomDataFormatItemField)
+ {
+ CustomDataFormatItemField itm = (item as CustomDataFormatItemField);
+ switch (itm.DataType)
+ {
+ case "Boolean":
+ {
+ value = reader.ReadBoolean();
+ break;
+ }
+ case "Byte":
+ {
+ value = reader.ReadByte();
+ break;
+ }
+ case "Char":
+ {
+ value = reader.ReadChar();
+ break;
+ }
+ case "DateTime":
+ {
+ value = reader.ReadDateTime();
+ break;
+ }
+ case "Decimal":
+ {
+ value = reader.ReadDecimal();
+ break;
+ }
+ case "Double":
+ {
+ value = reader.ReadDouble();
+ break;
+ }
+ case "Guid":
+ {
+ value = reader.ReadGuid();
+ break;
+ }
+ case "Int16":
+ {
+ value = reader.ReadInt16();
+ break;
+ }
+ case "Int32":
+ {
+ value = reader.ReadInt32();
+ break;
+ }
+ case "Int64":
+ {
+ value = reader.ReadInt64();
+ break;
+ }
+ case "SByte":
+ {
+ value = reader.ReadSByte();
+ break;
+ }
+ case "Single":
+ {
+ value = reader.ReadSingle();
+ break;
+ }
+ case "String":
+ {
+ value = reader.ReadLengthPrefixedString();
+ break;
+ }
+ case "Structure":
+ {
+ value = ReadStructure(reader, itm.StructureID);
+ break;
+ }
+ case "UInt16":
+ {
+ value = reader.ReadUInt16();
+ break;
+ }
+ case "UInt32":
+ {
+ value = reader.ReadUInt32();
+ break;
+ }
+ case "UInt64":
+ {
+ value = reader.ReadUInt64();
+ break;
+ }
+ case "TerminatedString":
+ {
+ IO.Encoding encoding = IO.Encoding.Default;
+ if (itm.Encoding != null) encoding = itm.Encoding;
+
+ if (itm.Length.HasValue)
+ {
+ value = reader.ReadNullTerminatedString(itm.Length.Value, encoding);
+ }
+ else
+ {
+ value = reader.ReadNullTerminatedString(encoding);
+ }
+ break;
+ }
+ case "FixedString":
+ {
+ IO.Encoding encoding = IO.Encoding.Default;
+ if (itm.Encoding != null) encoding = itm.Encoding;
+
+ if (!itm.Length.HasValue)
+ {
+ throw new InvalidOperationException();
+ }
+ value = reader.ReadFixedLengthString(itm.Length.Value, encoding);
+ break;
+ }
+ }
+ }
+ return value;
+ }
+
+ private object ReadStructure(Reader reader, Guid id)
+ {
+ CustomDataFormatReference cdfr = (base.Reference as CustomDataFormatReference);
+ if (cdfr == null) throw new InvalidOperationException("Must have a CustomDataFormatReference");
+
+ CustomDataFormatStructure type = cdfr.Structures[id];
+ CustomDataFormatStructureInstance inst = type.CreateInstance();
+
+ foreach (CustomDataFormatItem item in type.Items)
+ {
+ CustomDataFormatItemField cdfif = (inst.Items[item.Name] as CustomDataFormatItemField);
+ if (cdfif != null)
+ {
+ cdfif.Value = ReadObject(reader, item);
+ }
+ }
+ return inst;
+ }
+
+ private void WriteStructure(Writer writer, CustomDataFormatStructure structure)
+ {
+ CustomDataFormatReference cdfr = (base.Reference as CustomDataFormatReference);
+ if (cdfr == null) throw new InvalidOperationException("Must have a CustomDataFormatReference");
+
+ foreach (CustomDataFormatItem item in structure.Items)
+ {
+ WriteObject(writer, item);
+ }
+ }
+
private string ReplaceVariables(string p, Dictionary localVariables)
{
string retval = p;
foreach (string key in localVariables.Keys)
{
- retval = retval.Replace("$(" + key + ")", localVariables[key].ToString());
+ string value = String.Empty;
+ if (localVariables[key] != null) value = localVariables[key].ToString();
+
+ retval = retval.Replace("$(Local:" + key + ")", value);
}
return retval;
}
@@ -213,8 +262,24 @@ namespace UniversalEditor
string sectionName = null;
if (variableStr.Contains(":")) sectionName = variableStr.Substring(0, variableStr.IndexOf(':'));
- string methodName = variableStr.Substring(variableStr.IndexOf(':'));
+ string methodOrPropertyName = variableStr.Substring(variableStr.IndexOf(':') + 1);
+ switch (sectionName)
+ {
+ case "CustomOption":
+ {
+ // this is a CustomOption property
+ CustomOption co = mvarReference.ExportOptions[methodOrPropertyName];
+ if (co != null)
+ {
+ string bw = co.GetValue().ToString();
+ sb.Append(bw);
+ }
+ break;
+ }
+ }
+
+ i += variableStr.Length + 1; // $(...)
}
}
else if (value[i] == '\\')
@@ -238,6 +303,20 @@ namespace UniversalEditor
return sb.ToString();
}
+ private bool EvaluateCondition(CustomDataFormatFieldCondition condition)
+ {
+ bool retval = false;
+
+ string value = ExpandVariables(condition.Variable);
+
+ bool bValue1 = (value.ToLower().Equals("true"));
+ bool bValue2 = (condition.Value.ToLower().Equals("true"));
+
+ retval = (bValue1 == bValue2);
+
+ return retval;
+ }
+
protected override void SaveInternal(ObjectModel objectModel)
{
CustomDataFormatReference cdfr = (this.Reference as CustomDataFormatReference);
@@ -251,137 +330,8 @@ namespace UniversalEditor
if (cdfi is CustomDataFormatItemField)
{
CustomDataFormatItemField fld = (cdfi as CustomDataFormatItemField);
- object value = ExpandVariables(fld.Value);
-
- switch (fld.DataType)
- {
- case "Boolean":
- {
- value = (value.ToString().ToLower().Equals("true"));
- bw.WriteBoolean((bool)value);
- break;
- }
- case "Byte":
- {
- value = Byte.Parse(value.ToString());
- bw.WriteByte((byte)value);
- break;
- }
- case "Char":
- {
- value = Char.Parse(value.ToString());
- bw.WriteChar((char)value);
- break;
- }
- case "DateTime":
- {
- value = DateTime.Parse(value.ToString());
- bw.WriteDateTime((DateTime)value);
- break;
- }
- case "Decimal":
- {
- value = Decimal.Parse(value.ToString());
- bw.WriteDecimal((decimal)value);
- break;
- }
- case "Double":
- {
- value = Double.Parse(value.ToString());
- bw.WriteDouble((double)value);
- break;
- }
- case "Guid":
- {
- value = Guid.Parse(value.ToString());
- bw.WriteGuid((Guid)value);
- break;
- }
- case "Int16":
- {
- value = Int16.Parse(value.ToString());
- bw.WriteInt16((short)value);
- break;
- }
- case "Int32":
- {
- value = Int32.Parse(value.ToString());
- bw.WriteInt32((int)value);
- break;
- }
- case "Int64":
- {
- value = Int64.Parse(value.ToString());
- bw.WriteInt64((long)value);
- break;
- }
- case "SByte":
- {
- value = SByte.Parse(value.ToString());
- bw.WriteSByte((sbyte)value);
- break;
- }
- case "Single":
- {
- value = Single.Parse(value.ToString());
- bw.WriteSingle((float)value);
- break;
- }
- case "String":
- {
- bw.WriteLengthPrefixedString((string)value);
- break;
- }
- case "UInt16":
- {
- value = UInt16.Parse(value.ToString());
- bw.WriteUInt16((ushort)value);
- break;
- }
- case "UInt32":
- {
- value = UInt32.Parse(value.ToString());
- bw.WriteUInt32((uint)value);
- break;
- }
- case "UInt64":
- {
- value = UInt64.Parse(value.ToString());
- bw.WriteUInt64((ulong)value);
- break;
- }
- case "TerminatedString":
- {
- IO.Encoding encoding = IO.Encoding.Default;
- if (fld.Encoding != null) encoding = fld.Encoding;
-
- if (fld.Length.HasValue)
- {
- bw.WriteNullTerminatedString((string)value, encoding, fld.Length.Value);
- }
- else
- {
- bw.WriteNullTerminatedString((string)value, encoding);
- }
- break;
- }
- case "FixedString":
- {
- IO.Encoding encoding = IO.Encoding.Default;
- if (fld.Encoding != null) encoding = fld.Encoding;
- if (fld.Value == null) continue;
-
- if (fld.Length != null)
- {
- bw.WriteFixedLengthString(fld.Value, encoding, fld.Length.Value);
- }
- else
- {
- bw.WriteFixedLengthString(fld.Value, encoding);
- }
- break;
- }
- }
+
+ WriteObject(bw, fld);
if (fld.Name != null)
{
@@ -401,6 +351,169 @@ namespace UniversalEditor
}
}
}
+
+ private void WriteObject(Writer writer, CustomDataFormatItem item)
+ {
+ object value = null;
+
+ if (item is CustomDataFormatItemField)
+ {
+ CustomDataFormatItemField fld = (item as CustomDataFormatItemField);
+ if (fld != null)
+ {
+ if (fld.FieldCondition == null)
+ {
+ if (fld.Value == null) return;
+ value = ExpandVariables(fld.Value.ToString());
+ }
+ else
+ {
+ if (EvaluateCondition(fld.FieldCondition))
+ {
+ value = ExpandVariables(fld.FieldCondition.TrueResult);
+ }
+ else
+ {
+ value = ExpandVariables(fld.FieldCondition.FalseResult);
+ }
+ }
+ }
+
+ switch (fld.DataType)
+ {
+ case "Boolean":
+ {
+ value = (value.ToString().ToLower().Equals("true"));
+ writer.WriteBoolean((bool)value);
+ break;
+ }
+ case "Byte":
+ {
+ value = Byte.Parse(value.ToString());
+ writer.WriteByte((byte)value);
+ break;
+ }
+ case "Char":
+ {
+ value = Char.Parse(value.ToString());
+ writer.WriteChar((char)value);
+ break;
+ }
+ case "DateTime":
+ {
+ value = DateTime.Parse(value.ToString());
+ writer.WriteDateTime((DateTime)value);
+ break;
+ }
+ case "Decimal":
+ {
+ value = Decimal.Parse(value.ToString());
+ writer.WriteDecimal((decimal)value);
+ break;
+ }
+ case "Double":
+ {
+ value = Double.Parse(value.ToString());
+ writer.WriteDouble((double)value);
+ break;
+ }
+ case "Guid":
+ {
+ value = Guid.Parse(value.ToString());
+ writer.WriteGuid((Guid)value);
+ break;
+ }
+ case "Int16":
+ {
+ value = Int16.Parse(value.ToString());
+ writer.WriteInt16((short)value);
+ break;
+ }
+ case "Int32":
+ {
+ value = Int32.Parse(value.ToString());
+ writer.WriteInt32((int)value);
+ break;
+ }
+ case "Int64":
+ {
+ value = Int64.Parse(value.ToString());
+ writer.WriteInt64((long)value);
+ break;
+ }
+ case "SByte":
+ {
+ value = SByte.Parse(value.ToString());
+ writer.WriteSByte((sbyte)value);
+ break;
+ }
+ case "Single":
+ {
+ value = Single.Parse(value.ToString());
+ writer.WriteSingle((float)value);
+ break;
+ }
+ case "String":
+ {
+ writer.WriteLengthPrefixedString((string)value);
+ break;
+ }
+ case "Structure":
+ {
+ writer.WriteLengthPrefixedString((string)value);
+ break;
+ }
+ case "UInt16":
+ {
+ value = UInt16.Parse(value.ToString());
+ writer.WriteUInt16((ushort)value);
+ break;
+ }
+ case "UInt32":
+ {
+ value = UInt32.Parse(value.ToString());
+ writer.WriteUInt32((uint)value);
+ break;
+ }
+ case "UInt64":
+ {
+ value = UInt64.Parse(value.ToString());
+ writer.WriteUInt64((ulong)value);
+ break;
+ }
+ case "TerminatedString":
+ {
+ IO.Encoding encoding = IO.Encoding.Default;
+ if (fld.Encoding != null) encoding = fld.Encoding;
+
+ if (fld.Length.HasValue)
+ {
+ writer.WriteNullTerminatedString((string)value, encoding, fld.Length.Value);
+ }
+ else
+ {
+ writer.WriteNullTerminatedString((string)value, encoding);
+ }
+ break;
+ }
+ case "FixedString":
+ {
+ IO.Encoding encoding = IO.Encoding.Default;
+ if (fld.Encoding != null) encoding = fld.Encoding;
+
+ if (fld.Length != null)
+ {
+ writer.WriteFixedLengthString((string)value, encoding, fld.Length.Value);
+ }
+ else
+ {
+ writer.WriteFixedLengthString((string)value, encoding);
+ }
+ break;
+ }
+ }
+ }
+ }
}
public class CustomDataFormatReference : DataFormatReference
{
@@ -408,6 +521,9 @@ namespace UniversalEditor
{
}
+ private CustomDataFormatStructure.CustomDataFormatStructureCollection mvarStructures = new CustomDataFormatStructure.CustomDataFormatStructureCollection();
+ public CustomDataFormatStructure.CustomDataFormatStructureCollection Structures { get { return mvarStructures; } }
+
private CustomDataFormatItem.CustomDataFormatItemCollection mvarItems = new CustomDataFormatItem.CustomDataFormatItemCollection();
public CustomDataFormatItem.CustomDataFormatItemCollection Items
{
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatFieldCondition.cs b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatFieldCondition.cs
new file mode 100644
index 00000000..97e7834e
--- /dev/null
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatFieldCondition.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace UniversalEditor
+{
+ public class CustomDataFormatFieldCondition
+ {
+ private string mvarVariable = String.Empty;
+ public string Variable { get { return mvarVariable; } set { mvarVariable = value; } }
+
+ private string mvarValue = String.Empty;
+ public string Value { get { return mvarValue; } set { mvarValue = value; } }
+
+ private string mvarTrueResult = String.Empty;
+ public string TrueResult { get { return mvarTrueResult; } set { mvarTrueResult = value; } }
+
+ private string mvarFalseResult = String.Empty;
+ public string FalseResult { get { return mvarFalseResult; } set { mvarFalseResult = value; } }
+
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.Append("`");
+ sb.Append(mvarVariable);
+ sb.Append("` == `");
+ sb.Append(mvarValue);
+ sb.Append("` ? `");
+ sb.Append(mvarTrueResult);
+ sb.Append("` : `");
+ sb.Append(mvarFalseResult);
+ sb.Append("`");
+ return sb.ToString();
+ }
+ }
+}
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatItem.cs b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatItem.cs
index 419ba8bc..c9edad97 100644
--- a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatItem.cs
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatItem.cs
@@ -9,6 +9,34 @@ namespace UniversalEditor
public class CustomDataFormatItemCollection
: System.Collections.ObjectModel.Collection
{
+ public CustomDataFormatItem this[string name]
+ {
+ get
+ {
+ foreach (CustomDataFormatItem item in this)
+ {
+ if (item.Name == name) return item;
+ }
+ return null;
+ }
+ }
+ }
+ public class CustomDataFormatItemReadOnlyCollection
+ : System.Collections.ObjectModel.ReadOnlyCollection
+ {
+ public CustomDataFormatItemReadOnlyCollection(IList list) : base(list) { }
+
+ public CustomDataFormatItem this[string name]
+ {
+ get
+ {
+ foreach (CustomDataFormatItem item in this)
+ {
+ if (item.Name == name) return item;
+ }
+ return null;
+ }
+ }
}
private string mvarName = null;
@@ -22,21 +50,33 @@ namespace UniversalEditor
private string mvarDataType = String.Empty;
public string DataType { get { return mvarDataType; } set { mvarDataType = value; } }
+ private Guid mvarStructureID = Guid.Empty;
+ public Guid StructureID { get { return mvarStructureID; } set { mvarStructureID = value; } }
+
private int? mvarLength = null;
public int? Length { get { return mvarLength; } set { mvarLength = value; } }
private IO.Encoding mvarEncoding = null;
public IO.Encoding Encoding { get { return mvarEncoding; } set { mvarEncoding = value; } }
- private string mvarValue = null;
- public string Value { get { return mvarValue; } set { mvarValue = value; } }
+ private object mvarValue = null;
+ public object Value { get { return mvarValue; } set { mvarValue = value; } }
+
+ private CustomDataFormatFieldCondition mvarFieldCondition = null;
+ public CustomDataFormatFieldCondition FieldCondition { get { return mvarFieldCondition; } set { mvarFieldCondition = value; } }
}
public class CustomDataFormatItemArray : CustomDataFormatItem
{
private string mvarDataType = String.Empty;
public string DataType { get { return mvarDataType; } set { mvarDataType = value; } }
- private int mvarLength = 0;
- public int Length { get { return mvarLength; } set { mvarLength = value; } }
+ private Guid mvarStructureID = Guid.Empty;
+ public Guid StructureID { get { return mvarStructureID; } set { mvarStructureID = value; } }
+
+ private string mvarLength = null;
+ public string Length { get { return mvarLength; } set { mvarLength = value; } }
+
+ private string mvarMaximumSize = null;
+ public string MaximumSize { get { return mvarMaximumSize; } set { mvarMaximumSize = value; } }
}
}
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructure.cs b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructure.cs
new file mode 100644
index 00000000..08d0c8e1
--- /dev/null
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructure.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace UniversalEditor
+{
+ public class CustomDataFormatStructure
+ {
+ public class CustomDataFormatStructureCollection
+ : System.Collections.ObjectModel.Collection
+ {
+ public CustomDataFormatStructure this[Guid id]
+ {
+ get
+ {
+ foreach (CustomDataFormatStructure item in this)
+ {
+ if (item.ID == id) return item;
+ }
+ return null;
+ }
+ }
+ }
+
+ private Guid mvarID = Guid.Empty;
+ public Guid ID { get { return mvarID; } set { mvarID = value; } }
+
+ private CustomDataFormatItem.CustomDataFormatItemCollection mvarItems = new CustomDataFormatItem.CustomDataFormatItemCollection();
+ public CustomDataFormatItem.CustomDataFormatItemCollection Items
+ {
+ get { return mvarItems; }
+ }
+
+ public CustomDataFormatStructureInstance CreateInstance()
+ {
+ CustomDataFormatStructureInstance inst = new CustomDataFormatStructureInstance(this);
+ return inst;
+ }
+ }
+}
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructureInstance.cs b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructureInstance.cs
new file mode 100644
index 00000000..6a228437
--- /dev/null
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/CustomDataFormatStructureInstance.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace UniversalEditor
+{
+ public class CustomDataFormatStructureInstance
+ {
+ private CustomDataFormatStructure mvarStructure = null;
+ public CustomDataFormatStructure Structure { get { return mvarStructure; } }
+
+ private CustomDataFormatItem.CustomDataFormatItemReadOnlyCollection mvarItems = null;
+ public CustomDataFormatItem.CustomDataFormatItemReadOnlyCollection Items { get { return mvarItems; } }
+
+ internal CustomDataFormatStructureInstance(CustomDataFormatStructure structure)
+ {
+ mvarStructure = structure;
+
+ List items = new List();
+ foreach (CustomDataFormatItem item in structure.Items)
+ {
+ items.Add(item);
+ }
+ mvarItems = new CustomDataFormatItem.CustomDataFormatItemReadOnlyCollection(items);
+ }
+ }
+}
diff --git a/CSharp/V5/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj b/CSharp/V5/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj
index f4eee824..341d6d79 100644
--- a/CSharp/V5/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj
+++ b/CSharp/V5/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj
@@ -56,7 +56,10 @@
+
+
+
diff --git a/CSharp/V5/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs b/CSharp/V5/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs
index 832b5f9c..a2fa906f 100644
--- a/CSharp/V5/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs
+++ b/CSharp/V5/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs
@@ -162,128 +162,38 @@ namespace UniversalEditor.DataFormats.UEPackage
}
}
#endregion
- #region Filters
+ #region Export Options
{
- if (tagFilters != null)
+ MarkupTagElement tagCustomOptions = (tagDataFormat.Elements["ExportOptions"] as MarkupTagElement);
+ if (tagCustomOptions != null)
{
- Console.WriteLine("WARNING: this method of adding filters is deprecated; please use Associations instead!");
-
- foreach (MarkupElement elFilter in tagFilters.Elements)
+ foreach (MarkupElement elCustomOption in tagCustomOptions.Elements)
{
- MarkupTagElement tagFilter = (elFilter as MarkupTagElement);
- if (tagFilter.Name != "Filter") continue;
+ MarkupTagElement tagCustomOption = (elCustomOption as MarkupTagElement);
+ if (tagCustomOption == null) continue;
+ CustomOption co = LoadCustomOption(tagCustomOption);
+ if (co == null) continue;
- DataFormatFilter filter = new DataFormatFilter();
- MarkupAttribute attHintComparison = tagFilter.Attributes["HintComparison"];
- if (attHintComparison != null)
- {
- switch (attHintComparison.Value.ToLower())
- {
- case "always":
- {
- filter.HintComparison = DataFormatHintComparison.Always;
- break;
- }
- case "filteronly":
- {
- filter.HintComparison = DataFormatHintComparison.FilterOnly;
- break;
- }
- case "filterthenmagic":
- {
- filter.HintComparison = DataFormatHintComparison.FilterThenMagic;
- break;
- }
- case "magiconly":
- {
- filter.HintComparison = DataFormatHintComparison.MagicOnly;
- break;
- }
- case "magicthenfilter":
- {
- filter.HintComparison = DataFormatHintComparison.MagicThenFilter;
- break;
- }
- default:
- {
- filter.HintComparison = DataFormatHintComparison.Never;
- break;
- }
- }
- }
+ dfr.ExportOptions.Add(co);
+ }
+ }
+ }
+ #endregion
+ #region Import Options
+ {
+ MarkupTagElement tagCustomOptions = (tagDataFormat.Elements["ImportOptions"] as MarkupTagElement);
+ if (tagCustomOptions != null)
+ {
+ foreach (MarkupElement elCustomOption in tagCustomOptions.Elements)
+ {
+ MarkupTagElement tagCustomOption = (elCustomOption as MarkupTagElement);
+ if (tagCustomOption == null) continue;
- MarkupTagElement tagFilterTitle = (tagFilter.Elements["Title"] as MarkupTagElement);
- if (tagFilterTitle != null) filter.Title = tagFilterTitle.Value;
+ CustomOption co = LoadCustomOption(tagCustomOption);
+ if (co == null) continue;
- #region File Name Filters
- {
- MarkupTagElement tagFilterFileNames = (tagFilter.Elements["FileNameFilters"] as MarkupTagElement);
- if (tagFilterFileNames != null)
- {
- foreach (MarkupElement elFilterFileName in tagFilterFileNames.Elements)
- {
- MarkupTagElement tagFilterFileName = (elFilterFileName as MarkupTagElement);
- if (tagFilterFileName.Name != "FileNameFilter") continue;
- filter.FileNameFilters.Add(tagFilterFileName.Value);
- }
- }
- }
- #endregion
- #region Magic Bytes
- {
- MarkupTagElement tagMagicBytes = (tagFilter.Elements["MagicBytes"] as MarkupTagElement);
- if (tagMagicBytes != null)
- {
- foreach (MarkupElement elMagicByteCollection in tagMagicBytes.Elements)
- {
- MarkupTagElement tagMagicByteCollection = (elMagicByteCollection as MarkupTagElement);
- if (tagMagicByteCollection == null) continue;
- if (tagMagicByteCollection.Name != "MagicByteCollection") continue;
-
- List array = new List();
- foreach (MarkupElement elMagicByte in tagMagicByteCollection.Elements)
- {
- MarkupTagElement tagMagicByte = (elMagicByte as MarkupTagElement);
- if (tagMagicByte == null) continue;
- if (tagMagicByte.Name != "MagicByte") continue;
-
- byte? value = null;
- byte tryValue = 0;
- char tryChar = '\0';
-
- if (Byte.TryParse(tagMagicByte.Value, out tryValue))
- {
- value = tryValue;
- }
- else if (tagMagicByte.Value.StartsWith("0x"))
- {
- if (Byte.TryParse(tagMagicByte.Value.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out tryValue))
- {
- value = tryValue;
- }
- }
- else if (tagMagicByte.Value.Length > 1)
- {
- for (int i = 0; i < tagMagicByte.Value.Length; i++)
- {
- array.Add((byte)(tagMagicByte.Value[i]));
- }
- continue;
- }
- else if (Char.TryParse(tagMagicByte.Value, out tryChar))
- {
- value = (byte)tryChar;
- }
- array.Add(value);
- }
- filter.MagicBytes.Add(array.ToArray());
- }
- }
- }
- #endregion
-
- // dfr.Filters.Add(filter);
+ dfr.ImportOptions.Add(co);
}
}
}
@@ -295,53 +205,8 @@ namespace UniversalEditor.DataFormats.UEPackage
MarkupTagElement tagField = (elField as MarkupTagElement);
if (tagField == null) continue;
- switch (tagField.Name)
- {
- case "Field":
- {
- if (tagField.Attributes["DataType"] == null) continue;
-
- CustomDataFormatItemField cdfif = new CustomDataFormatItemField();
- cdfif.DataType = tagField.Attributes["DataType"].Value;
-
- MarkupAttribute attFieldID = tagField.Attributes["ID"];
- if (attFieldID != null)
- {
- cdfif.Name = attFieldID.Value;
- }
-
- MarkupAttribute attValue = tagField.Attributes["Value"];
- if (attValue != null)
- {
- cdfif.Value = attValue.Value;
- }
- dfr.Items.Add(cdfif);
- break;
- }
- case "Array":
- {
- if (tagField.Attributes["DataType"] == null) continue;
-
- CustomDataFormatItemArray cdfif = new CustomDataFormatItemArray();
- cdfif.DataType = tagField.Attributes["DataType"].Value;
-
- if (tagField.Attributes["ID"] != null)
- {
- cdfif.Name = tagField.Attributes["ID"].Value;
- }
- if (tagField.Attributes["Length"] != null)
- {
- string value = tagField.Attributes["Length"].Value;
- value = UniversalEditor.Common.Strings.ReplaceVariables(value, localVariables);
- int length = 0;
- Int32.TryParse(value, out length);
-
- cdfif.Length = length;
- }
- dfr.Items.Add(cdfif);
- break;
- }
- }
+ CustomDataFormatItem cdfi = CreateField(tagField, localVariables);
+ if (cdfi != null) dfr.Items.Add(cdfi);
}
}
#endregion
@@ -1037,7 +902,7 @@ namespace UniversalEditor.DataFormats.UEPackage
for (int i = 0; i < value.Length; i += 2)
{
string val = value.Substring(i, 2);
- realvalue = Byte.Parse(value, System.Globalization.NumberStyles.HexNumber);
+ realvalue = Byte.Parse(val, System.Globalization.NumberStyles.HexNumber);
magicByteSequence.Add(realvalue);
}
break;
@@ -1059,6 +924,112 @@ namespace UniversalEditor.DataFormats.UEPackage
}
#endregion
}
+
+ private CustomOption LoadCustomOption(MarkupTagElement tag)
+ {
+ CustomOption co = null;
+
+ Type[] tCustomOptions = UniversalEditor.Common.Reflection.GetAvailableTypes(new Type[] { typeof(CustomOption) });
+ foreach (Type tCustomOption in tCustomOptions)
+ {
+ if (tCustomOption.Name == tag.FullName)
+ {
+ MarkupAttribute attID = tag.Attributes["ID"];
+ if (attID == null) continue;
+
+ MarkupAttribute attTitle = tag.Attributes["Title"];
+ if (attTitle == null) continue;
+
+ co = (CustomOption)tCustomOption.Assembly.CreateInstance(tCustomOption.FullName, false, System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.OptionalParamBinding, null, new object[] { attID.Value, attTitle.Value.Replace("_", "&") }, null, null);
+
+ foreach (MarkupAttribute att in tag.Attributes)
+ {
+ if (att.Name == "ID" || att.Name == "Title")
+ {
+ // already initialized
+ continue;
+ }
+ else
+ {
+ tCustomOption.GetProperty(att.Name).SetValue(co, att.Value, null);
+ }
+ }
+ }
+ }
+ return co;
+ }
+
+ private CustomDataFormatItem CreateField(MarkupTagElement tagField, Dictionary localVariables)
+ {
+ switch (tagField.Name)
+ {
+ case "Field":
+ {
+ if (tagField.Attributes["DataType"] == null) return null;
+
+ CustomDataFormatItemField cdfif = new CustomDataFormatItemField();
+ cdfif.DataType = tagField.Attributes["DataType"].Value;
+
+ MarkupAttribute attFieldID = tagField.Attributes["ID"];
+ if (attFieldID != null)
+ {
+ cdfif.Name = attFieldID.Value;
+ }
+
+ MarkupAttribute attValue = tagField.Attributes["Value"];
+ if (attValue != null)
+ {
+ cdfif.Value = attValue.Value;
+ }
+
+ MarkupAttribute attConditionalVariable = tagField.Attributes["Conditional-Variable"];
+ if (attConditionalVariable != null)
+ {
+ CustomDataFormatFieldCondition cond = new CustomDataFormatFieldCondition();
+ cond.Variable = attConditionalVariable.Value;
+
+ MarkupAttribute attConditionalValue = tagField.Attributes["Conditional-Value"];
+ if (attConditionalValue != null) cond.Value = attConditionalValue.Value;
+
+ MarkupAttribute attConditionalTrueResult = tagField.Attributes["Conditional-TrueResult"];
+ if (attConditionalTrueResult != null) cond.TrueResult = attConditionalTrueResult.Value;
+
+ MarkupAttribute attConditionalFalseResult = tagField.Attributes["Conditional-FalseResult"];
+ if (attConditionalFalseResult != null) cond.FalseResult = attConditionalFalseResult.Value;
+
+ cdfif.FieldCondition = cond;
+ }
+ return cdfif;
+ }
+ case "Array":
+ {
+ if (tagField.Attributes["DataType"] == null) return null;
+
+ CustomDataFormatItemArray cdfif = new CustomDataFormatItemArray();
+ cdfif.DataType = tagField.Attributes["DataType"].Value;
+ if (cdfif.DataType == "Structure")
+ {
+ MarkupAttribute attStructureID = tagField.Attributes["StructureID"];
+ if (attStructureID != null) cdfif.StructureID = new Guid(attStructureID.Value);
+ }
+
+ if (tagField.Attributes["ID"] != null)
+ {
+ cdfif.Name = tagField.Attributes["ID"].Value;
+ }
+ if (tagField.Attributes["Length"] != null)
+ {
+ cdfif.Length = tagField.Attributes["Length"].Value;
+ }
+ if (tagField.Attributes["MaximumSize"] != null)
+ {
+ cdfif.MaximumSize = tagField.Attributes["MaximumSize"].Value;
+ }
+ return cdfif;
+ }
+ }
+ return null;
+ }
protected override void BeforeSaveInternal(Stack objectModels)
{
base.BeforeSaveInternal(objectModels);