aboutsummaryrefslogtreecommitdiff
path: root/src/ca/DriveCheck.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2019-01-12 11:11:10 -0600
committerSean Hall <r.sean.hall@gmail.com>2019-01-12 11:11:10 -0600
commit9d5d059a2147aa0fe38f7103148c020b66455e83 (patch)
tree7673cb14721cf21df43fdfc1c0bcad572817fecc /src/ca/DriveCheck.cpp
parentde844c32ea0afe45a2deb1b25e6bdd267b7df103 (diff)
downloadwix-9d5d059a2147aa0fe38f7103148c020b66455e83.tar.gz
wix-9d5d059a2147aa0fe38f7103148c020b66455e83.tar.bz2
wix-9d5d059a2147aa0fe38f7103148c020b66455e83.zip
Import code from old v4 repo
Diffstat (limited to 'src/ca/DriveCheck.cpp')
-rw-r--r--src/ca/DriveCheck.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/ca/DriveCheck.cpp b/src/ca/DriveCheck.cpp
new file mode 100644
index 00000000..fafd73c2
--- /dev/null
+++ b/src/ca/DriveCheck.cpp
@@ -0,0 +1,126 @@
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
5static HRESULT PathIsRemote(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRemote);
6static HRESULT PathIsRemovable(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRemovable);
7
8/********************************************************************
9 ValidatePath - Custom Action entry point
10
11********************************************************************/
12UINT __stdcall ValidatePath(MSIHANDLE hInstall)
13{
14 HRESULT hr = S_OK;
15
16 LPWSTR pwszWixUIDir = NULL;
17 LPWSTR pwszInstallPath = NULL;
18 BOOL fInstallPathIsRemote = TRUE;
19 BOOL fInstallPathIsRemoveable = TRUE;
20
21 hr = WcaInitialize(hInstall, "ValidatePath");
22 ExitOnFailure(hr, "failed to initialize");
23
24 hr = WcaGetProperty(L"WIXUI_INSTALLDIR", &pwszWixUIDir);
25 ExitOnFailure(hr, "failed to get WixUI Installation Directory");
26
27 hr = WcaGetProperty(pwszWixUIDir, &pwszInstallPath);
28 ExitOnFailure(hr, "failed to get Installation Directory");
29
30 hr = PathIsRemote(pwszInstallPath, &fInstallPathIsRemote);
31 if (FAILED(hr))
32 {
33 TraceError(hr, "Unable to determine if path is remote");
34 //reset HR, as we need to continue and find out if is a UNC path
35 hr = S_OK;
36 }
37
38 hr = PathIsRemovable(pwszInstallPath, &fInstallPathIsRemoveable);
39 if (FAILED(hr))
40 {
41 TraceError(hr, "Unable to determine if path is removable");
42 //reset HR, as we need to continue and find out if is a UNC path
43 hr = S_OK;
44 }
45
46 // If the path does not point to a network drive, mapped drive, or removable drive,
47 // then set WIXUI_INSTALLDIR_VALID to "1" otherwise set it to 0
48 BOOL fInstallPathIsUnc = PathIsUNCW(pwszInstallPath);
49 if (!fInstallPathIsUnc && !fInstallPathIsRemote && !fInstallPathIsRemoveable)
50 {
51 // path is valid
52 hr = WcaSetProperty(L"WIXUI_INSTALLDIR_VALID", L"1");
53 ExitOnFailure(hr, "failed to set WIXUI_INSTALLDIR_VALID");
54 }
55 else
56 {
57 // path is invalid; we can't log it because we're being called from a DoAction control event
58 // but we can at least call WcaLog to get it to write to the debugger from a debug build
59 WcaLog(LOGMSG_STANDARD, "Installation path %ls is invalid: it is %s UNC path, %s remote path, or %s path on a removable drive, and must be none of these.",
60 pwszInstallPath, fInstallPathIsUnc ? "a" : "not a", fInstallPathIsRemote ? "a" : "not a", fInstallPathIsRemoveable ? "a" : "not a");
61 hr = WcaSetProperty(L"WIXUI_INSTALLDIR_VALID", L"0");
62 ExitOnFailure(hr, "failed to set WIXUI_INSTALLDIR_VALID");
63 }
64
65LExit:
66 ReleaseStr(pwszInstallPath);
67 ReleaseStr(pwszWixUIDir);
68
69 return WcaFinalize(SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE);
70}
71
72/********************************************************************
73 PathIsRemote - helper function for ValidatePath
74
75********************************************************************/
76static HRESULT PathIsRemote(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRemote)
77{
78 HRESULT hr = S_OK;
79 LPWSTR pStrippedTargetFolder = NULL;
80
81 hr = StrAllocString(&pStrippedTargetFolder, pTargetFolder, 0);
82
83 // Terminate the path at the root
84 if(!::PathStripToRootW(pStrippedTargetFolder))
85 {
86 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE);
87 ExitOnFailure(hr, "failed to parse target folder");
88 }
89
90 UINT uResult = GetDriveTypeW(pStrippedTargetFolder);
91
92 *fPathRemote = (DRIVE_REMOTE == uResult) ;
93
94LExit:
95 ReleaseStr(pStrippedTargetFolder);
96
97 return hr;
98}
99
100/********************************************************************
101 PathIsRemovable - helper function for ValidatePath
102
103********************************************************************/
104static HRESULT PathIsRemovable(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRemovable)
105{
106 HRESULT hr = S_OK;
107 LPWSTR pStrippedTargetFolder = NULL;
108
109 hr = StrAllocString(&pStrippedTargetFolder, pTargetFolder, 0);
110
111 // Terminate the path at the root
112 if(!::PathStripToRootW(pStrippedTargetFolder))
113 {
114 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE);
115 ExitOnFailure(hr, "failed to parse target folder");
116 }
117
118 UINT uResult = GetDriveTypeW(pStrippedTargetFolder);
119
120 *fPathRemovable = ((DRIVE_CDROM == uResult) || (DRIVE_REMOVABLE == uResult) || (DRIVE_RAMDISK == uResult) || (DRIVE_UNKNOWN == uResult));
121
122LExit:
123 ReleaseStr(pStrippedTargetFolder);
124
125 return hr;
126}