author | herrick |
Fri, 08 Nov 2019 14:53:03 -0500 | |
branch | JDK-8200758-branch |
changeset 58994 | b09ba68c6a19 |
parent 58887 | src/jdk.jpackage/windows/native/libwixhelper/libwixhelper.cpp@920f6770d71c |
permissions | -rw-r--r-- |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
1 |
/* |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
4 |
* |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
10 |
* |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
16 |
* |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
20 |
* |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
23 |
* questions. |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
24 |
*/ |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
25 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
26 |
#include <Windows.h> |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
27 |
#include <msiquery.h> |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
28 |
#include <shlwapi.h> |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
29 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
30 |
extern "C" { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
31 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
32 |
#ifdef JP_EXPORT_FUNCTION |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
33 |
#error Unexpected JP_EXPORT_FUNCTION define |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
34 |
#endif |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
35 |
#define JP_EXPORT_FUNCTION comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__) |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
36 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
37 |
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
38 |
LPVOID lpvReserved) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
39 |
return TRUE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
40 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
41 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
42 |
BOOL DirectoryExist(TCHAR *szValue) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
43 |
DWORD attr = GetFileAttributes(szValue); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
44 |
if (attr == INVALID_FILE_ATTRIBUTES) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
45 |
return FALSE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
46 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
47 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
48 |
if (attr & FILE_ATTRIBUTE_DIRECTORY) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
49 |
return TRUE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
50 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
51 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
52 |
return FALSE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
53 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
54 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
55 |
UINT __stdcall CheckInstallDir(MSIHANDLE hInstall) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
56 |
#pragma JP_EXPORT_FUNCTION |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
57 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
58 |
TCHAR *szValue = NULL; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
59 |
DWORD cchSize = 0; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
60 |
|
58887
920f6770d71c
8233138 : Error 2343 when using --win-dir-chooser
herrick
parents:
57909
diff
changeset
|
61 |
UINT result = MsiGetProperty(hInstall, TEXT("INSTALLDIR"), |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57254
diff
changeset
|
62 |
TEXT(""), &cchSize); |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
63 |
if (result == ERROR_MORE_DATA) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
64 |
cchSize = cchSize + 1; // NULL termination |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
65 |
szValue = new TCHAR[cchSize]; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
66 |
if (szValue) { |
58887
920f6770d71c
8233138 : Error 2343 when using --win-dir-chooser
herrick
parents:
57909
diff
changeset
|
67 |
result = MsiGetProperty(hInstall, TEXT("INSTALLDIR"), |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57254
diff
changeset
|
68 |
szValue, &cchSize); |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
69 |
} else { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
70 |
return ERROR_INSTALL_FAILURE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
71 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
72 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
73 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
74 |
if (result != ERROR_SUCCESS) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
75 |
delete [] szValue; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
76 |
return ERROR_INSTALL_FAILURE; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
77 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
78 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
79 |
if (DirectoryExist(szValue)) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
80 |
if (PathIsDirectoryEmpty(szValue)) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
81 |
MsiSetProperty(hInstall, TEXT("INSTALLDIR_VALID"), TEXT("1")); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
82 |
} else { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
83 |
MsiSetProperty(hInstall, TEXT("INSTALLDIR_VALID"), TEXT("0")); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
84 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
85 |
} else { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
86 |
MsiSetProperty(hInstall, TEXT("INSTALLDIR_VALID"), TEXT("1")); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
87 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
88 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
89 |
delete [] szValue; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
90 |
|
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
91 |
return ERROR_SUCCESS; |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
92 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
diff
changeset
|
93 |
} |