HMS

Home Media Server for Roku Players
git clone https://www.brianlane.com/git/HMS
Log | Files | Refs | README | LICENSE

checkServerUrl.brs (2216B)


      1 '*****************************************************************
      2 '**  Home Media Server Application
      3 '**  Copyright (c) 2010-2013 Brian C. Lane All Rights Reserved.
      4 '*****************************************************************
      5 
      6 '************************************************************
      7 ' ** Check the registry for the server URL
      8 ' ** Prompt the user to enter the URL or IP if it is not
      9 ' ** found and write it to the registry.
     10 '************************************************************
     11 Function checkServerUrl(forceEdit As Boolean) As Boolean
     12     serverUrl = RegRead("ServerURL")
     13     if (serverUrl = invalid) then
     14         print "ServerUrl not found in the registry"
     15         serverUrl = "video.local"
     16     else if not forceEdit and isUrlValid(serverUrl+"/Setup-SD.png") then
     17         print "Server set to "; serverUrl
     18         return true
     19     end if
     20 
     21     screen = CreateObject("roKeyboardScreen")
     22     port = CreateObject("roMessagePort")
     23     screen.SetMessagePort(port)
     24     screen.SetTitle("HMS Video Server URL")
     25     screen.SetText(serverURL)
     26     screen.SetDisplayText("Enter Host Name or IP Address")
     27     screen.SetMaxLength(25)
     28     screen.AddButton(1, "finished")
     29     screen.Show()
     30 
     31     while true
     32         msg = wait(0, screen.GetMessagePort())
     33         print "message received"
     34         if type(msg) = "roKeyboardScreenEvent"
     35             if msg.isScreenClosed()
     36                 return false
     37             else if msg.isButtonPressed() then
     38                 print "Evt: ";msg.GetMessage();" idx:"; msg.GetIndex()
     39                 if msg.GetIndex() = 1 then
     40                     serverText = screen.GetText()
     41                     print "Server set to "; serverText
     42 
     43                     if isUrlValid(serverText) then
     44                         RegWrite("ServerURL", serverText)
     45                         return true
     46                     end if
     47                 endif
     48             endif
     49         endif
     50     end while
     51 End Function
     52 
     53 '************************************************************
     54 '** Check a URL to see if it is valid
     55 '************************************************************
     56 Function isUrlValid( url As String ) As Boolean
     57     result = getHTMLWithTimeout(url, 60)
     58     return not result.error
     59 End Function
     60