VirtualBox

Ignore:
Timestamp:
Jun 28, 2019 11:28:24 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131649
Message:

USBInstall: Don't make CWD assumptions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/Install/USBInstall.cpp

    r76553 r79408  
    3535#include <iprt/errcore.h>
    3636#include <iprt/initterm.h>
     37#include <iprt/message.h>
    3738#include <iprt/param.h>
    3839#include <iprt/path.h>
     40#include <iprt/process.h>
    3941#include <iprt/stream.h>
    4042#include <iprt/string.h>
    41 #include <iprt/errcore.h>
    42 #include <stdio.h>
     43#include <iprt/utf16.h>
    4344
    4445#include <VBox/VBoxDrvCfg-win.h>
     46
     47
     48/*********************************************************************************************************************************
     49*   Defined Constants And Macros                                                                                                 *
     50*********************************************************************************************************************************/
     51/** The support service name. */
     52#define SERVICE_NAME    "VBoxUSBMon"
     53/** Win32 Device name. */
     54#define DEVICE_NAME     "\\\\.\\VBoxUSBMon"
     55/** NT Device name. */
     56#define DEVICE_NAME_NT   L"\\Device\\VBoxUSBMon"
     57/** Win32 Symlink name. */
     58#define DEVICE_NAME_DOS  L"\\DosDevices\\VBoxUSBMon"
     59
     60
     61/*********************************************************************************************************************************
     62*   Internal Functions                                                                                                           *
     63*********************************************************************************************************************************/
     64int usblibOsCreateService(void);
     65
    4566
    4667static DECLCALLBACK(void) vboxUsbLog(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char *pszMsg, void *pvContext)
     
    6889}
    6990
    70 int usblibOsCreateService(void);
    7191
    7292int __cdecl main(int argc, char **argv)
    7393{
    74     if (RTR3InitExe(argc, &argv, 0) != VINF_SUCCESS)
    75     {
    76         printf("Could not init IPRT!\n");
    77         return 1;
    78     }
     94    int rc = RTR3InitExe(argc, &argv, 0);
     95    if (RT_FAILURE(rc))
     96        return RTMsgInitFailure(rc);
    7997
    8098    VBoxDrvCfgLoggerSet(vboxUsbLog, NULL);
     
    83101    RTPrintf("USB installation\n");
    84102
    85     int rc = usblibOsCreateService();
    86 
     103    rc = usblibOsCreateService();
    87104    if (RT_SUCCESS(rc))
    88105    {
    89         LPWSTR  lpszFilePart;
    90         WCHAR  szFullPath[MAX_PATH];
    91         DWORD  len;
    92 
    93         len = GetFullPathNameW(L".\\VBoxUSB.inf", RT_ELEMENTS(szFullPath), szFullPath, &lpszFilePart);
    94         Assert(len);
    95 
    96         HRESULT hr = VBoxDrvCfgInfInstall(szFullPath);
    97         if (hr == S_OK)
    98         {
    99             RTPrintf("Installation successful.\n");
     106        /* Build the path to the INF file: */
     107        char szInfFile[RTPATH_MAX];
     108        rc = RTProcGetExecutablePath(szInfFile, sizeof(szInfFile)) ? VINF_SUCCESS : VERR_BUFFER_OVERFLOW;
     109        if (RT_SUCCESS(rc))
     110        {
     111            RTPathStripFilename(szInfFile);
     112            rc = RTPathAppend(szInfFile, sizeof(szInfFile), "VBoxUSB.inf");
     113        }
     114        PRTUTF16 pwszInfFile = NULL;
     115        if (RT_SUCCESS(rc))
     116            rc = RTStrToUtf16(szInfFile, &pwszInfFile);
     117        if (RT_SUCCESS(rc))
     118        {
     119            /* Install the INF file: */
     120            HRESULT hr = VBoxDrvCfgInfInstall(pwszInfFile);
     121            if (hr == S_OK)
     122                RTPrintf("Installation successful.\n");
     123            else
     124                rc = -1;
     125
     126            RTUtf16Free(pwszInfFile);
    100127        }
    101128        else
    102         {
    103             rc = -1;
    104         }
    105     }
    106 
    107     if (RT_SUCCESS(rc))
    108         rc = 0;
    109 
    110     /** @todo RTR3Term(); */
    111     return rc;
    112 }
    113 
    114 /** The support service name. */
    115 #define SERVICE_NAME    "VBoxUSBMon"
    116 /** Win32 Device name. */
    117 #define DEVICE_NAME     "\\\\.\\VBoxUSBMon"
    118 /** NT Device name. */
    119 #define DEVICE_NAME_NT   L"\\Device\\VBoxUSBMon"
    120 /** Win32 Symlink name. */
    121 #define DEVICE_NAME_DOS  L"\\DosDevices\\VBoxUSBMon"
     129            RTMsgError("Failed to construct INF path: %Rrc", rc);
     130    }
     131
     132    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     133}
    122134
    123135
Note: See TracChangeset for help on using the changeset viewer.

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