[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: TortoiseProc crash

From: Kapl Roland <rkapl_at_oebfa.co.at>
Date: 2007-03-05 16:01:45 CET

Hi!

OK, I now worked around the path problem (F: actually maps to
\\OEBFASRV01\public) by calling GetUncFullPathFromMappedDrive from the
approach below:

Might that be something to be considered integrating into TortoiseSVN in
the future?

Sorry I didn't reply directly to your answer, I just didn't get any mail
from the mailing list. Anything I'm missing here?

-regards & thanks,
Roland

>>>BEGIN Recipe from
http://vbnet.mvps.org/code/network/uncfrommappeddrive.htm
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_PATH As Long = 260

Private Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" _
                                           (ByVal lpszLocalName As
String, _
                                            ByVal lpszRemoteName As
String, _
                                            cbRemoteName As Long) As
Long

Private Declare Function PathIsNetworkPath Lib "shlwapi.dll" Alias
"PathIsNetworkPathA" _
                                           (ByVal pszPath As String) As
Long

Private Declare Function PathIsUNC Lib "shlwapi.dll" Alias "PathIsUNCA"
_
                                   (ByVal pszPath As String) As Long

Private Declare Function PathStripToRoot Lib "shlwapi.dll" Alias
"PathStripToRootA" _
                                         (ByVal pPath As String) As Long

Private Declare Function PathSkipRoot Lib "shlwapi.dll" Alias
"PathSkipRootA" _
                                      (ByVal pPath As String) As Long

Private Declare Function lstrlenW Lib "kernel32" _
                                  (ByVal lpString As Long) As Long

Private Declare Function lstrcpyA Lib "kernel32" _
                                  (ByVal RetVal As String, ByVal Ptr As
Long) As Long

Private Declare Function lstrlenA Lib "kernel32" _
                                  (ByVal Ptr As Any) As Long

Public Function GetUncFullPathFromMappedDrive(sLocalName As String) As
String
Dim sLocalRoot As String
Dim sRemoteName As String
Dim cbRemoteName As Long

  sRemoteName = Space$(MAX_PATH)
  cbRemoteName = Len(sRemoteName)
  'get the drive letter
  sRemotePath = StripRootFromPath(sLocalName)
  sLocalRoot = StripPathToRoot(sLocalName)
  'if drive letter is a network share,
  'resolve the share UNC name
  If IsPathNetPath(sLocalRoot) Then
    If WNetGetConnection(sLocalRoot, _
                         sRemoteName, _
                         cbRemoteName) = ERROR_SUCCESS Then

      'this assures the retrieved name is in
      'fact a valid UNC path.
      sRemoteName = QualifyPath(TrimNull(sRemoteName)) & sRemotePath

      If IsUNCPathValid(sRemoteName) Then
        GetUncFullPathFromMappedDrive = TrimNull(sRemoteName)
      End If
    End If
  End If
End Function

Private Function QualifyPath(spath As String) As String
'add trailing slash if required
  If Right$(spath, 1) <> "\" Then
    QualifyPath = spath & "\"
  Else
    QualifyPath = spath
  End If
End Function

Public Function IsPathNetPath(ByVal spath As String) As Boolean
'Determines whether a path represents network resource.
  IsPathNetPath = PathIsNetworkPath(spath) = 1
End Function

Private Function IsUNCPathValid(ByVal spath As String) As Boolean
'Determines if string is a valid UNC
  IsUNCPathValid = PathIsUNC(spath) = 1
End Function

Private Function StripPathToRoot(ByVal spath As String) As String
'Removes all of the path except for
'the root information (ie drive. Also
'removes any trailing slash.
Dim pos As Integer
  Call PathStripToRoot(spath)
  pos = InStr(spath, Chr$(0))
  If pos Then
    StripPathToRoot = Left$(spath, pos - 2)
  Else
    StripPathToRoot = spath
  End If
End Function

Private Function TrimNull(startstr As String) As String
  TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
End Function

Private Function StripRootFromPath(ByVal spath As String) As String
'Parses a path, ignoring the drive
'letter or UNC server/share path parts
  StripRootFromPath = TrimNull(GetStrFromPtrA(PathSkipRoot(spath)))
End Function

Private Function GetStrFromPtrA(ByVal lpszA As Long) As String
'Given a pointer to a string, return the string
  GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
  Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function

>>>END Recipe from
http://vbnet.mvps.org/code/network/uncfrommappeddrive.htm

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Mon Mar 5 16:11:44 2007

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.