From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- .../Installer/win/InstallHelper/VBoxCommon.cpp | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp (limited to 'src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp') diff --git a/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp b/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp new file mode 100644 index 00000000..f02447bc --- /dev/null +++ b/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp @@ -0,0 +1,103 @@ +/* $Id: VBoxCommon.cpp $ */ +/** @file + * VBoxCommon - Misc helper routines for install helper. + * + * This is used by internal/serial.cpp and VBoxInstallHelper.cpp. + */ + +/* + * Copyright (C) 2008-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include +#include +#include + +#include +#include + + +UINT VBoxGetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, WCHAR *pwszValueBuf, DWORD cwcValueBuf) +{ + RT_BZERO(pwszValueBuf, cwcValueBuf * sizeof(pwszValueBuf[0])); + + /** @todo r=bird: why do we need to query the size first and then the data. + * The API should be perfectly capable of doing that without our help. */ + DWORD cwcNeeded = 0; + UINT uiRet = MsiGetPropertyW(hMsi, pwszName, L"", &cwcNeeded); + if (uiRet == ERROR_MORE_DATA) + { + ++cwcNeeded; /* On output does not include terminating null, so add 1. */ + + if (cwcNeeded > cwcValueBuf) + return ERROR_MORE_DATA; + uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValueBuf, &cwcNeeded); + } + return uiRet; +} + +#if 0 /* unused */ +/** + * Retrieves a MSI property (in UTF-8). + * + * Convenience function for VBoxGetMsiProp(). + * + * @returns VBox status code. + * @param hMsi MSI handle to use. + * @param pcszName Name of property to retrieve. + * @param ppszValue Where to store the allocated value on success. + * Must be free'd using RTStrFree() by the caller. + */ +int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue) +{ + PRTUTF16 pwszName; + int rc = RTStrToUtf16(pcszName, &pwszName); + if (RT_SUCCESS(rc)) + { + WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */ + if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS) + rc = RTUtf16ToUtf8(wszValue, ppszValue); + else + rc = VERR_NOT_FOUND; + + RTUtf16Free(pwszName); + } + + return rc; +} +#endif + +UINT VBoxSetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, const WCHAR *pwszValue) +{ + return MsiSetPropertyW(hMsi, pwszName, pwszValue); +} + +UINT VBoxSetMsiPropDWORD(MSIHANDLE hMsi, const WCHAR *pwszName, DWORD dwVal) +{ + wchar_t wszTemp[32]; + RTUtf16Printf(wszTemp, RT_ELEMENTS(wszTemp), "%u", dwVal); + return VBoxSetMsiProp(hMsi, pwszName, wszTemp); +} + -- cgit v1.2.3