VirtualBox

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

Last change on this file since 93391 was 93340, checked in by vboxsync, 3 years ago

Installer/win/InstallHelper: Don't use IPRT in the helper DLL, causes trouble in ASAN build as we don't have a non-ASAN IPRT library. This saves a big of space too and make procRun do a non-polling wait for the child progress. Reworked the python path detection code a bit too, won't return empty paths any more. The procRun now returns a failure on non-zero child exit. bugref:8489 bugref:9841

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: VBoxCommon.cpp 93340 2022-01-19 10:52:09Z 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 Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#include <iprt/win/windows.h>
25
26#include <tchar.h>
27#include <stdio.h>
28
29#include <msi.h>
30#include <msiquery.h>
31
32#include <iprt/utf16.h>
33
34
35#if (_MSC_VER < 1400) /* Provide swprintf_s to VC < 8.0. */
36int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...)
37{
38 int ret;
39 va_list va;
40 va_start(va, format);
41 ret = _vsnwprintf(buffer, cbBuffer, format, va);
42 va_end(va);
43 return ret;
44}
45#endif
46
47UINT VBoxGetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue, DWORD dwSize)
48{
49 DWORD dwBuffer = 0;
50 UINT uiRet = MsiGetPropertyW(hMsi, pwszName, L"", &dwBuffer);
51 if (uiRet == ERROR_MORE_DATA)
52 {
53 ++dwBuffer; /* On output does not include terminating null, so add 1. */
54
55 if (dwBuffer > dwSize)
56 return ERROR_MORE_DATA;
57
58 ZeroMemory(pwszValue, dwSize);
59 uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValue, &dwBuffer);
60 }
61 return uiRet;
62}
63
64#if 0 /* unused */
65/**
66 * Retrieves a MSI property (in UTF-8).
67 *
68 * Convenience function for VBoxGetMsiProp().
69 *
70 * @returns VBox status code.
71 * @param hMsi MSI handle to use.
72 * @param pcszName Name of property to retrieve.
73 * @param ppszValue Where to store the allocated value on success.
74 * Must be free'd using RTStrFree() by the caller.
75 */
76int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue)
77{
78 PRTUTF16 pwszName;
79 int rc = RTStrToUtf16(pcszName, &pwszName);
80 if (RT_SUCCESS(rc))
81 {
82 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */
83 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS)
84 {
85 rc = RTUtf16ToUtf8(wszValue, ppszValue);
86 }
87 else
88 rc = VERR_NOT_FOUND;
89
90 RTUtf16Free(pwszName);
91 }
92
93 return rc;
94}
95#endif
96
97UINT VBoxSetMsiProp(MSIHANDLE hMsi, WCHAR *pwszName, WCHAR *pwszValue)
98{
99 return MsiSetPropertyW(hMsi, pwszName, pwszValue);
100}
101
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