-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCStructureInfo.cs
81 lines (70 loc) · 2.46 KB
/
CStructureInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WowClientDB2MySQLTableGenerator
{
public sealed class CStructureInfo
{
public string Name { get; set; }
public string NormalizedName { get; set; }
public List<CStructureMemberInfo> Members { get; set; } = new List<CStructureMemberInfo>();
public bool IsLocale { get; set; }
public override string ToString()
{
return "struct " + NormalizedName;
}
public string GetTableName()
{
var sb = new StringBuilder();
for (int i = 0; i < NormalizedName.Length; ++i)
{
char c = NormalizedName[i];
if (char.IsUpper(c) && i > 0)
sb.Append('_');
sb.Append(char.ToLower(c));
}
return sb.ToString();
}
public CStructureInfo CreateLocaleTable()
{
var stringFields = Members.Where(m => m.FormattedTypeName.StartsWith("LocalizedString"))
.Select(m =>
{
var m2 = new CStructureMemberInfo()
{
TypeName = m.TypeName,
Name = m.Name.Replace("_lang", "").Replace("_loc", ""),
ArraySize = m.ArraySize
};
var indexOfArray = m.Name.LastIndexOf('[');
if (indexOfArray != -1)
m2.Name = m2.Name.Insert(indexOfArray, "_lang");
else
m2.Name += "_lang";
return m2;
}).ToList();
if (stringFields.Count == 0)
return null;
stringFields.Insert(0, new CStructureMemberInfo()
{
TypeName = "uint32",
Name = "ID"
});
stringFields.Insert(1, new CStructureMemberInfo()
{
TypeName = "char[4]",
Name = "locale"
});
stringFields.Add(new CStructureMemberInfo()
{
TypeName = "int32",
Name = "VerifiedBuild"
});
var localeStruct = new CStructureInfo();
localeStruct.NormalizedName = NormalizedName + "Locale";
localeStruct.Members = stringFields;
localeStruct.IsLocale = true;
return localeStruct;
}
}
}