aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/uncutil.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-09-03 11:22:38 -0700
committerRob Mensching <rob@firegiant.com>2017-09-03 13:33:33 -0700
commit5d8375007754101ff2889d0e79486c8f9b7cf5ab (patch)
treea76d6fb6a38dd9f04a93ffcfd9d64e76779b3414 /src/dutil/uncutil.cpp
parent8e8da6dbc051ec884b5d439bb4f44dc027d05bbf (diff)
downloadwix-5d8375007754101ff2889d0e79486c8f9b7cf5ab.tar.gz
wix-5d8375007754101ff2889d0e79486c8f9b7cf5ab.tar.bz2
wix-5d8375007754101ff2889d0e79486c8f9b7cf5ab.zip
Initial commit
Diffstat (limited to 'src/dutil/uncutil.cpp')
-rw-r--r--src/dutil/uncutil.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/dutil/uncutil.cpp b/src/dutil/uncutil.cpp
new file mode 100644
index 00000000..6deb43bd
--- /dev/null
+++ b/src/dutil/uncutil.cpp
@@ -0,0 +1,54 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5DAPI_(HRESULT) UncConvertFromMountedDrive(
6 __inout LPWSTR *psczUNCPath,
7 __in LPCWSTR sczMountedDrivePath
8 )
9{
10 HRESULT hr = S_OK;
11 DWORD dwLength = 0;
12 DWORD er = ERROR_SUCCESS;
13 LPWSTR sczDrive = NULL;
14
15 // Only copy drive letter and colon
16 hr = StrAllocString(&sczDrive, sczMountedDrivePath, 2);
17 ExitOnFailure(hr, "Failed to copy drive");
18
19 // ERROR_NOT_CONNECTED means it's not a mapped drive
20 er = ::WNetGetConnectionW(sczDrive, NULL, &dwLength);
21 if (ERROR_MORE_DATA == er)
22 {
23 er = ERROR_SUCCESS;
24
25 hr = StrAlloc(psczUNCPath, dwLength);
26 ExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength);
27
28 er = ::WNetGetConnectionW(sczDrive, *psczUNCPath, &dwLength);
29 if (ERROR_CONNECTION_UNAVAIL == er)
30 {
31 // This means the drive is remembered but not currently connected, this can mean the location is accessible via UNC path but not via mounted drive path
32 er = ERROR_SUCCESS;
33 }
34 ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive);
35
36 // Skip drive letter and colon
37 hr = StrAllocConcat(psczUNCPath, sczMountedDrivePath + 2, 0);
38 ExitOnFailure(hr, "Failed to copy rest of database path");
39 }
40 else
41 {
42 if (ERROR_SUCCESS == er)
43 {
44 er = ERROR_NO_DATA;
45 }
46
47 ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive);
48 }
49
50LExit:
51 ReleaseStr(sczDrive);
52
53 return hr;
54}