﻿' Present Web Browser Favourites in Dropdown on Local Web Server MyFavourites.html

Imports System
Imports System.IO

Module Module1

    Sub Main()
        Dim ourpath As String = Environment.GetEnvironmentVariable("PATH")
        Dim iplace As Integer = ourpath.ToLower().IndexOf("easyphp")
        Dim jplace As Integer
        Dim localrootdir As String = ""
        Dim localrootfile As String = ""
        If iplace > 0 Then
            jplace = iplace
            While (jplace < ourpath.Length And ourpath.Substring(jplace, 1) <> "\" And ourpath.Substring(jplace, 1) <> ";")
                localrootdir = localrootdir + ourpath.Substring(jplace, 1)
                jplace = jplace + 1
            End While
            jplace = iplace - 1
            While (jplace > 0 And ourpath.Substring(jplace, 1) <> ";")
                localrootdir = ourpath.Substring(jplace, 1) + localrootdir
                jplace = jplace - 1
            End While
            localrootdir = localrootdir + "\www\"
            Dim fplace As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
            Dim ourdi As DirectoryInfo = New DirectoryInfo(fplace + "\")
            Dim ourfls() As FileInfo = ourdi.GetFiles("*.url", SearchOption.AllDirectories)
            Dim ourfl As FileInfo
            Dim baseurl As String = ""
            Dim cnt As Integer = 0
            For Each ourfl In ourfls
                If localrootfile.Length = 0 Then
                    localrootfile = "MyFavourites.html"
                    System.IO.File.WriteAllText(localrootdir + localrootfile, "<html><head><title>Your Favourites</title><body><h1>Your Favourites</h1><select id='favourites'>")
                End If
                cnt = cnt + 1
                Try
                    ' Create new StreamReader instance with Using block.
                    Using reader As StreamReader = New StreamReader(ourfl.FullName)
                        ' Read one line from file
                        baseurl = "[DEFAULT]"
                        While baseurl.IndexOf("ASEURL=") <= 0
                            baseurl = reader.ReadLine
                        End While
                    End Using
                Catch ex As Exception
                    baseurl = "BASEURL=http://127.0.0.1/" + localrootfile
                End Try
                System.IO.File.AppendAllText(localrootdir + localrootfile, "<option id='f" + cnt.ToString() + "' onclick='window.open(" + Chr(34) + baseurl.Replace("BASEURL=", "") + Chr(34) + "," + Chr(34) + "_blank" + Chr(34) + ");' value='" + ourfl.Name.Replace(".url", "") + "'>" + ourfl.Name.Replace(".url", "") + "</option>")
            Next
            If localrootfile.Length > 0 Then
                System.IO.File.AppendAllText(localrootdir + localrootfile, "</select</body></html>")
                Try
                    Shell(localrootdir + localrootfile, AppWinStyle.NormalFocus, False, -1)
                Catch ex As Exception
                    Process.Start("IExplore.exe", "http://127.0.0.1/" + localrootfile)
                End Try
            End If
        End If
    End Sub

End Module
