private void ApplyFilterSet(FilterSet set) { foreach (var packetListEntry in PacketListView.Items.OfType <PacketListItem>()) { switch (set.type) { case FilterType.Message: if (packetListEntry.MessageCol == ((int)set.value).ToString("X4")) { packetListEntry.IsVisible = true; } break; case FilterType.ActorControl: if (packetListEntry.ActorControl == (int)set.value) { packetListEntry.IsVisible = true; } break; case FilterType.ActorControlName: if (packetListEntry.ActorControl != -1 && packetListEntry.NameCol.ToLower().Contains(((string)set.value).ToLower())) { packetListEntry.IsVisible = true; } break; case FilterType.PacketName: if (packetListEntry.NameCol.ToLower().Contains(((string)set.value).ToLower())) { packetListEntry.IsVisible = true; } break; case FilterType.StringContents: var findStr = Convert.ToString(set.value).ToLower(); var packetStr = Encoding.UTF8.GetString(packetListEntry.Data).ToLower(); if (packetStr.Contains(findStr)) { packetListEntry.IsVisible = true; } break; } } }
public static FilterSet[] Parse(string input) { Debug.WriteLine(input); List <FilterSet> output = new List <FilterSet>(); if (input.Length == 0) { return(output.ToArray()); } for (int i = 0; i < input.Length; i++) { try { string thisFilter = ""; FilterType type; thisFilter = input.Substring(0, input.IndexOf(";") + 1); input = input.Replace(thisFilter, ""); object value; // _A(ActorControlType) if (thisFilter.Substring(0, "_A(".Length) == "_A(") { type = FilterType.ActorControl; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = int.Parse(vstring, NumberStyles.HexNumber); } // _AN(ActorControlName) else if (thisFilter.Substring(0, "_AN(".Length) == "_AN(") { type = FilterType.ActorControlName; string vstring = thisFilter.Substring(4, thisFilter.IndexOf(')', 4) - 4); value = vstring; } // _S(CharName) else if (thisFilter.Substring(0, "_S(".Length) == "_S(") { type = FilterType.StringContents; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = vstring; } else if (thisFilter.Substring(0, "_N(".Length) == "_N(") { type = FilterType.PacketName; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = vstring; } else { type = FilterType.Message; string vstring = thisFilter.Substring(0, thisFilter.Length - 1); value = int.Parse(vstring, NumberStyles.HexNumber); } FilterSet set = new FilterSet { type = type, value = value }; output.Add(set); Debug.WriteLine(input.Length); } catch (Exception exc) { MessageBox.Show( $"[Filter] Filter Parse error!\n\n{exc}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); break; } if (input.Length <= 1) { break; } } return(output.ToArray()); }
public static FilterSet[] Parse(string input) { Debug.WriteLine(input); List <FilterSet> output = new List <FilterSet>(); if (input.Length == 0) { return(output.ToArray()); } for (int i = 0; i < input.Length; i++) { string thisFilter = ""; FilterType type; thisFilter = input.Substring(0, input.IndexOf(";") + 1); input = input.Replace(thisFilter, ""); object value; if (thisFilter[0] != '_') { type = FilterType.Message; string vstring = thisFilter.Substring(0, thisFilter.Length - 1); value = vstring; } // _A(ActorControlType) else if (thisFilter.Substring(0, "_A(".Length) == "_A(") { type = FilterType.ActorControl; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = vstring; } // _AN(ActorControlName) else if (thisFilter.Substring(0, "_AN(".Length) == "_AN(") { type = FilterType.ActorControlName; string vstring = thisFilter.Substring(4, thisFilter.IndexOf(')', 4) - 4); value = vstring; } // _S(CharName) else if (thisFilter.Substring(0, "_S(".Length) == "_S(") { type = FilterType.StringContents; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = vstring; } // _N(Name) else if (thisFilter.Substring(0, "_N(".Length) == "_N(") { type = FilterType.PacketName; string vstring = thisFilter.Substring(3, thisFilter.IndexOf(')', 3) - 3); value = vstring; } // _I64([u]long) else if (thisFilter.Substring(0, "_I64(".Length) == "_I64(") { type = FilterType.Int64; string vstring = thisFilter.Substring("_I64(".Length, thisFilter.IndexOf(')', "_I64(".Length) - "_I64(".Length); value = vstring; } // _I32([u]int) else if (thisFilter.Substring(0, "_I32(".Length) == "_I32(") { type = FilterType.Int32; string vstring = thisFilter.Substring("_I32(".Length, thisFilter.IndexOf(')', "_I32(".Length) - "_I32(".Length); value = vstring; } // _I16([u]short) else if (thisFilter.Substring(0, "_I16(".Length) == "_I16(") { type = FilterType.Int16; string vstring = thisFilter.Substring("_I16(".Length, thisFilter.IndexOf(')', "_I16(".Length) - "_I16(".Length); value = vstring; } // _I8(char/byte) else if (thisFilter.Substring(0, "_I8(".Length) == "_I8(") { type = FilterType.Int8; string vstring = thisFilter.Substring("_I8(".Length, thisFilter.IndexOf(')', "_I8(".Length) - "_I8(".Length); value = vstring; } // _F(float) else if (thisFilter.Substring(0, "_F(".Length) == "_F(") { type = FilterType.Float; string vstring = thisFilter.Substring("_F(".Length, thisFilter.IndexOf(')', "_F(".Length) - "_F(".Length); value = vstring; } // _D(double) else if (thisFilter.Substring(0, "_D(".Length) == "_D(") { type = FilterType.Double; string vstring = thisFilter.Substring("_D(".Length, thisFilter.IndexOf(')', "_D(".Length) - "_D(".Length); value = vstring; } // _B(AA BB CC DD EE FF) else if (thisFilter.Substring(0, "_B(".Length) == "_B(") { type = FilterType.ByteArray; string vstring = thisFilter.Substring("_B(".Length, thisFilter.IndexOf(')', "_B(".Length) - "_B(".Length); value = vstring; } else { type = FilterType.Message; string vstring = thisFilter.Substring(0, thisFilter.Length - 1); value = int.Parse(vstring, NumberStyles.HexNumber); } FilterSet set = new FilterSet { type = type, value = value }; output.Add(set); Debug.WriteLine(input.Length); if (input.Length <= 1) { break; } } return(output.ToArray()); }