VirtualBox

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

Last change on this file since 106061 was 106061, checked in by vboxsync, 3 months 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 106061 2024-09-16 14:03:52Z 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-2024 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#include <msi.h>
36#include <msiquery.h>
37
38#include <iprt/string.h>
39#include <iprt/utf16.h>
40
41#include "VBoxCommon.h"
42
43
44#ifndef TESTCASE
45/**
46 * Retrieves a MSI property (in UTF-16).
47 *
48 * Convenience function for VBoxGetMsiProp().
49 *
50 * @returns VBox status code.
51 * @param hMsi MSI handle to use.
52 * @param pwszName Name of property to retrieve.
53 * @param pwszValueBuf Where to store the allocated value on success.
54 * @param cwcValueBuf Size (in WCHARs) of \a pwszValueBuf.
55 */
56UINT VBoxGetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, WCHAR *pwszValueBuf, DWORD cwcValueBuf)
57{
58 RT_BZERO(pwszValueBuf, cwcValueBuf * sizeof(WCHAR));
59 return MsiGetPropertyW(hMsi, pwszName, pwszValueBuf, &cwcValueBuf);
60}
61#endif
62
63/**
64 * Retrieves a MSI property (in UTF-8).
65 *
66 * Convenience function for VBoxGetMsiProp().
67 *
68 * @returns VBox status code.
69 * @param hMsi MSI handle to use.
70 * @param pcszName Name of property to retrieve.
71 * @param ppszValue Where to store the allocated value on success.
72 * Must be free'd using RTStrFree() by the caller.
73 */
74int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue)
75{
76 PRTUTF16 pwszName;
77 int rc = RTStrToUtf16(pcszName, &pwszName);
78 if (RT_SUCCESS(rc))
79 {
80 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */
81 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, RT_ELEMENTS(wszValue)) == ERROR_SUCCESS)
82 rc = RTUtf16ToUtf8(wszValue, ppszValue);
83 else
84 rc = VERR_NOT_FOUND;
85
86 RTUtf16Free(pwszName);
87 }
88
89 return rc;
90}
91
92#ifndef TESTCASE
93UINT VBoxSetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, const WCHAR *pwszValue)
94{
95 return MsiSetPropertyW(hMsi, pwszName, pwszValue);
96}
97#endif
98
99UINT VBoxSetMsiPropDWORD(MSIHANDLE hMsi, const WCHAR *pwszName, DWORD dwVal)
100{
101 wchar_t wszTemp[32];
102 RTUtf16Printf(wszTemp, RT_ELEMENTS(wszTemp), "%u", dwVal);
103 return VBoxSetMsiProp(hMsi, pwszName, wszTemp);
104}
105
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