VirtualBox

source: vbox/trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp@ 96428

Last change on this file since 96428 was 96428, checked in by vboxsync, 2 years ago

Installer/win: Added new build define VBOX_WITH_CRT_PACKING, which leaves out packing the MSCRT with the Windows installer and also checks if the MSCRT 2019 Redistributable Package is installed on the system as a prerequisite (via a custom action). bugref:10284

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: VBoxCommon.cpp 96428 2022-08-23 07:27:21Z vboxsync $ */
2/** @file
3 * VBoxCommon - Misc helper routines for install helper.
4 *
5 * This is used by internal/serial.cpp and VBoxInstallHelper.cpp.
6 */
7
8/*
9 * Copyright (C) 2008-2022 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30
31/*********************************************************************************************************************************
32* Header Files *
33*********************************************************************************************************************************/
34#include <iprt/win/windows.h>
35
36#include <tchar.h>
37#include <stdio.h>
38
39#include <msi.h>
40#include <msiquery.h>
41
42#include <iprt/utf16.h>
43
44
45#if (_MSC_VER < 1400) /* Provide swprintf_s to VC < 8.0. */
46int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...)
47{
48 int ret;
49 va_list va;
50 va_start(va, format);
51 ret = _vsnwprintf(buffer, cbBuffer, format, va);
52 va_end(va);
53 return ret;
54}
55#endif
56
57UINT VBoxGetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, WCHAR *pwszValue, DWORD dwSize)
58{
59 DWORD dwBuffer = 0;
60 UINT uiRet = MsiGetPropertyW(hMsi, pwszName, L"", &dwBuffer);
61 if (uiRet == ERROR_MORE_DATA)
62 {
63 ++dwBuffer; /* On output does not include terminating null, so add 1. */
64
65 if (dwBuffer > dwSize)
66 return ERROR_MORE_DATA;
67
68 ZeroMemory(pwszValue, dwSize);
69 uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValue, &dwBuffer);
70 }
71 return uiRet;
72}
73
74#if 0 /* unused */
75/**
76 * Retrieves a MSI property (in UTF-8).
77 *
78 * Convenience function for VBoxGetMsiProp().
79 *
80 * @returns VBox status code.
81 * @param hMsi MSI handle to use.
82 * @param pcszName Name of property to retrieve.
83 * @param ppszValue Where to store the allocated value on success.
84 * Must be free'd using RTStrFree() by the caller.
85 */
86int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue)
87{
88 PRTUTF16 pwszName;
89 int rc = RTStrToUtf16(pcszName, &pwszName);
90 if (RT_SUCCESS(rc))
91 {
92 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */
93 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS)
94 {
95 rc = RTUtf16ToUtf8(wszValue, ppszValue);
96 }
97 else
98 rc = VERR_NOT_FOUND;
99
100 RTUtf16Free(pwszName);
101 }
102
103 return rc;
104}
105#endif
106
107UINT VBoxSetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, const WCHAR *pwszValue)
108{
109 return MsiSetPropertyW(hMsi, pwszName, pwszValue);
110}
111
112UINT VBoxSetMsiPropDWORD(MSIHANDLE hMsi, const WCHAR *pwszName, DWORD dwVal)
113{
114 wchar_t wszTemp[32];
115 swprintf(wszTemp, sizeof(wszTemp) / sizeof(wchar_t), L"%ld", dwVal);
116 return VBoxSetMsiProp(hMsi, pwszName, wszTemp);
117}
118
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette