Imports DevComponents.DotNetBar Public Class frmMimicOptions 'this is the container of the original filters (loaded from mimic.dat) Private OriginalFilters As New List(Of ListViewItem) Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try If txtOld.Text <> String.Empty Then 'this value is a must Dim ItemToAdd As New ListViewItem({txtOld.Text, _txtNew.Text}) With lstFilters For Each Item As ListViewItem In .Items 'check if the item already exists if it does then displays an alert and exit sub If Item.Text = ItemToAdd.Text Then TopMost = False MessageBoxEx.Show("This item already exists.", "Adding", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If Next 'added and checked .Items.Add(ItemToAdd) .Items(.Items.Count - 1).Checked = True End With Else Throw New Exception("Old value camp is required.") End If Catch ex As Exception TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try lstFilters.Items.Clear() Catch ex As Exception TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub frmPackets_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Path As String = System.AppDomain.CurrentDomain.BaseDirectory & "mimic.dat", Stream As IO.FileStream = Nothing If IO.File.Exists(Path) Then Try 'clean data If OriginalFilters.Count > 0 Then OriginalFilters.Clear() If lstFilters.Items.Count > 0 Then lstFilters.Items.Clear() 'deserialize the container of listviewitems Dim Formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter Stream = New IO.FileStream(Path, IO.FileMode.Open) OriginalFilters = CType(Formatter.Deserialize(Stream), List(Of ListViewItem)) lstFilters.Items.AddRange(OriginalFilters.ToArray) 'add those items to the listview Catch ex As Exception MessageboxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If Stream IsNot Nothing Then Stream.Close() End Try End If If CBool(My.Settings.LogFormat64) = False Then Me.TitleText = "Ihabbox - Mimic Options (Trial Version)" End If MessageBoxEx.MessageBoxTextColor = Color.White MessageBoxEx.EnableGlass = False End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim Writer As IO.FileStream = Nothing Try If OriginalFilters.Count > 0 Then OriginalFilters.Clear() 'clear 'save data Writer = New IO.FileStream(System.AppDomain.CurrentDomain.BaseDirectory & "mimic.dat", IO.FileMode.OpenOrCreate) 'deserialize the container of listviewitems Dim Formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter For Each Item As ListViewItem In lstFilters.Items 'moving data OriginalFilters.Add(Item) Next TopMost = False Formatter.Serialize(Writer, OriginalFilters) 'serialize into a file MessageBoxEx.Show("Saved successfully!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If Writer IsNot Nothing Then Writer.Close() End Try End Sub Private Sub frmPackets_FormClosing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.FormClosing My.Settings.Save() 'save options data e.Cancel = True 'avoid the lstfilters cleaning Me.Hide() 'check for changes If lstFilters.Items.Count <> OriginalFilters.Count Then DisplayAlert() 'display an alert which warns the user about the unsaved changes Exit Sub Else For i As Int32 = 0 To OriginalFilters.Count - 1 If Not lstFilters.Items.Item(i).Equals(OriginalFilters.Item(i)) Then DisplayAlert() : Exit Sub Next End If 'there are not changes frmSearch.Hide() Hide() End Sub Private Sub DisplayAlert() Dim Response As DialogResult = MessageboxEx.Show("There are unsaved changes, would you like to save them?", _ "Unsaved", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) If Response = Windows.Forms.DialogResult.Yes Then btnSave_Click(Me, New EventArgs) 'if the user clicks "Yes" save the new data frmSearch.Hide() Hide() ElseIf Response = Windows.Forms.DialogResult.No Then frmSearch.Hide() Hide() lstFilters.Items.AddRange(OriginalFilters.ToArray) 'if "No" restore the original data End If End Sub Private Sub ctmValue_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ctmValue.Opening If lstFilters.SelectedItems.Count = 0 Then e.Cancel = True 'if there are not selected items then abort the displaying ElseIf lstFilters.SelectedItems.Count > 1 Then ctmValue.Items.Item(0).Enabled = False 'if there are more than 1 object selected then disable the Edit menù End If End Sub Private Sub RemoveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveToolStripMenuItem.Click Try For Each Item As ListViewItem In lstFilters.SelectedItems Item.Remove() Next Catch ex As Exception TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click With frmSetFilters .Item = lstFilters.SelectedItems(0) 'if there are more than one item selected this menù being unclickable .FullShow = False 'check if the form has to show txtDescription and lblDescription .ShowDialog() End With End Sub Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try If txtOld.Text <> String.Empty Then 'this value is a must Dim ItemToAdd As New ListViewItem({txtOld.Text, _txtNew.Text}) With lstFilters For Each Item As ListViewItem In .Items 'check if the item already exists if it does then displays an alert and exit sub If Item.Text = ItemToAdd.Text Then Me.TopMost = False MessageBoxEx.Show("This item already exists.", "Adding", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If Next 'added and checked .Items.Add(ItemToAdd) .Items(.Items.Count - 1).Checked = True End With Else Me.TopMost = False Throw New Exception("Old value camp is required.") End If Catch ex As Exception Me.TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub ButtonX1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim Writer As IO.FileStream = Nothing Try Me.TopMost = False If OriginalFilters.Count > 0 Then OriginalFilters.Clear() 'clear 'save data Writer = New IO.FileStream(System.AppDomain.CurrentDomain.BaseDirectory & "mimic.dat", IO.FileMode.OpenOrCreate) 'deserialize the container of listviewitems Dim Formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter For Each Item As ListViewItem In lstFilters.Items 'moving data OriginalFilters.Add(Item) Next Me.TopMost = False Formatter.Serialize(Writer, OriginalFilters) 'serialize into a file MessageBoxEx.Show("Saved successfully!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception Me.TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If Writer IsNot Nothing Then Writer.Close() Me.TopMost = True End Try End Sub Private Sub ButtonX1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveAll.Click Try lstFilters.Items.Clear() Catch ex As Exception Me.TopMost = False MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.TopMost = True End Try End Sub End Class