aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/uncutil.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-04-22 06:38:23 -0700
committerRob Mensching <rob@firegiant.com>2021-04-29 16:21:09 -0700
commit7f642e51670bc38a4ef782a363936850bc2b0ba9 (patch)
tree19684b2d94979f130c0935328f0d44cf006e45ef /src/libs/dutil/WixToolset.DUtil/uncutil.cpp
parentf39e7a3e164d0736e45049e5726d0da2013da3c9 (diff)
downloadwix-7f642e51670bc38a4ef782a363936850bc2b0ba9.tar.gz
wix-7f642e51670bc38a4ef782a363936850bc2b0ba9.tar.bz2
wix-7f642e51670bc38a4ef782a363936850bc2b0ba9.zip
Move dutil into libs/dutil
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/uncutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/uncutil.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/uncutil.cpp b/src/libs/dutil/WixToolset.DUtil/uncutil.cpp
new file mode 100644
index 00000000..415ea198
--- /dev/null
+++ b/src/libs/dutil/WixToolset.DUtil/uncutil.cpp
@@ -0,0 +1,69 @@
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
5
6// Exit macros
7#define UncExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
8#define UncExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
9#define UncExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
10#define UncExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
11#define UncExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
12#define UncExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
13#define UncExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__)
14#define UncExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__)
15#define UncExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__)
16#define UncExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__)
17#define UncExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_UNCUTIL, e, x, s, __VA_ARGS__)
18#define UncExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_UNCUTIL, g, x, s, __VA_ARGS__)
19
20DAPI_(HRESULT) UncConvertFromMountedDrive(
21 __inout LPWSTR *psczUNCPath,
22 __in LPCWSTR sczMountedDrivePath
23 )
24{
25 HRESULT hr = S_OK;
26 DWORD dwLength = 0;
27 DWORD er = ERROR_SUCCESS;
28 LPWSTR sczDrive = NULL;
29
30 // Only copy drive letter and colon
31 hr = StrAllocString(&sczDrive, sczMountedDrivePath, 2);
32 UncExitOnFailure(hr, "Failed to copy drive");
33
34 // ERROR_NOT_CONNECTED means it's not a mapped drive
35 er = ::WNetGetConnectionW(sczDrive, NULL, &dwLength);
36 if (ERROR_MORE_DATA == er)
37 {
38 er = ERROR_SUCCESS;
39
40 hr = StrAlloc(psczUNCPath, dwLength);
41 UncExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength);
42
43 er = ::WNetGetConnectionW(sczDrive, *psczUNCPath, &dwLength);
44 if (ERROR_CONNECTION_UNAVAIL == er)
45 {
46 // 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
47 er = ERROR_SUCCESS;
48 }
49 UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive);
50
51 // Skip drive letter and colon
52 hr = StrAllocConcat(psczUNCPath, sczMountedDrivePath + 2, 0);
53 UncExitOnFailure(hr, "Failed to copy rest of database path");
54 }
55 else
56 {
57 if (ERROR_SUCCESS == er)
58 {
59 er = ERROR_NO_DATA;
60 }
61
62 UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive);
63 }
64
65LExit:
66 ReleaseStr(sczDrive);
67
68 return hr;
69}