08
Apr
09

[VB.Net] Release: MSN Chat Log Reader 2

MSN Chat Log Reader 2

Main Window

Main Window

Features:

  • Custom Message colours
  • Custom Message options
  • Custom Save options
  • Remove messages from Log
  • Export as Comma Separated Text File (*.csv)
  • Export as Comma Separated Text File (*.txt)
  • Export as Tab Separated Text File (*.txt)
  • Reduces MSN Log file sizes when re-saved:
    msn-chat-log-reader-2-saved1

    Downloads & Source Code:

    Options Window

    Options Window

    Program:
    MSN Chat Log Reader 2.rar – 15 KB
    MSN Chat Log Reader 2.zip – 16 KB

    Source:
    MSN Chat Log Reader 2 Source.rar – 23 KB
    MSN Chat Log Reader 2 Source.zip – 24 KB

    Form1.vb:

    Public Class Form1
        Dim File As String
        Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
            ''Create Open File Dialog
            Dim ofd As New OpenFileDialog
            ofd.Filter = "XML Document (*.xml)|*.xml"
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Me.Text = "sim0n - MSN Chat Log Reader 2 - " & My.Computer.FileSystem.GetName(ofd.FileName)
                File = ofd.FileName
                ''Clear List
                ListView1.Items.Clear()
                ToolStripStatusLabel1.Text = "Loading XML"
                ''Resize the Progress bar
                pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
                pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
                ''Read the MSN Chat log
                ''https://sim0n.wordpress.com/2009/04/08/vbnet-parse-msn-logs/
                ''For comments on what the code does
                Dim XML_Reader As New System.Xml.XmlTextReader(ofd.FileName)
                XML_Reader.Read()
                XML_Reader.Read()
                XML_Reader.Read()
                XML_Reader.Read()
                XML_Reader.Read()
                Dim FirstSessionID As Integer = CInt(XML_Reader.GetAttribute("FirstSessionID"))
                Dim LastSessionID As Integer = CInt(XML_Reader.GetAttribute("LastSessionID"))
                ''Sets the progress bars maximum value
                pgb.Maximum = LastSessionID - FirstSessionID + 1
                ''Mstarter = Person who started conversation
                Dim MStarter As String = ""
                ''ID of current session
                Dim MID As Integer = 0
    
                While Not XML_Reader.EOF
                    ''Create listitem
                    Dim lvi As New ListViewItem
                    XML_Reader.Read()
                    Dim MDate As String = XML_Reader.GetAttribute("Date")
                    Dim MTime As String = XML_Reader.GetAttribute("Time")
                    Dim MSessionID As String = XML_Reader.GetAttribute("SessionID")
                    XML_Reader.Read()
                    XML_Reader.Read()
                    Dim FromFriendlyName As String = XML_Reader.GetAttribute("FriendlyName")
                    XML_Reader.Read()
                    XML_Reader.Read()
                    XML_Reader.Read()
                    Dim ToFriendlyName As String = XML_Reader.GetAttribute("FriendlyName")
                    XML_Reader.Read()
                    XML_Reader.Read()
                    Dim MStyle As String = XML_Reader.GetAttribute("Style")
                    Dim MText As String = XML_Reader.ReadString
                    ''Make sure that the XML was parsed correctly (Multi-person conversations Error)
                    If Not FromFriendlyName = "" Or Not ToFriendlyName = "" Or Not MSessionID = "" Then
                        ''Set up list item
                        lvi.Text = MSessionID
                        lvi.SubItems.Add(FromFriendlyName)
                        lvi.SubItems.Add(ToFriendlyName)
                        lvi.SubItems.Add(MDate & " - " & MTime)
                        lvi.SubItems.Add(MText)
                        ''If the session ID has changed
                        If Not MID = CDbl(MSessionID) Then
                            Try
                                ''Increase the progress bars value
                                pgb.Value += 1
                            Catch ex As Exception
                            End Try
                            ''Add a blank line
                            If MID <> 0 And My.Settings.ShowSpacer = True Then
                                Dim lv2 As New ListViewItem()
                                lv2.BackColor = My.Settings.SpacerColour
                                ListView1.Items.Add(lv2)
                            End If
                            ''Reset session details
                            MID = CInt(MSessionID)
                            MStarter = FromFriendlyName
                            lvi.ForeColor = My.Settings.M1Colour
                        Else
                            ''Colour messages
                            If Not MStarter = FromFriendlyName Then
                                lvi.ForeColor = My.Settings.M2Colour
                            Else
                                lvi.ForeColor = My.Settings.M1Colour
                            End If
                        End If
                        ''Add the list item
                        ListView1.Items.Add(lvi)
                    End If
                    XML_Reader.Read()
                End While
                ''Size columns
                ListView1.Columns(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
                ListView1.Columns(3).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
                ListView1.Columns(4).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
                ''Reset progress
                pgb.Value = 0
                ToolStripStatusLabel1.Text = "Ready   "
                ''Resize progress bar
                pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
                pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ''Resize the Progress bar
            pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
            pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
        End Sub
    
        Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            ''Resize the Progress bar
            pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
            pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
        End Sub
    
        Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
            MessageBox.Show("MSN Chat Log Reader 2.0" & vbNewLine & "----------------" & vbNewLine & "Created by: sim0n" & vbNewLine & "http://www.sim0n.wordpress.com", "About", MessageBoxButtons.OK, MessageBoxIcon.None)
        End Sub
    
        Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
            Application.Exit()
        End Sub
    
        Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
            If ListView1.Items.Count = 0 Then
                MessageBox.Show("There are no messages to save", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If
    
            ''If the log is large, give warning
            If ListView1.Items.Count > 2000 And My.Settings.ShowWarning = True Then
                If MessageBox.Show("Converting logs to different formats can take a long time." & vbNewLine & "If your log is large and you only want to save parts then use the edit menu to remove the unwanted messages" & vbNewLine & vbNewLine & " Continue Saving?", "Warning:", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then Exit Sub
            End If
            ''Create save file dialog
            Dim SFD As New SaveFileDialog
            SFD.Filter = "Comma Separated Text File (*.csv)|*.csv|Comma Separated Text File (*.txt)|*.txt|Tab Separated Text File (*.txt)|*.txt"
            SFD.FilterIndex = My.Settings.FileType + 1
            If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                ''Set up
                ToolStripStatusLabel1.Text = "Saving Log"
                pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
                pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
                pgb.Maximum = ListView1.Items.Count
                ''Determine deliminater
                Dim deliminater As String = ""
                If SFD.FilterIndex = 1 Or SFD.FilterIndex = 2 Then
                    deliminater = ","
                Else
                    deliminater = vbTab
                End If
                ''Create file output
                Dim Output As String = ""
                For Each row As ListViewItem In ListView1.Items
                    pgb.Value += 1
                    For Each item As ListViewItem.ListViewSubItem In row.SubItems
                        ''Set up text qualifiers
                        Dim temp As String = item.Text.Replace("""", """""")
                        ''Add to output
                        Output += """" & temp & """" & deliminater
                    Next
                    Output += Environment.NewLine
                Next
                ''Write to file
                My.Computer.FileSystem.WriteAllText(SFD.FileName, Output, False)
                ''Reset progress
                pgb.Value = 0
                ToolStripStatusLabel1.Text = "Ready   "
                ''Resize progress bar
                pgb.Location = New Point(ToolStripStatusLabel1.Width + 10, pgb.Location.Y)
                pgb.Width = Me.Width - (ToolStripStatusLabel1.Width + 42)
                ''Save complete
                MessageBox.Show("Save Completed." & vbNewLine & vbNewLine & "Original Log Size: " & My.Computer.FileSystem.GetFileInfo(File).Length / 1000 & " KB" & vbNewLine & "New Log Size: " & My.Computer.FileSystem.GetFileInfo(SFD.FileName).Length / 1000 & " KB" & vbNewLine & vbNewLine & "Saving " & (My.Computer.FileSystem.GetFileInfo(File).Length - My.Computer.FileSystem.GetFileInfo(SFD.FileName).Length) / 1000 & " KB", "Success!", MessageBoxButtons.OK)
            End If
        End Sub
    
        Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
            ''Remove items
            For Each item As ListViewItem In ListView1.SelectedItems
                item.Remove()
            Next
        End Sub
    
        Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
            Options.ShowDialog()
        End Sub
    
        Private Sub AsdToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AsdToolStripMenuItem.Click
            System.Diagnostics.Process.Start("http://www.sim0n.wordpress.com")
        End Sub
    End Class

    Options.vb:

    Imports System.Windows.Forms
    
    Public Class Options
    
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            My.Settings.FileType = ComboBox1.SelectedIndex
            My.Settings.M1Colour = Panel1.BackColor
            My.Settings.M2Colour = Panel2.BackColor
            My.Settings.ShowSpacer = RadioButton1.Checked
            My.Settings.ShowWarning = RadioButton3.Checked
            My.Settings.SpacerColour = Panel3.BackColor
            My.Settings.Save()
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        End Sub
    
        Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        End Sub
    
        Private Sub Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Panel1.BackColor = My.Settings.M1Colour
            Panel2.BackColor = My.Settings.M2Colour
            Panel3.BackColor = My.Settings.SpacerColour
            If My.Settings.ShowSpacer = True Then
                RadioButton1.Checked = True
            Else
                RadioButton2.Checked = True
            End If
            If My.Settings.ShowWarning = True Then
                RadioButton3.Checked = True
            Else
                RadioButton4.Checked = True
            End If
            ComboBox1.SelectedIndex = My.Settings.FileType
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim cd1 As New ColorDialog
            If cd1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Panel1.BackColor = cd1.Color
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim cd1 As New ColorDialog
            If cd1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Panel2.BackColor = cd1.Color
            End If
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim cd1 As New ColorDialog
            If cd1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Panel3.BackColor = cd1.Color
            End If
        End Sub
    End Class
    Advertisements

    2 Responses to “[VB.Net] Release: MSN Chat Log Reader 2”


    1. 1 thedarshan
      September 5, 2009 at 9:14 pm

      Nice job, exactly what I was looking for.
      Thank you

    2. 2 Sindre (Norway!)
      January 6, 2010 at 5:44 pm

      Thank you so much!
      Have a nice day. 🙂


    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s


    %d bloggers like this: