public List <ImageHashData> LoadImageHashes(JsonParser.ObjectValue jsonOb) { List <ImageHashData> list = new List <ImageHashData>(); string[] enumArr = Enum.GetNames(typeof(EImageHashType)); foreach (var kvp in jsonOb.entries) { EImageHashType groupType = (EImageHashType)Array.IndexOf(enumArr, kvp.Key); JsonParser.ArrayValue typeArr = (JsonParser.ArrayValue)kvp.Value; foreach (JsonParser.Value value in typeArr.entries) { JsonParser.ObjectValue jsonHashOb = (JsonParser.ObjectValue)value; string idStr = jsonHashOb["id"]; bool hasIdNum = int.TryParse(idStr, out int idNum); bool needsIdNum = (groupType != EImageHashType.Rule); if (hasIdNum != needsIdNum) { continue; } ImageHashData hashEntry = new ImageHashData() { type = groupType, isKnown = true }; switch (groupType) { case EImageHashType.Rule: hashEntry.ownerOb = ParseRule(idStr); break; case EImageHashType.CardImage: hashEntry.ownerOb = TriadCardDB.Get().cards[idNum]; break; default: hashEntry.ownerOb = idNum; break; } if (hashEntry.ownerOb != null) { string descHashTLSH = jsonHashOb["hashC", JsonParser.StringValue.Empty]; string descHashMd5 = jsonHashOb["hashB", JsonParser.StringValue.Empty]; hashEntry.LoadFromString(descHashTLSH, descHashMd5); if (hashEntry.IsValid()) { list.Add(hashEntry); } } } } return(list); }
public ImageHashData LoadHashEntry(XmlElement xmlElem) { ImageHashData result = null; if (xmlElem != null && xmlElem.Name == "hash" && xmlElem.HasAttribute("type") && (xmlElem.HasAttribute("value") || xmlElem.HasAttribute("valueB"))) { string typeName = xmlElem.GetAttribute("type"); string hashValueC = xmlElem.HasAttribute("value") ? xmlElem.GetAttribute("value") : null; string hashValueB = xmlElem.HasAttribute("valueB") ? xmlElem.GetAttribute("valueB") : null; if (typeName.Equals("rule", StringComparison.InvariantCultureIgnoreCase)) { string ruleName = xmlElem.GetAttribute("name"); result = new ImageHashData() { type = EImageHashType.Rule, isKnown = true }; result.ownerOb = ParseRule(ruleName); result.LoadFromString(hashValueC, hashValueB); } else if (typeName.Equals("card", StringComparison.InvariantCultureIgnoreCase)) { string cardIdName = xmlElem.GetAttribute("id"); int cardId = int.Parse(cardIdName); result = new ImageHashData() { type = EImageHashType.CardImage, isKnown = true }; result.ownerOb = TriadCardDB.Get().cards[cardId]; result.LoadFromString(hashValueC, hashValueB); } else if (typeName.Equals("cactpot", StringComparison.InvariantCultureIgnoreCase)) { string numIdName = xmlElem.GetAttribute("id"); result = new ImageHashData() { type = EImageHashType.Cactpot, isKnown = true }; result.ownerOb = int.Parse(numIdName); result.LoadFromString(hashValueC, hashValueB); } } return(result); }