Imports System
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing
Public Class MainClass
Shared Sub Main()
Dim Favorites As Favorites = New Favorites()
Favorites.ScanFavorites()
Dim f As WebFavorite
For Each f in Favorites.Favorites
Console.WriteLine(f.Name)
Next
End Sub
End Class
Public Class Favorites
Public Favorites As WebFavoriteCollection
Public ReadOnly Property FavoritesFolder() As String
Get
Return _
Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
End Get
End Property
Public Sub ScanFavorites()
ScanFavorites(FavoritesFolder)
End Sub
Public Sub ScanFavorites(ByVal folderName As String)
If Favorites Is Nothing Then Favorites = New _
WebFavoriteCollection()
Dim scanFolder As New DirectoryInfo(folderName)
Dim favoriteFile As FileInfo
For Each favoriteFile In scanFolder.GetFiles
If String.Compare(favoriteFile.Extension, ".url", True) = 0 Then
Dim favorite As New WebFavorite()
favorite.Load(favoriteFile)
Favorites.Add(favorite)
End If
Next
End Sub
End Class
Public Class WebFavoriteCollection
Inherits CollectionBase
Public Sub Add(ByVal favorite As WebFavorite)
List.Add(favorite)
End Sub
Public Sub Remove(ByVal index As Integer)
If index >= 0 And index < Count Then
List.Remove(index)
End If
End Sub
Public ReadOnly Property Item(ByVal index As Integer) _
As WebFavorite
Get
Return CType(List.Item(index), WebFavorite)
End Get
End Property
End Class
Public Class WebFavorite
Public Name As String
Public Url As String
Public Sub Open()
System.Diagnostics.Process.Start(Url)
End Sub
Public Sub Load(ByVal fileInfo As FileInfo)
Name = fileInfo.Name.Substring(0, _
fileInfo.Name.Length - fileInfo.Extension.Length)
Dim stream As New FileStream(fileInfo.FullName, FileMode.Open)
Dim reader As New StreamReader(stream)
Do While True
Dim buf As String = reader.ReadLine
If buf Is Nothing Then Exit Do
If buf.StartsWith("URL=") Then
Url = buf.Substring(4)
Exit Do
End If
Loop
reader.Close()
stream.Close()
End Sub
End Class
|