VirtualBox

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

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

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VBoxCommon.cpp 98103 2023-01-17 14:15:46Z 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-2023 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.215389.xyz.
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#include <msi.h>
36#include <msiquery.h>
37
38#include <iprt/string.h>
39#include <iprt/utf16.h>
40
41
42UINT VBoxGetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, WCHAR *pwszValueBuf, DWORD cwcValueBuf)
43{
44 RT_BZERO(pwszValueBuf, cwcValueBuf * sizeof(pwszValueBuf[0]));
45
46 /** @todo r=bird: why do we need to query the size first and then the data.
47 * The API should be perfectly capable of doing that without our help. */
48 DWORD cwcNeeded = 0;
49 UINT uiRet = MsiGetPropertyW(hMsi, pwszName, L"", &cwcNeeded);
50 if (uiRet == ERROR_MORE_DATA)
51 {
52 ++cwcNeeded; /* On output does not include terminating null, so add 1. */
53
54 if (cwcNeeded > cwcValueBuf)
55 return ERROR_MORE_DATA;
56 uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValueBuf, &cwcNeeded);
57 }
58 return uiRet;
59}
60
61#if 0 /* unused */
62/**
63 * Retrieves a MSI property (in UTF-8).
64 *
65 * Convenience function for VBoxGetMsiProp().
66 *
67 * @returns VBox status code.
68 * @param hMsi MSI handle to use.
69 * @param pcszName Name of property to retrieve.
70 * @param ppszValue Where to store the allocated value on success.
71 * Must be free'd using RTStrFree() by the caller.
72 */
73int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue)
74{
75 PRTUTF16 pwszName;
76 int rc = RTStrToUtf16(pcszName, &pwszName);
77 if (RT_SUCCESS(rc))
78 {
79 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */
80 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS)
81 rc = RTUtf16ToUtf8(wszValue, ppszValue);
82 else
83 rc = VERR_NOT_FOUND;
84
85 RTUtf16Free(pwszName);
86 }
87
88 return rc;
89}
90#endif
91
92UINT VBoxSetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, const WCHAR *pwszValue)
93{
94 return MsiSetPropertyW(hMsi, pwszName, pwszValue);
95}
96
97UINT VBoxSetMsiPropDWORD(MSIHANDLE hMsi, const WCHAR *pwszName, DWORD dwVal)
98{
99 wchar_t wszTemp[32];
100 RTUtf16Printf(wszTemp, RT_ELEMENTS(wszTemp), "%u", dwVal);
101 return VBoxSetMsiProp(hMsi, pwszName, wszTemp);
102}
103
Note: See TracBrowser for help on using the repository browser.

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