Namespace Gww Namespace Vss Namespace CommonLibrary Public Class VssReader #Region " Global Constants " Private Const C_VSSPROJECT As Int16 = 0 Private Const C_VSSFILE As Int16 = 1 #End Region #Region " Declarations " Dim m_Username As String Dim m_Password As String Dim m_SrcSafeIni As String Dim m_ProjectPath As String Dim m_LocalPath As String Dim m_Label As String Dim m_FileDownload As Boolean Dim m_IsRecursive As Boolean Dim m_FileColl As New Collection Dim m_Status As Boolean Dim m_SubFolder As String Dim m_VssDatabase As SourceSafeTypeLib.IVSSDatabase #End Region #Region " Exposed Properties " Public Property IsRecursive() As Boolean Get IsRecursive = m_IsRecursive End Get Set(ByVal value As Boolean) m_IsRecursive = value End Set End Property Public Property FileDownload() As Boolean Get FileDownload = m_FileDownload End Get Set(ByVal value As Boolean) m_FileDownload = value End Set End Property Public Property Status() As Boolean Get Status = m_Status End Get Set(ByVal Value As Boolean) m_Status = Value End Set End Property Public Property Username() As String Get Return m_Username End Get Set(ByVal Value As String) m_Username = Value End Set End Property Public Property Password() As String Get Return m_Password End Get Set(ByVal Value As String) m_Password = Value End Set End Property Public Property SrcSafeIni() As String Get SrcSafeIni = m_SrcSafeIni End Get Set(ByVal Value As String) m_SrcSafeIni = Value End Set End Property Public Property ProjectPath() As String Get ProjectPath = m_ProjectPath End Get Set(ByVal Value As String) m_ProjectPath = Value End Set End Property Public Property LocalPath() As String Get LocalPath = m_LocalPath End Get Set(ByVal Value As String) m_LocalPath = Value End Set End Property Public Property Label() As String Get Label = m_Label End Get Set(ByVal value As String) m_Label = value End Set End Property Public ReadOnly Property FileColl() As Collection Get FileColl = m_FileColl End Get End Property #End Region #Region " Exposed Methods " Public Function connect() As Boolean ' // Connect to the Visual SourceSafe Database Status = True m_VssDatabase = New SourceSafeTypeLib.VSSDatabase Try m_VssDatabase.Open(m_SrcSafeIni, m_Username, m_Password) Catch eX As Exception Status = False Return eX.Message End Try Return Status End Function Public Function disconnect() As Boolean ' // There is no method in VSS 6.0 for closing an open connection, but this is one way to do it! ' // Ref: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=123307&SiteID=1 m_VssDatabase = New SourceSafeTypeLib.VSSDatabase() Try m_VssDatabase.Open("..", "", "") Catch ex As Exception End Try Return True End Function Public Function getLatest() As Boolean ' // This is the primary method to call to retrieve items from VSS Try If Not (m_VssDatabase Is System.DBNull.Value) Then ' // This first item would be a project Dim vItem As SourceSafeTypeLib.IVSSItem = m_VssDatabase.VSSItem(m_ProjectPath, False) getItems(vItem, LocalPath) End If Catch ex As Exception Return False End Try Return True End Function #End Region #Region " Private Methods " Private Sub getItems(ByVal pItem As SourceSafeTypeLib.IVSSItem, ByVal pProjectPath As String) ' // The bulk of the work in finding and retrieving the items are performed here! Dim vItems As SourceSafeTypeLib.IVSSItems Dim vItem As SourceSafeTypeLib.IVSSItem Dim vFilePath As String ' // Not Implementing Recursion, therefore only interested in file items If pItem.Type = C_VSSPROJECT Then ' // Create folder if not ' // Only interested in active (non-deleted) file items vItems = pItem.Items(False) ' // Process all items For Each vItem In vItems If vItem.Type = C_VSSFILE Then If getLabelledItem(vItem) > -1 Then vFilePath = pProjectPath + vItem.Name ' // Useful for testing purposes If FileDownload Then vItem.Get(vFilePath, False) End If ' // Store downloaded files to a collection m_FileColl.Add(vFilePath, vItem.Name) getItems(vItem, pProjectPath) End If ElseIf m_IsRecursive Then Dim vNewProjectPath As String ' // create the sub folder path if it does not exist vNewProjectPath = pProjectPath + vItem.Name + "\" If Not System.IO.Directory.Exists(vNewProjectPath) Then System.IO.Directory.CreateDirectory(vNewProjectPath) End If ' // start all over again if recursion is enabled getItems(vItem, vNewProjectPath) End If Next End If End Sub Private Function getLabelledItem(ByRef pItem As SourceSafeTypeLib.IVSSItem) As Integer ' // To determine the label of a VSS item, it is necessary to loop ' // through the versions collection for that item Dim vVersions As SourceSafeTypeLib.IVSSVersions = pItem.Versions(0) Dim vVersion As SourceSafeTypeLib.IVSSVersion Dim VerLabel As String For Each vVersion In vVersions VerLabel = vVersion.Label If (VerLabel = m_Label) Then pItem = vVersion.VSSItem Return vVersion.VersionNumber End If Next Return -1 End Function #End Region End Class End Namespace End Namespace End Namespace