' Gambas module file

'' Routines for managing the IDE help system.

Public Const TYPE_NATIVE As Integer = 0
Public Const TYPE_CLASS As Integer = 1
Public Const TYPE_CONTROL As Integer = 2
Public Const TYPE_SYMBOL As Integer = 3
Public Const TYPE_EVENT As Integer = 4
Public Const TYPE_KEYWORD As Integer = 5
Public Const TYPE_SPECIAL As Integer = 6
Public Const TYPE_COMPONENT As Integer = 7

Private Const ROOT_URL As String = "http://gambasdoc.org/help"

Public $PopupHelpCache As Collection

Private Sub GetPath(sPath As String) As String
  
  sPath = Replace(sPath, "/gb+gui/", "/gb+qt/")
  sPath = Replace(sPath, "/gb+gtk/", "/gb+qt/")
  Return System.Path &/ "share/gambas" & CStr(System.Version) &/ "help" &/ sPath
  
End

Public Sub SetLanguage(sLang As String)
  
  Settings["/HelpLanguage"] = sLang
  
End

Public Sub GetLanguage(Optional bReturnVoidIfDefault As Boolean) As String
  
  Dim sLang As String
  Dim iPos As Integer
  Dim sCar As String
  
  sLang = Settings["/HelpLanguage"]
  If sLang Then Return sLang
  If bReturnVoidIfDefault Then Return
  
  sLang = System.Language
  
  For iPos = 1 To Len(sLang)
    If Not IsLower(Mid$(sLang, iPos, 1)) Then Break
  Next
  
  Return Left$(sLang, iPos - 1)
  
End

Public Sub Open()
  
  Dim sTool As String = FToolBox.GetTool()
  
  If sTool Then 
    GotoClass(CComponent.Classes[sTool].Component, sTool)
    FToolBox.SetTool
  Else
    Project.OpenWebPage(GetPath("tree/index.html"))
  Endif
  
End

Private Sub FormatName(sName As String) As String
  
  sName = LCase(sName)
  sName = Replace(sName, "_", "+")
  sName = Replace(sName, "/.", "/_")
  sName = Replace(sName, "/+", "/_")
  sName = Replace(sName, ".", "+")
  sName = Replace(sName, ":", "+")
  
  Return sName
  
End

Public Sub GotoSymbol(hSymbol As CSymbolInfo)
  
  Dim sLink As String
  Dim sName As String
  Dim sComp As String
  
  sName = LCase(hSymbol.Name)
  If Right(sName) = "$" Then sName = Left(sName, -1)
  If hSymbol.Component = "gb" And If hSymbol.Class = "." Then
    sLink = "help/lang"
  Else
    sLink = "help/comp"
    sComp = hSymbol.Component
    If sComp = "gb.qt4" Or If sComp = "gb.gtk" Or If sComp = "gb.gui" Then sComp = "gb.qt"
    sLink &= "/" & sComp
    If hSymbol.Class <> "." Then sLink &= "/" & LCase(hSymbol.Class)
  Endif
  
  sLink &/= sName '& ".html"
  'sLink = FormatName(sLink)
  
  If Exist(GetPath(FormatName(sLink)) & ".html")
    Project.OpenWebPage(GetPath(FormatName(sLink)) & ".html")
  Else
    Project.OpenWebPage("http://gambasdoc.org" &/ sLink & "?v3&" & GetLanguage())
  Endif
  
End

Public Sub GotoComponent(sComp As String)
  
  Dim sLink As String
  
  sLink = "help/comp" &/ FormatName(sComp)
  Project.OpenWebPage(GetPath(sLink) & ".html")
  FHelpBrowser.Main
  
End

Public Sub GotoClass(sComp As String, sClass As String)
  
  Dim sLink As String
  
  sLink = "help/comp" &/ FormatName(sComp) &/ FormatName(sClass)
  Project.OpenWebPage(GetPath(sLink) & ".html")
  
End

Public Function GotoKeyword(sName As String, Optional sName2 As String) As Boolean
  
  Dim sPath As String
  
  If sName2 Then
    If Not GotoKeyword(sName2) Then Return
  Endif
  
  If Right(sName) = "$" Then sName = Left$(sName, -1)
  
  sPath = GetPath("help/lang" &/ LCase(sName)) & ".html"
  If Not Exist(sPath) Then Return True
  Project.OpenWebPage(sPath)
  
Catch
  
  Return True
  
End

Public Function GotoDatatype(sName As String) As Boolean
  
  Dim sPath As String
  
  sPath = GetPath("help/lang/type" &/ LCase(sName)) & ".html"
  If Not Exist(sPath) Then Return True
  Project.OpenWebPage(sPath)
  
Catch
  
  Return True
  
End

Public Function GetSymbolHelpPath(hSymbol As CSymbolInfo) As String
  
  Dim sLink As String
  Dim sName As String
  Dim Result As String
  Dim sComp As String
  
  sName = LCase(hSymbol.Name)
  
  If hSymbol.Component = "gb" And If hSymbol.Class = "." Then
    sLink = "help/lang"
  Else
    sLink = "help/comp"
    sComp = hSymbol.Component
    If sComp = "gb.qt4" Or If sComp = "gb.gtk" Or If sComp = "gb.gui" Then sComp = "gb.qt"
    sLink &= "/" & sComp
    If hSymbol.Class <> "." Then sLink &= "/" & LCase(hSymbol.Class)
  Endif
  
  sLink &/= sName 
  sLink = FormatName(sLink)
  
  Result = GetPath(sLink) & ".html"
  
  If Not Exist(Result) Then 
    If hSymbol.Kind Then 
      'Try looking for the property in the object that this object inherits from
      hSymbol.Class = hSymbol.Kind
      hSymbol.Kind = ""
      Result = GetSymbolHelpPath(hsymbol)
      If Not Exist(Result) Then 
        'Try looking for the property in the Control object
        hSymbol.Class = "Control"
        Result = GetSymbolHelpPath(hsymbol)
      Endif   
    Endif 
  Endif 
  
  Result = LCase(Result)
  
  Return Result
  
End

Public Function GetSymbolHelpText(SymbolHelpPath As String) As String

  Dim HelpText As String
  
  'Check cache
  If Not $PopupHelpCache Then 
    'Create cache collection
    $PopupHelpCache = New Collection(gb.IgnoreCase)
  Endif 
  
  If $PopupHelpCache.Exist(SymbolHelpPath) Then 
    Return $PopupHelpCache[SymbolHelpPath]
  Else 
    'Get from file
    HelpText = GetHelpTextFromFile(SymbolHelpPath)
    If HelpText Then 
      'Add to cache
      $PopupHelpCache[SymbolHelpPath] = HelpText 
      Return HelpText 
    Else 
      Return ""
    Endif 
  Endif 
  
End

Private Function GetHelpTextFromFile(SymbolHelpPath As String) As String
  
  Dim hFileIn As File
  Dim sInputLine As String
  Dim bGrabNextLine As Boolean
  Dim sResult As String
  Dim iPos As Integer
  Dim iPos2 As Integer
  Dim sWord As String
  
  bGrabNextLine = False
  sResult = ""
  
  hFileIn = Open SymbolHelpPath For Read
  
  Do While Not Eof(hFileIn)
    Line Input #hFileIn, sInputLine
    If bGrabNextLine Then 
      
      ' Remove links
      
      Do
        iPos = InStr(sInputLine, "<a ")
        If iPos = 0 Then Break 
        iPos2 = InStr(sInputLine, ">", iPos)
        If iPos2 = 0 Then Break 
        sInputLine = Left(sInputLine, iPos - 1) & Mid$(sInputLine, iPos2 + 1)
      Loop 
      
      sInputLine = Replace(sInputLine, "</a>", "")
      
      For Each sWord In Split(Trim(sInputLine), " \n")
        sResult &= " " & sWord
        iPos = InStr(sWord, ".")
        If iPos > 0 And If iPos = Len(sWord) Then Break
      Next
      If iPos > 0 And If iPos = Len(sWord) Then Break
      
    Else 
      If Right(RTrim(sInputLine), 6) = "</pre>" Then 
        bGrabNextLine = True
      Endif 
    Endif 
  Loop 
  
  sResult = Trim(sResult)
  
Finally 
  
  Try Close hFileIn
  
  If Not sResult Then 
    Return "<i>" & ("No help found.") & "</i>"
  Else
    Return sResult 
  Endif
  
End

Public Sub GetURL(Optional sPath As String) As String
  
  Return ROOT_URL &/ sPath
  
End



Public Sub GetLangURL(sSymbol As String) As String
  
  sSymbol = LCase(sSymbol)
  sSymbol = Replace(sSymbol, "$", "")
  If Right(sSymbol) = "?" Then sSymbol = "is" & Left(sSymbol, -1)
  
  Return GetURL("lang") &/ sSymbol & "?help&v3&" & GetLanguage()
  
End

Public Sub GetSpecialURL(sSymbol As String) As String
  
  Return GetURL("lang") &/ "special" &/ Mid$(sSymbol, 2) & "?help&v3&" & GetLanguage()
  
End

'' +Description
'' Initialize a web browser view with the help on a specific symbol.
'' +Arguments
'' - #hWebView# is the WebView control to initialize.
'' - #iType# is the type of the symbol.
'' - #sSymbol# is the symbol.
'' - #sClass# is the class if the symbol is a member of this class.
'' - #sMore# is a suffix that will be added to the URL of the help page.
'' - #hEditor# is the source code editor that the symbol comes from.
'' +Symbol types
'' The #iType# argument can be one of the following constants, defined in the MHelp module:
'' - =TYPE_NATIVE= for a native datatype.
'' - =TYPE_CLASS= for a class.
'' - =TYPE_CONTROL= for a control name.
'' - =TYPE_SYMBOL= for a class symbol, a local or a global variable.
'' - =TYPE_EVENT= for an event.
'' - =TYPE_KEYWORD= for a language keyword.
'' - =TYPE_SPECIAL= for a special method.

Public Sub InitWebViewWith(hWebView As WebView, iType As Integer, sSymbol As String, Optional sClass As String, Optional sMore As String, Optional hEditor As FEditor)
  
  Dim cSymbol As Collection
  Dim hSymbol As CSymbolInfo
  Dim hClass As CClassInfo
  Dim hComp As CComponent
  Dim sUrl As String
  Dim sHtml As String
  Dim sLang As String
  Dim iPos As Integer
  Dim sTemp As String
  
  If Not hWebView Then 
    If Not FHelpBrowser.Visible Then Return
    hWebView = FHelpBrowser.webHelp
  Endif
  
  If iType = TYPE_NATIVE Then
    
    sUrl = MHelp.GetLangURL("type" &/ sSymbol)
    
  Else If iType = TYPE_KEYWORD Then
    
    sUrl = MHelp.GetLangURL(sSymbol)
    
  Else If iType = TYPE_SYMBOL Or If iType = TYPE_EVENT Then
    
    If iType = TYPE_EVENT Then
      iPos = InStr(sSymbol, "_")
      If iPos Then sSymbol = ":" & Mid$(sSymbol, iPos + 1)
    Endif
    Try hSymbol = CComponent.GetClassSymbols(sClass)[sSymbol]
    If Not hSymbol Then 
      hEditor.GetSymbolType(sSymbol)
      hSymbol = hEditor.GetLastSymbolDesc()
    Endif
    If hSymbol Then 
      If Not hSymbol.Component Or hSymbol.Component = CComponent.PROJECT_NAME Then
        sHtml = hSymbol.GetHelpHTML()
        sUrl = "-" & sClass & "-" & sSymbol
      Else If CComponent.All.Exist(hSymbol.Component) And If Not CComponent.All[hSymbol.Component].Library Then 
        sUrl = hSymbol.GetHelpURL()
      Else
        sUrl = hSymbol.Component & "-" & sClass & "-" & sSymbol
        sHtml = hSymbol.GetHelpHTML()
      Endif
    Endif
    
  Else If iType = TYPE_CLASS Or If iType = TYPE_CONTROL Then
    
    Try hClass = CComponent.Classes[sSymbol]
    If hClass Then 
      If hClass.Component And If hClass.Component <> CComponent.PROJECT_NAME Then
        sUrl = hClass.GetHelpURL()  
      Endif
    Endif
    If Not sUrl And If Project.GetClasses().Exist(sSymbol) Then
      sHtml = GetProjectClassHelpHTML(sSymbol)
      sUrl = "-" & sSymbol
    Endif
    
  Else If iType = TYPE_SPECIAL Then
    
    sUrl = MHelp.GetSpecialURL(sSymbol)
    
  Else If iType = TYPE_COMPONENT
    
    Try hComp = CComponent.All[sSymbol]
    If hComp Then sUrl = hComp.GetHelpURL()
    
  Endif
  
  hWebView.Stop
  
  If sHtml Then
    
    sTemp = File.Dir(Temp$()) &/ "help"
    Try Mkdir sTemp
    sTemp &/= sUrl & ".html"
    File.Save(sTemp, sHtml)
    hWebView.Url = "file://" & sTemp
    
  Else If sUrl Then
    
    If sMore Then sUrl &= "&" & sMore
    sMore &= "&" & GetLanguage() ' ??
    If hWebView.Url <> sUrl Then 
      'Debug sUrl
      hWebView.Url = sUrl
    Endif
    
  Else
    hWebView.HTML = "<html><body><h2>" & ("No help found.") & "</h2></body></html>"
  Endif
  hWebView.TextZoom = 0.8
  
End

'' +Description
'' Initialize the help browser with the help on a specific symbol, and show it automatically.
'' +Arguments
'' - #hWebView# is the WebView control to initialize.
'' - #iType# is the type of the symbol.
'' - #sSymbol# is the symbol.
'' - #sClass# is the class if the symbol is a member of this class.
'' - #sMore# is a suffix that will be added to the URL of the help page.
'' +Symbol types
'' The #iType# argument can be one of the following constants, defined in the MHelp module:
'' - =TYPE_NATIVE= for a native datatype.
'' - =TYPE_CLASS= for a class.
'' - =TYPE_CONTROL= for a control name.
'' - =TYPE_SYMBOL= for a class symbol, a local or a global variable.
'' - =TYPE_EVENT= for an event.
'' - =TYPE_KEYWORD= for a language keyword.
'' - =TYPE_SPECIAL= for a special method.
'' - =TYPE_COMPONENT= for a component help page.

Public Sub ShowHelpBrowserWith(hWebView As WebView, iType As Integer, sSymbol As String, Optional sClass As String, Optional sMore As String)
  
  FHelpBrowser.Show
  InitWebViewWith(hWebView, iType, sSymbol, sClass, sMore)
  
End

Private Sub SubstPart(sHtml As String, sPart As String, bShow As Boolean) As String
  
  If bShow Then
    sHtml = Replace(sHtml, sPart & "[", "")
    sHtml = Replace(sHtml, sPart & "]", "")
  Else
    sHtml = Replace(sHtml, sPart & "[", "<!--")
    sHtml = Replace(sHtml, sPart & "]", "-->")
  Endif
  
  Return sHtml
  
End


'' +Description
'' Return the formated help of the local class if it exist
'' +Arguments
'' - #sClass# is the class to analyze
'' - #hWebView# is the WebView control to use.

Public Function GetProjectClassHelpHTML(sClass As String, Optional hWebView As WebView) As String
  
  Dim sHelp, sHtml, sLine, sWhere, sSymbols, sParSymbols, sInfo, sInherit As String
  Dim hForm As FEditor
  Dim hEdit As Editor
  Dim i As Integer
  Dim hSymbol As CSymbolInfo
  Dim cClassSymbols As Collection
  Dim hClassInfo, hParentClass As CClassInfo
  Dim aProperty, aEvent, aMethod, aConst, aVar As New String[]
  Dim aParentProperty, aParentEvent, aParentMethod, aParentConst, aParentVar As New String[]
  Dim sComp, sSymbolName As String
  Dim hArray As String[]
  Dim sLink As String
  Dim sParent As String

  'Getting help
  hForm = Project.LoadFile(Project.FindPath(sClass))
  
  Try hEdit = hForm.Editor
  
  If Not hEdit Then Return  
  
  For i = 0 To hEdit.Lines.Count - 1
    sLine = Trim(hEdit.Lines[i].Text)
    If sLine Begins "''" Then
      sHelp &= Trim(Mid(sLine, 3)) & "<br>"
    Else
      If sLine Begins "'" Then Continue
      If Not sLine And If Not sHelp Then Continue
      Break
    Endif
  Next
  
  While sHelp Ends "<br>"
    sHelp = Trim(Left(sHelp, -4))
  Wend
  
  hClassInfo = CComponent.GetClassDescription(sClass)
  cClassSymbols = CComponent.GetClassSymbols(sClass)
  
  'If hClassInfo.Name = sClass Then hClassInfo.Name = hClassInfo.Parent ????? Do not modify the class info!
  
  If cClassSymbols.Count > 0 Then
    
    For Each hSymbol In cClassSymbols
      
      sSymbolName = hSymbol.Name
      If Left(sSymbolName) = ":" Then sSymbolName = Mid$(sSymbolName, 2)
      
      sComp = Subst("<a class=\"none\" href=\"&1\">&2</a>", Html(hSymbol.GetHelpURL()), sSymbolName)
      
      If hSymbol.NotPublic Or If hSymbol.IsHidden() Then Continue

      If IsLetter(hSymbol.Kind) And If hSymbol.Kind = UCase(hSymbol.Kind) Then sComp = "<b>" & sComp & "</b>"

      If hSymbol.Class = sClass Then
        
        Select Case LCase(hSymbol.Kind)
          Case ":" 
            aEvent.Add(sComp)
          Case "m"
            aMethod.Add(sComp)
          Case "p", "r"
            aProperty.Add(sComp)
          Case "c"
            aConst.Add(sComp)
          Case "v"
            aVar.Add(sComp)
        End Select
        
      Else
        
        Select Case LCase(hSymbol.Kind)
          Case ":" 
            aParentEvent.Add(sComp)
          Case "m"
            aParentMethod.Add(sComp)
          Case "p", "r"
            aParentProperty.Add(sComp)
          Case "c"
            aParentConst.Add(sComp)
          Case "v"
            aParentVar.Add(sComp)
        End Select
        
      Endif
      
    Next
    
    For Each hArray In [aConst, aEvent, aMethod, aProperty, aVar, aParentConst, aParentEvent, aParentMethod, aParentProperty, aParentVar]
      hArray.Sort
    Next
    
    sParSymbols = ""
    If aParentProperty.Count + aParentMethod.Count + aParentEvent.Count + aParentVar.Count Then
      sParSymbols &= "<tr>"
      If aParentProperty.Count Then sParSymbols &= "<td><b>" & ("Properties") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aParentVar.Count Then sParSymbols &= "<td><b>" & ("Variables") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aParentMethod.Count Then sParSymbols &= "<td><b>" & ("Methods") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aParentEvent.Count Then sParSymbols &= "<td><b>" & ("Events") & "</b></td><td width=\"32\">&nbsp;</td>"
      sParSymbols &= "</tr>"
      sParSymbols &= "<tr valign=\"top\">"
      If aParentProperty.Count Then sParSymbols &= "<td>" & aParentProperty.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aParentVar.Count Then sParSymbols &= "<td>" & aParentVar.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aParentMethod.Count Then sParSymbols &= "<td>" & aParentMethod.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aParentEvent.Count Then sParSymbols &= "<td>" & aParentEvent.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      sParSymbols &= "</tr>"
    Endif
    
    sSymbols = ""
    If aProperty.Count + aMethod.Count + aEvent.Count + aVar.Count Then
      sSymbols &= "<tr>"
      If aProperty.Count Then sSymbols &= "<td><b>" & ("Properties") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aVar.Count Then sSymbols &= "<td><b>" & ("Variables") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aMethod.Count Then sSymbols &= "<td><b>" & ("Methods") & "</b></td><td width=\"32\">&nbsp;</td>"
      If aEvent.Count Then sSymbols &= "<td><b>" & ("Events") & "</b></td><td width=\"32\">&nbsp;</td>"
      sSymbols &= "</tr>"
      sSymbols &= "<tr valign=\"top\">"
      If aProperty.Count Then sSymbols &= "<td>" & aProperty.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aVar.Count Then sSymbols &= "<td>" & aVar.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aMethod.Count Then sSymbols &= "<td>" & aMethod.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      If aEvent.Count Then sSymbols &= "<td>" & aEvent.Join(" ") & "</td><td width=\"32\">&nbsp;</td>"
      sSymbols &= "</tr>"
    Endif
    
  Endif
  
  If hClassInfo.AutoCreatable Then sInfo = ("This class can be used like an object by creating an hidden instance on demand.<br>")
  If hClassInfo.Creatable Then sInfo &= ("This class is creatable.<br>")
  
  sWhere = "gambas://project/" & sClass & "?showfile"
  
  sHtml = File.Load("help/class-help.html")
  sHtml = Replace(sHtml, "$(class)", sClass)
  sHtml = Replace(sHtml, "$(help)", sHelp)
  
  If sInfo Then 
    sHtml = Replace(sHtml, "<!--$(Info)-->", sInfo & "<hr class=\"border\">")
  Endif
  
  If hClassInfo.Parent Then 
    
    sParent = hClassInfo.Parent
    
    hParentClass = CComponent.Classes[hClassInfo.ParentComponent &/ sParent]
    If Not hParentClass Then hParentClass = CComponent.GetClassDescription(sParent)
    
    sHtml = SubstPart(sHtml, "ShowInherits", True)
    sHtml = SubstPart(sHtml, "ShowParConst", aParentConst.Count > 0)
    sHtml = Replace(sHtml, "$(ParConst)", aParentConst.Join(" "))
    
    sHtml = Replace(sHtml, "$(Inherits)", Subst(("This class inherits &1."), Subst("<a href=\"&1\">&2</a>", Html(hParentClass.GetHelpURL()), sParent)))
    sHtml = Replace(sHtml, "$(ParSymbols)", sParSymbols)
    
  Else
    
    sHtml = SubstPart(sHtml, "ShowInherits", False)
    
  Endif
  
  sHtml = SubstPart(sHtml, "ShowConst", aConst.Count > 0)
  sHtml = Replace(sHtml, "$(Const)", aConst.Join(" "))
  
  sHtml = Replace(sHtml, "$(where)", sWhere)
  sHtml = Replace(sHtml, "$(Symbols)", sSymbols)
  
  sHtml = Replace(sHtml, "''Symbols''", ("Symbols"))
  sHtml = Replace(sHtml, "''Constants''", ("Constants"))
  
  sHtml = Replace(sHtml, "$(hide-title)", "")
  
  Return sHtml

End

'' Manage 'the gambas://' links

Public Sub ManageSpecialLink(hWebView As WebView, sUrl As String)
  
  Dim sClass As String
  Dim sSymbol As String
  Dim sComp As String 
  Dim iLine As Integer
  Dim iPos As Integer
  Dim aValues As String[]
  Dim bShowFile As Boolean
  Dim sLast As String
  
  If InStr(sUrl, "?showfile") Then
    sUrl = Replace(sUrl, "?showfile", "")
    bShowFile = True
  Endif
  
  aValues = Split(sUrl, "/")
  sClass = aValues[3]
  
  If sUrl Begins "gambas://project/" Then 
    
    sLast = aValues[aValues.Max]
    iPos = InStr(sLast, "#")
    If iPos Then
      Try iLine = CInt(Mid$(sLast, iPos + 1))
      aValues[aValues.Max] = Left$(sLast, iPos - 1)
      sClass = aValues[3]
    Endif
    If bShowFile Then 
      Project.OpenFile(Project.FindPath(sClass), iLine)
      FMain.Show
    Else
      If aValues.Count = 4 Then
        InitWebViewWith(hWebView, TYPE_CLASS, aValues[3])
      Else
        InitWebViewWith(hWebView, TYPE_SYMBOL, aValues[4])
      Endif
    Endif 
    
  Else
    
    sSymbol = aValues[3]
    sClass = File.Name(File.Dir(sUrl))
    InitWebViewWith(hWebView, TYPE_SYMBOL, sSymbol, sClass)
    
  Endif 
  
End

Public Sub Clear()
  
  Try Shell "rm -rf " & Shell$(File.Dir(Temp$()) &/ "help")
  
End

Public Sub LoadProxyConfig()
  
  With WebSettings.Proxy
    
    Select Case Settings["/Proxy/Type", 0]
      Case 0
        .Type = WebSettings.DefaultProxy
        Return
      Case 1
        .Type = WebSettings.NoProxy
        Return
      Case 2
        .Type = WebSettings.HttpProxy
      Case 3
        .Type = WebSettings.Socks5Proxy
    End Select
    
    .Host = Settings["/Proxy/Host"]
    .Port = Settings["/Proxy/Port", 0]
    .User = Settings["/Proxy/User"]
    If .User Then .Password = Desktop.Passwords["/Proxy" &/ .User]
    
  End With
  
End


