Imports System Imports System.IO Imports System.Xml Imports System.Xml.Xsl Imports System.Collections Imports System.Data Imports System.Text Public Class frmUPLReader Inherits System.Windows.Forms.Form Dim uplRead As System.IO.StreamReader Dim uplFile As System.IO.File Dim strUPL_Line As String Dim strSelected As String Dim strAll As String Dim uplFileInfo As FileInfo Dim intFileCount As Integer = 0 Dim strFileName As String Dim values As String Dim ods As New DataSet() Dim oTable As New DataTable("UPL INFO") #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lstFirst As System.Windows.Forms.ListBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Private Sub InitializeComponent() Me.lstFirst = New System.Windows.Forms.ListBox() Me.Button1 = New System.Windows.Forms.Button() Me.DataGrid1 = New System.Windows.Forms.DataGrid() CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'lstFirst ' Me.lstFirst.Location = New System.Drawing.Point(8, 8) Me.lstFirst.Name = "lstFirst" Me.lstFirst.Size = New System.Drawing.Size(1120, 56) Me.lstFirst.TabIndex = 3 ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(360, 712) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 4 Me.Button1.Text = "Button1" ' 'DataGrid1 ' Me.DataGrid1.DataMember = "" Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Location = New System.Drawing.Point(8, 72) Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.Size = New System.Drawing.Size(1256, 632) Me.DataGrid1.TabIndex = 5 ' 'frmUPLReader ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(1272, 741) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1, Me.Button1, Me.lstFirst}) Me.Name = "frmUPLReader" Me.Text = "frmUPLReader" Me.WindowState = System.Windows.Forms.FormWindowState.Maximized CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub frmUPLReader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim strAnyUPL As String = ".upl" Dim strUTsysPath As String = "Y:\UT2004\System" Try Dim dirINFO As New DirectoryInfo(strUTsysPath) Dim fileINFO As IO.FileInfo() = dirINFO.GetFiles() For Each uplFileInfo In fileINFO If uplFileInfo.Extension = (".upl") Then strFileName = uplFileInfo.ToString intFileCount = intFileCount + 1 Call ReadUPL() End If Next ods.Tables.Add(oTable) Catch exc As Exception MsgBox(exc.ToString) End Try 'open and read the ece bonus pack up End Sub Private Sub ReadUPL() Try 'quote this message box out 'MsgBox("change frmUPLReader line149, It assumes you have UT installed on drive Y:\") 'Unless you have UT with the ece bonus pack installed on Y:\ you need to change this uplRead = uplFileInfo.OpenText While uplRead.Peek <> -1 strUPL_Line = uplRead.ReadLine 'each line will go into the listbox 'the first line [Public] and any blank lines are skipped If strUPL_Line <> "[Public]" And strUPL_Line <> "" Then lstFirst.Items.Add(strUPL_Line) End If End While Catch exc As Exception MsgBox(exc.ToString) Finally uplRead.Close() End Try 'ods.DataSetName = "UPL" 'ods.Namespace = "PlayerUPL" 'ods.Tables.Add("UPL Contents") Try 'select a row from the listbox and put each field in the appropriate column 'strSelected = lstFirst.SelectedItem Dim intListCounter As Integer intListCounter = lstFirst.Items.Count Dim doloopcounter As Integer = 1 'every item in the list box gets broken down and put into a table / dataset Do Until doloopcounter = intListCounter 'use the value of the loop couter to select an item from the list 'and then convert it into a string lstFirst.SelectedIndex = doloopcounter lstFirst.SelectedItem = lstFirst.SelectedIndex strSelected = lstFirst.SelectedItem 'a new row each time the loop runs Dim oRows As DataRow = oTable.NewRow 'if the box pops up "it should work" 'MsgBox(strSelected) 'removes Player={ from the begining of the line (characters 0-8) strSelected = strSelected.Remove(0, 8) 'I don't know if I actually use strAll (thining probably not) strAll = strSelected 'not using this anymore (used the Remove above to do the same thing) ' strSelected = strSelected.TrimStart("Player=(") 'strSelected = strUPL_Line.Trim(")") 'trim off the ) from the end of the selected line strSelected = strSelected.TrimEnd(")") values = strSelected Dim field As String() = Nothing 'field will hold each seperate property by splitting at every comma field = values.Split(",") Dim delim As String() = Nothing Dim s As String Dim t As String 'look for strings in field. s will hold the property for each string (ie DefaultName="Karag") For Each s In field 'lstFields.Items.Add(s) 'create headers by splitting at the equal sign of each property, s will hold those strings delim = s.Split("=") 'this builds the table. t will split on the equal (=) sign of each property (which has 'already been seperated from the sting) then it adds only the half that matches the case '(ie after splitting s=DefaultName="Karag" , t will split that so that t="DefaultName" 'and t="=Karag" , since "DefaultName" is one of the cases it gets added to the header 'of the table then s gets added to the corresponding row of the table Dim bSkipColumn As Boolean For Each t In delim Select Case t Case "DefaultName" 'check if column has been created If oTable.Columns.Contains(t) Then 'if this column already exists do not crash program by trying to make it a 2nd time! bSkipColumn = True End If 'if the column does not exist then go ahead and create it If bSkipColumn = False Then oTable.Columns.Add(t) End If 'add the property ( s ) associated to the column ( t ) oRows.Item(t) = s 'start repeating until you have a column and or entry for each property needed Case "Race" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Mesh" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Species" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "BodySkin" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "FaceSkin" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Portrait" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Text" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Sex" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Menu" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case " Accuracy" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "Jumpiness" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "StrafingAbility" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "FavoriteWeapon" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "TeamFace" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s Case "BotUse" If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If oRows.Item(t) = s End Select t = ("UPL Name") If oTable.Columns.Contains(t) Then bSkipColumn = True End If If bSkipColumn = False Then oTable.Columns.Add(t) End If ' t = ("File Count") 'If oTable.Columns.Contains(t) Then ' bSkipColumn = True 'End If 'If bSkipColumn = False Then 'oTable.Columns.Add(t) 'End If Next t bSkipColumn = False Next s oRows.Item("UPL Name") = strFileName 'increment loop couter doloopcounter = doloopcounter + 1 'add the row to the table then start on the next row oTable.Rows.Add(oRows) 'link the data set (ods) to your table (oTable) Loop ' extrasRow.Item("File Count") = intFileCount ' oTable.Rows.Add(extrasRow) 'display the table on the grid DataGrid1.DataSource = ods DataGrid1.HeaderFont.Bold.ToString() DataGrid1.HeaderBackColor = System.Drawing.Color.DarkSlateGray DataGrid1.HeaderForeColor = System.Drawing.Color.White strFileName = "" 'possibly will count rows and assign a id to each before inserting the dataset into an actual database Dim intListCount As Integer Dim strListItem As String Catch exc As Exception MsgBox(exc.ToString) Finally 'oledbCon1.Close() End Try End Sub End Class