/* * Overridden to adjust to color depending on we have DB type information. */ public override void ChangeColor() { base.ChangeColor(); PackedFile packedFile = Tag as PackedFile; string text = Path.GetFileName(packedFile.Name); if (packedFile != null && packedFile.FullPath.StartsWith("db")) { if (packedFile.Data.Length == 0) { text = string.Format("{0} (empty)", packedFile.Name); } else { string mouseover; try { DBFileHeader header = PackedFileDbCodec.readHeader(packedFile); // text = string.Format("{0} - version {1}", text, header.Version); if (header.EntryCount == 0) { // empty db file ForeColor = Color.Blue; if (Parent != null) { Parent.ForeColor = Color.Blue; } } else if (!PackedFileDbCodec.CanDecode(packedFile, out mouseover)) { if (Parent != null) { Parent.ToolTipText = mouseover; Parent.ForeColor = Color.Red; } ForeColor = Color.Red; } else if (HeaderVersionObsolete(packedFile)) { if (Parent != null) { Parent.BackColor = Color.Yellow; } BackColor = Color.Yellow; } } catch { } } } Text = text; }
private List <ModLine> ReadPackedField(PackedFile file, string fileName) { if (File.Exists(fileName)) { string key = DBFile.Typename(file.FullPath); DBFileHeader header = PackedFileDbCodec.readHeader(file); string exp = null; if (PackedFileDbCodec.CanDecode(file, out exp)) { PackedFileDbCodec codec = PackedFileDbCodec.GetCodec(file); DBFile f = codec.Decode(file.Data); if (f != null) { if (f.Entries.Count > 0) { //寻找主键字段 List <string> keys = f.CurrentType.Fields.Where(p => p.PrimaryKey).Select(p => p.Name).ToList(); if (keys.Count > 0) { return(f.Entries.Select(line => { ModLine modLine = new ModLine(); modLine.FileName = fileName; modLine.TableName = f.CurrentType.Name; modLine.FieldKeyName = new string[keys.Count]; modLine.FieldKeyValue = new string[keys.Count]; for (int i = 0; i < keys.Count; i++) { modLine.FieldKeyName[i] = keys[i]; modLine.FieldKeyValue[i] = line[keys[i]].Value; } return modLine; }).ToList()); } } } } } return(new List <ModLine>()); }
public static void SetColourBasedOnValidation(Collection <Node> nodes) { foreach (var node in nodes) { var packedFile = node.Tag as PackedFile; if (packedFile != null) { if (packedFile.FullPath.StartsWith("db")) { var colourNode = node as TreeNode; DBFileHeader header = PackedFileDbCodec.readHeader(packedFile); string mouseover; if (header.EntryCount == 0) // empty db file { colourNode.Colour = Color.Blue; SetColourForParent(colourNode, colourNode.Colour.Value); } else if (!PackedFileDbCodec.CanDecode(packedFile, out mouseover)) { colourNode.Colour = Color.Red; SetColourForAllParents(colourNode, colourNode.Colour.Value); colourNode.ToolTipText = mouseover; } else if (HeaderVersionObsolete(packedFile)) { colourNode.Colour = Color.Yellow; SetColourForParent(colourNode, colourNode.Colour.Value); } } } else { SetColourBasedOnValidation(node.Nodes); } } }