author | herrick |
Mon, 17 Jun 2019 15:38:04 -0400 | |
branch | JDK-8200758-branch |
changeset 57413 | 45c74e654794 |
child 57444 | 91e9d4691e5e |
permissions | -rw-r--r-- |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
1 |
/* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
4 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
10 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
16 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
20 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
23 |
* questions. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
24 |
*/ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
25 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
26 |
#include "WinSysInfo.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
27 |
#include "FileUtils.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
28 |
#include "WinErrorHandling.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
29 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
30 |
namespace SysInfo { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
31 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
32 |
tstring getTempDir() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
33 |
std::vector<TCHAR> buffer(MAX_PATH); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
34 |
DWORD res = GetTempPath(static_cast<DWORD>(buffer.size()), buffer.data()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
35 |
if (res > buffer.size()) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
36 |
buffer.resize(res); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
37 |
GetTempPath(static_cast<DWORD>(buffer.size()), buffer.data()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
38 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
39 |
return FileUtils::removeTrailingSlash(buffer.data()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
40 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
41 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
42 |
namespace { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
43 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
44 |
template <class Func> |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
45 |
tstring getSystemDirImpl(Func func, const std::string& label) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
46 |
std::vector<TCHAR> buffer(MAX_PATH); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
47 |
for (int i=0; i<2; i++) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
48 |
DWORD res = func(buffer.data(), static_cast<DWORD>(buffer.size())); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
49 |
if (!res) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
50 |
JP_THROW(SysError(label + " failed", func)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
51 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
52 |
if (res < buffer.size()) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
53 |
return FileUtils::removeTrailingSlash(buffer.data()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
54 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
55 |
buffer.resize(res + 1); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
56 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
57 |
JP_THROW("Unexpected reply from" + label); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
58 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
59 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
60 |
} // namespace |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
61 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
62 |
tstring getSystem32Dir() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
63 |
return getSystemDirImpl(GetSystemDirectory, "GetSystemDirectory"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
64 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
65 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
66 |
tstring getWIPath() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
67 |
return FileUtils::mkpath() << getSystem32Dir() << _T("msiexec.exe"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
68 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
69 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
70 |
namespace { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
71 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
72 |
tstring getModulePath(HMODULE h) |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
73 |
{ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
74 |
std::vector<TCHAR> buf(MAX_PATH); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
75 |
DWORD len = 0; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
76 |
while (true) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
77 |
len = GetModuleFileName(h, buf.data(), (DWORD)buf.size()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
78 |
if (len < buf.size()) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
79 |
break; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
80 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
81 |
// buffer is too small, increase it |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
82 |
buf.resize(buf.size() * 2); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
83 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
84 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
85 |
if (len == 0) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
86 |
// error occured |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
87 |
JP_THROW(SysError("GetModuleFileName failed", GetModuleFileName)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
88 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
89 |
return tstring(buf.begin(), buf.begin() + len); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
90 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
91 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
92 |
} // namespace |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
93 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
94 |
tstring getProcessModulePath() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
95 |
return getModulePath(NULL); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
96 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
97 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
98 |
HMODULE getCurrentModuleHandle() |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
99 |
{ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
100 |
// get module handle for the address of this function |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
101 |
LPCWSTR address = reinterpret_cast<LPCWSTR>(getCurrentModuleHandle); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
102 |
HMODULE hmodule = NULL; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
103 |
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
104 |
address, &hmodule)) |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
105 |
{ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
106 |
JP_THROW(SysError(tstrings::any() << "GetModuleHandleExW failed", GetModuleHandleExW)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
107 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
108 |
return hmodule; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
109 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
110 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
111 |
tstring getCurrentModulePath() |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
112 |
{ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
113 |
return getModulePath(getCurrentModuleHandle()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
114 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
115 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
116 |
namespace { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
117 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
118 |
tstring getEnvVariableImpl(const tstring& name, bool* errorOccured=0) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
119 |
std::vector<TCHAR> buf(10); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
120 |
SetLastError(ERROR_SUCCESS); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
121 |
const DWORD size = GetEnvironmentVariable(name.c_str(), buf.data(), |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
122 |
DWORD(buf.size())); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
123 |
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
124 |
if (errorOccured) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
125 |
*errorOccured = true; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
126 |
return tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
127 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
128 |
JP_THROW(SysError(tstrings::any() << "GetEnvironmentVariable(" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
129 |
<< name << ") failed. Variable not set", GetEnvironmentVariable)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
130 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
131 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
132 |
if (size > buf.size()) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
133 |
buf.resize(size); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
134 |
GetEnvironmentVariable(name.c_str(), buf.data(), DWORD(buf.size())); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
135 |
if (GetLastError() != ERROR_SUCCESS) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
136 |
if (errorOccured) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
137 |
*errorOccured = true; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
138 |
return tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
139 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
140 |
JP_THROW(SysError(tstrings::any() << "GetEnvironmentVariable(" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
141 |
<< name << ") failed", GetEnvironmentVariable)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
142 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
143 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
144 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
145 |
if (errorOccured) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
146 |
*errorOccured = false; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
147 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
148 |
return tstring(buf.data()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
149 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
150 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
151 |
} // namespace |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
152 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
153 |
tstring getEnvVariable(const tstring& name) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
154 |
return getEnvVariableImpl(name); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
155 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
156 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
157 |
tstring getEnvVariable(const std::nothrow_t&, const tstring& name, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
158 |
const tstring& defValue) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
159 |
bool errorOccured = false; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
160 |
const tstring reply = getEnvVariableImpl(name, &errorOccured); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
161 |
if (errorOccured) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
162 |
return defValue; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
163 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
164 |
return reply; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
165 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
166 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
167 |
bool isEnvVariableSet(const tstring& name) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
168 |
TCHAR unused[1]; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
169 |
SetLastError(ERROR_SUCCESS); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
170 |
GetEnvironmentVariable(name.c_str(), unused, _countof(unused)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
171 |
return GetLastError() != ERROR_ENVVAR_NOT_FOUND; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
172 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
173 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
174 |
} // end of namespace SysInfo |