xEPGsearch plug-in www

Xlobby plugin development

Re: xEPGsearch plug-in www

Postby art on Thu Jun 21, 2007 1:33 pm

Interesting idea Sean, but I don’t think it’s doable in Xlobby alone. Filters in XL would narrow down search results, but you would need to have search results to begin with, which is not what you going for here, I think.
On the other hand it should be doable in plug-in itself, I would need to intercept keyboard strokes and perform a search on any alpha or numeric ones. Let me see what I can do here, I’ll try to get back with you around weekend.

EDIT: Or, it may also be doable with girder – same idea as above.
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby badubo on Thu Jun 21, 2007 2:43 pm

another solution, is to have in the plugin a timer that monitors the changes in the text button and restart the search if changes occur.
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Re: xEPGsearch plug-in www

Postby art on Fri Jun 22, 2007 2:39 pm

badubo wrote:another solution, is to have in the plugin a timer that monitors the changes in the text button and restart the search if changes occur.


And we have a winner! :D That's probably the simplest way to do this. Thanks badubo!
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby art on Sat Jun 23, 2007 3:52 am

Hey Sean, try downloading plug-in again. There is a new command "autosearch", that turns on and off search as you type. Argument for the command is in the format: "on/off/all:category@xmlfile"
'all' will work as toggle; category, like in the 'search' command, is the name of the category for search results; and 'xmlfile' are name(s) of xml file(s) you want to search, separated by comas (no .xml extension)
Per badubo's advice (thanks again man!) I implemented timer that is set to 250ms (if you need it to be user defined, let me know) and the search is locked once it starts, so it won't restart till it's over, however, you shouldn't type during the search. The search 'type' is also locked to "Starts with", you can change 'time' and 'filed'. I tested it only few times, so if you find any bugs let me know...

I have to say, first 2-3 letters are kindda slow, I turned off screen updates for results during search for this autosearch, but still...
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby S Pittaway on Wed Jun 27, 2007 8:58 am

it works ok for me, like you say a bit slow at first but its usable :)

the one in the nebula tv software is a bit quicker i hink it looks kindof neat having it auto filter.

I would prefer it to be locked to contains works (i nver know what i am searching for, just a bit of the title :))

out of interest how are you turning off screen updates, i always seem to have no end of problems when i try and do that...
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Re: xEPGsearch plug-in www

Postby art on Wed Jun 27, 2007 11:02 pm

I unlocked the "Starts With" (type) variable, it will still be set to "Starts With" when you turn on autosearch, but you are able to change it now. The only reason I locked it in the first place was that if user keys lets say "a" it would most likely bring 99% of their xml file with type set "contains" ...

I added one more thing that may be helpful with autosearch - you can now set number of letters (white spaces including) before the autosearch would kick in. To do that change argument for autosearch command to:
all/n:category@xmlfile
where 'n' is the number of letters. So, if n = 5 you could type 'the' or 'the ' without autosearch starting, on 'the o' (for 'the office') autosearch would start.

Also I turned off autosearch when deleting input (it was driving me crazy) in other words when input changes, new input has to be longer than the prior one.

The screen updates are nothing more than
GrabPaintKey()
do your thing
ReleasePaintKey()
Invalidate() to repaint the screen
It works for what I need.... :)
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby homepc on Thu Jun 28, 2007 12:37 pm

Art,

Great plugin. Although you say you turned off the autosearch when deleting input? I actually found this feature very helpful. If I entered an input and got no results, then I could just start deleting characters until I found something. Maybe I spelled it wrong or something like that. Just my thoughts.

Thanks
Ray
homepc
 
Posts: 251
Joined: Tue Mar 20, 2007 1:27 pm
Location: Delaware

Re: xEPGsearch plug-in www

Postby art on Thu Jun 28, 2007 6:33 pm

OK, you can control now 'search on delete' in autosearch by adding ':on' or ':off" to the end of the argument in autosearch command. ex: all/n:category@xmlfile:off
Default is 'on'.
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby homepc on Thu Jun 28, 2007 6:37 pm

SWEET!! great work!!
homepc
 
Posts: 251
Joined: Tue Mar 20, 2007 1:27 pm
Location: Delaware

Re: xEPGsearch plug-in www

Postby S Pittaway on Fri Jun 29, 2007 11:41 am

i always end up with problems if i try and use GrabPaintKey() / ReleasePaintKey(), maybe to much is going on i my plugin when i want to lock the screen down :)
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Re: xEPGsearch plug-in www

Postby P3rv3rt B3ar on Sat Jun 30, 2007 6:16 am

S Pittaway wrote:i always end up with problems if i try and use GrabPaintKey() / ReleasePaintKey(), maybe to much is going on i my plugin when i want to lock the screen down :)


So very true. Happens me all the time also and can generate real hard to find bugs. I build debugging "system" around these commands, damn i so wish Steven would have made them more robust and programmer friendly, But i already complained once... :(
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Re: xEPGsearch plug-in www

Postby jpoveda on Sat Jun 26, 2010 7:45 am

Hello,

I know that I'm just a dreamer but, Art, are you still there?

I would propose to you to adding channel as a field type to search......

Thanks in advance
jpoveda
 
Posts: 111
Joined: Mon May 17, 2004 6:45 am
Location: Spain

Re: xEPGsearch plug-in www

Postby art on Sat Jun 26, 2010 4:30 pm

jpoveda wrote:Hello,

I know that I'm just a dreamer but, Art, are you still there?

I would propose to you to adding channel as a field type to search......

Thanks in advance



Well, I got the message from the forum, but I stoped using xlobby shortly after Steve took it commercial. Since then, I switched all PCs to linux, so I don't even have windows on any of my machines.
I did take a look at xmltv to see if channel is even a possibility, it probably is, but it would involve some more coding than for other fields, so it's not a simple matter of just adding it.
With all that, and the fact that I'm not even sure if I have the source code, I'll have to say no, sorry.
art
art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

Re: xEPGsearch plug-in www

Postby jpoveda on Sun Jun 27, 2010 4:30 am

Hello Art,

Nice to ear you. Thanks for your answer. Could it be possible have code program to try to modify myself?
jpoveda
 
Posts: 111
Joined: Mon May 17, 2004 6:45 am
Location: Spain

Re: xEPGsearch plug-in www

Postby art on Sun Jun 27, 2010 2:59 pm

You're in luck, I found my xlobby plugins in some old backup zip file :). Code looks terrible, but you should be able to figure it out. It's not too long. Good luck!

Code: Select all

Imports XPluginSDK
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Timers
Imports System.Text.RegularExpressions

Public Class xEPGsearch
    Implements XPlugin

#Region "xlobby members"

    Private xhlp As XPluginHelper

    Public Sub SetHelper(ByVal xhelper As XPluginSDK.XPluginHelper) Implements XPluginSDK.XPlugin.SetHelper
        xhlp = xhelper
    End Sub

    Public Function GetDescription() As String Implements XPluginSDK.XPlugin.GetDescription
        Return "EPG Search Plug-in by art"
    End Function

    Public Function GetName() As String Implements XPluginSDK.XPlugin.GetName
        Return "xEPGsearch"
    End Function

    Public Function GetPluginType() As String Implements XPluginSDK.XPlugin.GetPluginType
        Return "EPG"
    End Function

    Public Function GetStatus() As String Implements XPluginSDK.XPlugin.GetStatus
        Return ""
    End Function

    Public Sub ShowDialog() Implements XPluginSDK.XPlugin.ShowDialog

    End Sub

    Public Function GetVariable(ByVal name As String) As Object Implements XPluginSDK.XPlugin.GetVariable
        Dim var As String = ""
        Select Case UCase(name)
            Case Is = "TIME"
                var = translate(timeType)
            Case Is = "FIELD"
                var = translate(field)
            Case Is = "TYPE"
                var = translate(strType)
            Case Is = "STATUS"
                var = translate(status)
            Case Is = "RESULTS"
                var = results
            Case Is = "CRITERIA"
                var = criteria
            Case Is = "AUTOSEARCH"
                var = translate(vautosearch)
        End Select
        Return var
    End Function

    Public Function GetCommands() As System.Collections.ArrayList Implements XPluginSDK.XPlugin.GetCommands

        Dim commands As ArrayList = New ArrayList
        commands.Add("Search(category@xmlfile)")
        commands.Add("Set Field(field name)")
        commands.Add("Set Time(time criteria)")
        commands.Add("Set Type(search type)")
        commands.Add("Auto Search(on/off:category@xmlfile)")
        Return commands

    End Function

    Public Sub Execute(ByVal command As String) Implements XPluginSDK.XPlugin.Execute
        If command.Contains("Search(category@xmlfile)") Then
            If command.Contains("Search(category@xmlfile)") Then
                command = command.Replace("Search(category@xmlfile) ", "")
            Else
                command = "xepgsearch" '// default name for category
            End If
            search(command)
        ElseIf command.Contains("Set Field(field name)") Then
            If command.Contains("Set Field(field name) ") Then
                command = command.Replace("Set Field(field name) ", "")
            Else
                command = "ALL"
            End If
            set_field(command)
        ElseIf command.Contains("Set Time(time criteria)") Then
            If command.Contains("Set Time(time criteria) ") Then
                command = command.Replace("Set Time(time criteria) ", "")
            Else
                command = "ALL"
            End If
            set_time(command)
        ElseIf command.Contains("Set Type(search type)") Then
            If command.Contains("Set Type(search type) ") Then
                command = command.Replace("Set Type(search type) ", "")
            Else
                command = "ALL"
            End If
            set_type(command)
        ElseIf command.Contains("Auto Search(on/off:category@xmlfile)") Then
            If command.Contains("Auto Search(on/off:category@xmlfile) ") Then
                autosearch(command.Replace("Auto Search(on/off:category@xmlfile) ", ""))
            Else
                autosearch("ALL:xepgsearch@xmltv")
            End If
        End If

    End Sub

#End Region

#Region "plug-in variables"

    Private appPath As String = System.AppDomain.CurrentDomain.BaseDirectory
    Private status As String = "Ready"
    Private results As String = "0"
    Private criteria As String = ""
    Private xmltv As String = "xmltv"
    Private navigator As String = "tv/programme/title"
    Private field As String = "Title"
    Private cat As String = ""
    Private strType As String = "Exact Match"
    Private timeType As String = "Now and Future"
    Private vautosearch As String = "OFF"
    Private dic As New Hashtable
    Private xmls As ArrayList
    Private t As New Timer(250)
    Private v_input As String = ""
    Private searching As Boolean = False
#End Region

#Region "plug-in core members"

    Private Sub search(ByVal command As String)

        searching = True
        Dim numberOfMatches As Integer = 0
        Dim xmlWriter As Xml.XmlTextWriter '// db writer
        Dim strFlag As Boolean = False
        Dim timeFlag As Boolean = False
        Dim textReader As XmlTextReader
        Dim xDoc As XPathDocument
        Dim xNav As XPathNavigator
        Dim xIter As XPathNodeIterator
        Dim xIterName As XPathNodeIterator '// for channel names
        Dim xmltvStr As String = "" '// string will hold values from xml file
        Dim chName As String = ""

        '// get search input from the user
        Dim searchStr As String = xhlp.ConvertVariables("%button>input%")
        '// if empty exit
        If searchStr = "" Then Exit Sub

        '// show user that search started
        xhlp.GrabPaintKey()
        criteria = searchStr
        status = "Please wait, searching ..."
        '// refresh XL screen
        xhlp.ReleasePaintKey()
        xhlp.Invalidate()
        '// freez XL
        xhlp.GrabPaintKey()

        '// process command string
        If command <> "auto" Then processCommand(command)

        '// start writing DB that will hold results
        xmlWriter = New Xml.XmlTextWriter(appPath & "databases\xEPGsearch.xml", Nothing)
        With xmlWriter
            .Formatting = Formatting.Indented
            .Indentation = 2
            .IndentChar = " "
            .WriteStartDocument()
            .WriteStartElement("database")
        End With
        '// get files from arraylist and search them
        For y As Integer = 0 To xmls.Count - 1
            xmltv = xmls(y).ToString & ".xml"

            '// load xml file with epg
            Try
                textReader = New XmlTextReader(appPath & "xmltv\" & xmltv)
                textReader.Read()
                xDoc = New XPathDocument(textReader)
                xNav = xDoc.CreateNavigator()
                xIter = xNav.Select(navigator)
            Catch ex As Exception
                xhlp.ReleasePaintKey()
                status = translate("Error. See log for details.")
                Log(ex.Message & vbCrLf & "@xmltv load")
                Exit Sub
            End Try

            '// serach for matches
            While xIter.MoveNext()
                Try
                    '// get string from the file
                    xmltvStr = xIter.Current.Value.ToString()

                    '// check if xmltvTitle is a match with searchStr
                    If strType = "Exact Match" Then
                        If Regex.IsMatch(UCase(xmltvStr), "^" & UCase(searchStr) & "$") Then strFlag = True
                    ElseIf strType = "Starts With" Then
                        If Regex.IsMatch(UCase(xmltvStr), "^" & UCase(searchStr)) Then strFlag = True
                    ElseIf strType = "Contains" Then
                        If Regex.IsMatch(UCase(xmltvStr), UCase(searchStr)) Then strFlag = True
                    ElseIf strType = "Contains Words" Then
                        If Regex.IsMatch(UCase(xmltvStr), Replace(UCase(searchStr), " ", ".*")) Then strFlag = True
                    End If
                Catch ex As Exception
                    status = translate("Error. See log for details.")
                    Log(ex.Message & vbCrLf & "@fieldcheck")
                    With xmlWriter
                        .WriteEndElement() '// database
                        .WriteEndDocument()
                    End With
                    xmlWriter.Flush()
                    xmlWriter.Close()
                    xhlp.ReleasePaintKey()
                    Exit Sub
                End Try

                '// if match was found check for time match
                If strFlag Then
                    Dim currNav As XPathNavigator
                    Dim sDateTime, eDateTime As Date
                    Dim sTime, eTime As String

                    Try
                        currNav = xIter.Current.Clone()
                        If navigator.Contains("tv/programme/credits/") Or _
                        navigator.Contains("tv/programme/rating/") Then
                            currNav.MoveToParent()
                            currNav.MoveToParent()
                        Else
                            currNav.MoveToParent()
                        End If

                        sTime = currNav.GetAttribute("start", "")
                        sDateTime = DateSerial(sTime.Substring(0, 4), sTime.Substring(4, 2), sTime.Substring(6, 2)) & _
                            " " & TimeSerial(sTime.Substring(8, 2), sTime.Substring(10, 2), 0)

                        eTime = currNav.GetAttribute("stop", "")
                        eDateTime = DateSerial(eTime.Substring(0, 4), eTime.Substring(4, 2), eTime.Substring(6, 2)) & _
                            " " & TimeSerial(eTime.Substring(8, 2), eTime.Substring(10, 2), 0)
                    Catch ex As Exception
                        status = translate("Error. See log for details.")
                        Log(ex.Message & vbCrLf & "@gettime")
                        With xmlWriter
                            .WriteEndElement() '// database
                            .WriteEndDocument()
                        End With
                        xmlWriter.Flush()
                        xmlWriter.Close()
                        xhlp.ReleasePaintKey()
                        Exit Sub
                    End Try

                    '// check time criteria
                    Try
                        If DateDiff(DateInterval.Minute, sDateTime, Date.Now) < 0 _
                                                    And timeType = "Future Only" Then
                            timeFlag = True
                        ElseIf DateDiff(DateInterval.Minute, eDateTime, Date.Now) < 0 _
                                                    And timeType = "Now and Future" Then
                            timeFlag = True
                        ElseIf timeType = "All Air Times" Then
                            timeFlag = True
                        End If
                    Catch ex As Exception
                        status = translate("Error. See log for details.")
                        Log(ex.Message & vbCrLf & "@timecheck")
                        With xmlWriter
                            .WriteEndElement() '// database
                            .WriteEndDocument()
                        End With
                        xmlWriter.Flush()
                        xmlWriter.Close()
                        xhlp.ReleasePaintKey()
                        Exit Sub
                    End Try

                    '// if time match was found write results to DB
                    If timeFlag Then
                        Try
                            '// update results and freez again
                            numberOfMatches = numberOfMatches + 1
                            If vautosearch = "OFF" Then
                                xhlp.ReleasePaintKey()
                                results = numberOfMatches
                                xhlp.Invalidate()
                                xhlp.GrabPaintKey()
                            End If

                            '// get the name of the channel
                            Dim id As String = currNav.GetAttribute("channel", "")
                            xIterName = xNav.Select("tv/channel")
                            While xIterName.MoveNext
                                If id = xIterName.Current.GetAttribute("id", "") Then
                                    xIterName.Current.MoveToFirstChild()
                                    chName = xIterName.Current.Value
                                    xIterName.Current.MoveToRoot()
                                    Exit While
                                End If
                            End While

                            '// write results to DB
                            With xmlWriter
                                .WriteStartElement("item")
                                .WriteStartElement("display")
                                currNav.MoveToChild("title", "")
                                .WriteString(currNav.Value)
                                currNav.MoveToParent()
                                .WriteEndElement()
                                .WriteStartElement("information")
                                .WriteStartElement("epgname")
                                .WriteString(xmls(y).ToString())
                                .WriteEndElement()
                                .WriteStartElement("ID")
                                .WriteString(id)
                                .WriteEndElement()
                                .WriteStartElement("StartWeekday")
                                .WriteString(translate(sDateTime.DayOfWeek.ToString))
                                .WriteEndElement()
                                .WriteStartElement("StartDate")
                                .WriteString(sDateTime.Date)
                                .WriteEndElement()
                                .WriteStartElement("StartTime")
                                .WriteString(Format(sDateTime.Hour, "00") & ":" & Format(sDateTime.Minute, "00"))
                                .WriteEndElement()
                                .WriteStartElement("EndDate")
                                .WriteString(eDateTime.Date)
                                .WriteEndElement()
                                .WriteStartElement("EndTime")
                                .WriteString(Format(eDateTime.Hour, "00") & ":" & Format(eDateTime.Minute, "00"))
                                .WriteEndElement()
                                .WriteStartElement("Channel")
                                .WriteString(chName)
                                .WriteEndElement()
                                .WriteStartElement("xmltvInfo")
                                .WriteRaw(currNav.InnerXml)
                                .WriteEndElement()
                                .WriteEndElement() '// information
                                .WriteEndElement() '// item
                            End With
                        Catch ex As Exception
                            status = translate("Error. See log for details.")
                            Log(ex.Message & vbCrLf & "@write DB")
                            With xmlWriter
                                .WriteEndElement() '// database
                                .WriteEndDocument()
                            End With
                            xmlWriter.Flush()
                            xmlWriter.Close()
                            xhlp.ReleasePaintKey()
                            Exit Sub
                        End Try
                    End If
                End If
                strFlag = False
                timeFlag = False
            End While
        Next
        With xmlWriter
            .WriteEndElement() '// database
            .WriteEndDocument()
        End With
        xmlWriter.Flush()
        xmlWriter.Close()
        status = translate("Search ended.")
        results = numberOfMatches
        xhlp.ReleasePaintKey()
        xhlp.Invalidate()
        xhlp.SendCommand("command:category:refresh:" & cat)
        searching = False
    End Sub

    Private Sub autosearch(ByVal command As String)
        If command.Contains(":") Then
            Dim a() As String = command.Split(":")
            If UCase(a(0)) = "ON" Or (UCase(a(0)) = "ALL" And vautosearch = "OFF") Then
                vautosearch = "ON"
                strType = "Starts With"
                processCommand(a(1))
                t.Enabled = True
            ElseIf UCase(a(0)) = "OFF" Or (UCase(a(0)) = "ALL" And vautosearch = "ON") Then
                vautosearch = "OFF"
                t.Enabled = False
            End If
        End If
        xhlp.Invalidate()
    End Sub

    Private Sub set_field(ByVal command As String)
        '// set navigator to the field to be search
        '// user can use "all" as argument to work as toggle button
        Try
            command = UCase(command)
            If (field = "Title" And command = "ALL") Or command = "CATEGORY" Then
                field = "Category"
                navigator = "tv/programme/category"
            ElseIf (field = "Category" And command = "ALL") Or command = "DIRECTOR" Then
                field = "Director"
                navigator = "tv/programme/credits/director"
            ElseIf (field = "Director" And command = "ALL") Or command = "ACTOR" Then
                field = "Actor"
                navigator = "tv/programme/credits/actor"
            ElseIf (field = "Actor" And command = "ALL") Or command = "WRITER" Then
                field = "Writer"
                navigator = "tv/programme/credits/writer"
            ElseIf (field = "Writer" And command = "ALL") Or command = "GUEST" Then
                field = "Guest"
                navigator = "tv/programme/credits/guest"
            ElseIf (field = "Guest" And command = "ALL") Or command = "RATING" Then
                field = "Rating"
                navigator = "tv/programme/rating/value"
            Else
                field = "Title"
                navigator = "tv/programme/title"
            End If

        Catch ex As Exception
            status = translate("Error. See log for details.")
            Log(ex.Message & vbCrLf & "@set_field")
        End Try
        'fieldDic = translate(field)
        xhlp.Invalidate()

    End Sub

    Private Sub set_time(ByVal command As String)
        Try
            command = UCase(command)
            If (timeType = "Now and Future" And command = "ALL") Or command = "FUTURE ONLY" Then
                timeType = "Future Only"
            ElseIf (timeType = "Future Only" And command = "ALL") Or command = "ALL AIR TIMES" Then
                timeType = "All Air Times"
            Else
                timeType = "Now and Future"
            End If
        Catch ex As Exception
            status = translate("Error. See log for details.")
            Log(ex.Message & vbCrLf & "@set_time")
        End Try
        'timeTypeDic = translate(timeType)
        xhlp.Invalidate()

    End Sub

    Private Sub set_type(ByVal command As String)

        '// if autosearch is set only "starts with" applies
        If vautosearch = "ON" Then Exit Sub

        Try
            command = UCase(command)
            If (strType = "Exact Match" And command = "ALL") Or command = "STARTS WITH" Then
                strType = "Starts With"
            ElseIf (strType = "Starts With" And command = "ALL") Or command = "CONTAINS" Then
                strType = "Contains"
            ElseIf (strType = "Contains" And command = "ALL") Or command = "CONTAINS WORDS" Then
                strType = "Contains Words"
            Else
                strType = "Exact Match"
            End If
        Catch ex As Exception
            status = translate("Error. See log for details.")
            Log(ex.Message & vbCrLf & "@set_type")
        End Try
        'strTypeDic = translate(strType)
        xhlp.Invalidate()

    End Sub

#End Region

#Region "plug-in misc"

    Private Sub tOnOff(ByVal sender As Object, _
              ByVal e As System.Timers.ElapsedEventArgs)
        If v_input <> xhlp.ConvertVariables("%button>input%") _
            And xhlp.ConvertVariables("%button>input%") <> "" Then
            v_input = xhlp.ConvertVariables("%button>input%")
            If searching = False Then search("auto")
        End If
    End Sub

    Private Sub processCommand(ByVal command As String)
        xmls = New ArrayList
        If command.Contains("@") Then
            Dim s() As String = command.Split("@")
            cat = s(0)
            If s(1).Contains(",") Then
                Dim x() As String = s(1).Split(",")
                For z As Integer = 0 To x.Length - 1
                    xmls.Add(x(z))
                Next
            Else
                xmls.Add(s(1))
            End If
        Else
            cat = command
            xmls.Add("xmltv")
        End If
    End Sub

    Private Sub Log(ByVal Message As String)
        Dim LogFileName As String = appPath & "plugins\xEPGsearch\LogFile.txt"
        If Not Directory.Exists(appPath & "plugins\xEPGsearch") Then
            Directory.CreateDirectory(appPath & "plugins\xEPGsearch")
        End If

        If File.Exists(LogFileName) Then
            Dim f As New System.IO.FileInfo(LogFileName)
            If f.Length > 1000000 Then
                File.Copy(LogFileName, Replace(LogFileName, "LogFile.txt", "LogFile_old_" & _
                Format(Now.Year, "0000") & Format(Now.Month, "00") & Format(Now.Day, "00") & _
                Format(Now.Hour, "00") & Format(Now.Minute, "00") & Format(Now.Second, "00") & ".txt"))
                File.Delete(LogFileName)
            End If
        End If
        '// NOTE: True is for "Append" if the file exists,
        '// it will be appended, if the file does not exist, it will be created
        Dim LSW As New StreamWriter(LogFileName, True)
        LSW.WriteLine(Now & ": " & Message & vbCrLf)
        LSW.Close()
    End Sub

    Private Function translate(ByVal fraze As String) As String
        If dic.ContainsKey(LCase(fraze)) Then
            fraze = dic.Item(LCase(fraze))
        ElseIf fraze.Contains(" ") Then
            Dim fa() As String = fraze.Split(" ")
            For i As Integer = 0 To fa.Length - 1
                If dic.ContainsKey(LCase(fa(i))) Then
                    fraze = Replace(fraze, fa(i), dic.Item(LCase(fa(i))))
                End If
            Next
        End If
        Return fraze
    End Function

    Public Sub New()
        Try
            If System.IO.File.Exists(appPath & "plugins\xEPGsearch\dictionary.txt") Then
                '\\ read dictionary file
                Dim strReader As System.IO.StreamReader
                strReader = System.IO.File.OpenText(appPath & "plugins\xEPGsearch\dictionary.txt")
                While strReader.Peek <> -1
                    Dim myLine As String = strReader.ReadLine.ToString()
                    Try
                        Dim myLineSplit() As String = myLine.Split("=")
                        dic.Add(LCase(myLineSplit(0).ToString), myLineSplit(1).ToString)
                    Catch ex As Exception
                    End Try
                End While
            End If
        Catch ex As Exception
            status = translate("Error. See log for details.")
            Log(ex.Message & vbCrLf & "@loading dictionary")
        End Try
        Try
            Dim xmlWriter As Xml.XmlTextWriter = New Xml.XmlTextWriter(appPath & "databases\xEPGsearch.xml", Nothing)
            With xmlWriter
                .Formatting = Formatting.Indented
                .Indentation = 2
                .IndentChar = " "
                .WriteStartDocument()
                .WriteStartElement("database")
                .WriteEndElement()
                .WriteEndDocument()
            End With
            xmlWriter.Flush()
            xmlWriter.Close()
        Catch ex As Exception
            status = translate("Error. See log for details.")
            Log(ex.Message & vbCrLf & "@write initial db")
        End Try
        AddHandler t.Elapsed, AddressOf tOnOff
    End Sub

#End Region

End Class


art
 
Posts: 284
Joined: Sat Mar 20, 2004 8:40 am
Location: Allen, TX

PreviousNext