GuestSessionImplTasks.cpp revision 965c5f95cd56476f8dfa452efc19dd7eb10a4a56
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/* $Id$ */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/** @file
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * VirtualBox Main - XXX.
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/*
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * Copyright (C) 2012 Oracle Corporation
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync *
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * available from http://www.virtualbox.org. This file is free software;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * General Public License (GPL) as published by the Free Software
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync */
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync/*******************************************************************************
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync* Header Files *
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync*******************************************************************************/
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync#include "GuestImpl.h"
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync#include "GuestSessionImpl.h"
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync#include "GuestCtrlImplPrivate.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include "Global.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include "AutoCaller.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include "ConsoleImpl.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include "MachineImpl.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include "ProgressImpl.h"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include <memory> /* For auto_ptr. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
032a52c5b2984e26e84c2961f8f7f98a3954c8f2vboxsync#include <iprt/env.h>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include <iprt/file.h> /* For CopyTo/From. */
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#ifdef LOG_GROUP
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync #undef LOG_GROUP
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#endif
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include <VBox/log.h>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/*******************************************************************************
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync* Defines *
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync*******************************************************************************/
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/**
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * Update file flags.
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync */
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync#define UPDATEFILE_FLAG_NONE RT_BIT(0)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync/** File is optional, does not have to be
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync * existent on the .ISO. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define UPDATEFILE_FLAG_OPTIONAL RT_BIT(1)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/** Execute file on the guest after it has
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync * been successfully transfered. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#define UPDATEFILE_FLAG_EXECUTE RT_BIT(2)
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync// session task classes
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync/////////////////////////////////////////////////////////////////////////////
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncGuestSessionTask::GuestSessionTask(GuestSession *pSession)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync mSession = pSession;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncGuestSessionTask::~GuestSessionTask(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncint GuestSessionTask::getGuestProperty(const ComObjPtr<Guest> &pGuest,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync const Utf8Str &strPath, Utf8Str &strValue)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync ComObjPtr<Console> pConsole = pGuest->getConsole();
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync const ComPtr<IMachine> pMachine = pConsole->machine();
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Assert(!pMachine.isNull());
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Bstr strTemp, strFlags;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync LONG64 i64Timestamp;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync HRESULT hr = pMachine->GetGuestProperty(Bstr(strPath).raw(),
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync strTemp.asOutParam(),
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync &i64Timestamp, strFlags.asOutParam());
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if (SUCCEEDED(hr))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync {
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync strValue = strTemp;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VINF_SUCCESS;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync }
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VERR_NOT_FOUND;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncint GuestSessionTask::setProgress(ULONG uPercent)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if (mProgress.isNull()) /* Progress is optional. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VINF_SUCCESS;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync BOOL fCanceled;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync && fCanceled)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VERR_CANCELLED;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync BOOL fCompleted;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync && !fCompleted)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VINF_SUCCESS;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync HRESULT hr = mProgress->SetCurrentOperationProgress(uPercent);
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if (FAILED(hr))
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VERR_COM_UNEXPECTED;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VINF_SUCCESS;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncint GuestSessionTask::setProgressSuccess(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if (mProgress.isNull()) /* Progress is optional. */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return VINF_SUCCESS;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync BOOL fCanceled;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync BOOL fCompleted;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && !fCanceled
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && !fCompleted)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync HRESULT hr = mProgress->notifyComplete(S_OK);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (FAILED(hr))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return VERR_COM_UNEXPECTED; /** @todo Find a better rc. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return VINF_SUCCESS;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync}
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsyncHRESULT GuestSessionTask::setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (mProgress.isNull()) /* Progress is optional. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return hr; /* Return original rc. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync BOOL fCanceled;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync BOOL fCompleted;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && !fCanceled
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && !fCompleted)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync HRESULT hr2 = mProgress->notifyComplete(hr,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync COM_IIDOF(IGuestSession),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync GuestSession::getStaticComponentName(),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync strMsg.c_str());
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (FAILED(hr2))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return hr2;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return hr; /* Return original rc. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync}
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync : GuestSessionTask(pSession),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource(strSource),
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync mSourceFile(NULL),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSourceOffset(0),
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync mSourceSize(0),
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync mDest(strDest)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync{
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync mCopyFileFlags = uFlags;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync}
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync/** @todo Merge this and the above call and let the above call do the open/close file handling so that the
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync * inner code only has to deal with file handles. No time now ... */
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync const Utf8Str &strDest, uint32_t uFlags)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync : GuestSessionTask(pSession)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSourceFile = pSourceFile;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSourceOffset = cbSourceOffset;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSourceSize = cbSourceSize;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync mDest = strDest;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mCopyFileFlags = uFlags;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync}
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsyncSessionTaskCopyTo::~SessionTaskCopyTo(void)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync}
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsyncint SessionTaskCopyTo::Run(void)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowThisFuncEnter();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync ComObjPtr<GuestSession> pSession = mSession;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Assert(!pSession.isNull());
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync AutoCaller autoCaller(pSession);
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (mCopyFileFlags)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Copy flags (%#x) not implemented yet"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mCopyFileFlags));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return VERR_INVALID_PARAMETER;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync int rc;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync RTFILE fileLocal;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync PRTFILE pFile = &fileLocal;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (!mSourceFile)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Does our source file exist? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (!RTFileExists(mSource.c_str()))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Source file \"%s\" does not exist or is not a file"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str()));
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = RTFileOpen(pFile, mSource.c_str(),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Could not open source file \"%s\" for reading: %Rrc"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = RTFileGetSize(*pFile, &mSourceSize);
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync if (RT_FAILURE(rc))
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Could not query file size of \"%s\": %Rrc"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), rc));
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync else
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync {
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync pFile = mSourceFile;
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync /* Size + offset are optional. */
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync }
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync GuestProcessStartupInfo procInfo;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" to the guest to \"%s\" (%RU64 bytes)"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), mDest.c_str(), mSourceSize);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Set arguments.*/
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync procInfo.mArguments.push_back(Utf8StrFmt("--output=%s", mDest.c_str())); /** @todo Do we need path conversion? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Startup process. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync ComObjPtr<GuestProcess> pProcess;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_SUCCESS(rc))
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync rc = pProcess->startProcess();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Unable to start guest process: %Rrc"), rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync GuestProcessWaitResult waitRes;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync BYTE byBuf[_64K];
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync BOOL fCanceled = FALSE;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync uint64_t cbWrittenTotal = 0;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync uint64_t cbToRead = mSourceSize;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync for (;;)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = pProcess->waitFor(ProcessWaitForFlag_StdIn,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync 30 * 1000 /* Timeout */, waitRes);
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync if ( RT_FAILURE(rc)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || ( waitRes.mResult != ProcessWaitResult_StdIn
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync && waitRes.mResult != ProcessWaitResult_WaitFlagNotSupported))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* If the guest does not support waiting for stdin, we now yield in
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * order to reduce the CPU load due to busy waiting. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync RTThreadYield(); /* Optional, don't check rc. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync size_t cbRead = 0;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (mSourceSize) /* If we have nothing to write, take a shortcut. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /** @todo Not very efficient, but works for now. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = RTFileSeek(*pFile, mSourceOffset + cbWrittenTotal,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync RTFILE_SEEK_BEGIN, NULL /* poffActual */);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_SUCCESS(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = RTFileRead(*pFile, (uint8_t*)byBuf,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync RT_MIN(cbToRead, sizeof(byBuf)), &cbRead);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /*
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * Some other error occured? There might be a chance that RTFileRead
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * could not resolve/map the native error code to an IPRT code, so just
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * print a generic error.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Could not read from file \"%s\" (%Rrc)"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Seeking file \"%s\" offset %RU64 failed: %Rrc"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), cbWrittenTotal, rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync uint32_t fFlags = ProcessInputFlag_None;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Did we reach the end of the content we want to transfer (last chunk)? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( (cbRead < sizeof(byBuf))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Did we reach the last block which is exactly _64K? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || (cbToRead - cbRead == 0)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* ... or does the user want to cancel? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && fCanceled)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync fFlags |= ProcessInputFlag_EndOfFile;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync uint32_t cbWritten;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Assert(sizeof(byBuf) >= cbRead);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = pProcess->writeData(0 /* StdIn */, fFlags,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync byBuf, cbRead,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync 30 * 1000 /* Timeout */, &cbWritten);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Writing to file \"%s\" (offset %RU64) failed: %Rrc"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mDest.c_str(), cbWrittenTotal, rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowThisFunc(("cbWritten=%RU32, cbToRead=%RU64, cbWrittenTotal=%RU64, cbFileSize=%RU64\n",
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync cbWritten, cbToRead - cbWritten, cbWrittenTotal + cbWritten, mSourceSize));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Only subtract bytes reported written by the guest. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Assert(cbToRead >= cbWritten);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync cbToRead -= cbWritten;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Update total bytes written to the guest. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync cbWrittenTotal += cbWritten;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Assert(cbWrittenTotal <= mSourceSize);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Did the user cancel the operation above? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (fCanceled)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* Update the progress.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * Watch out for division by zero. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSourceSize > 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync ? rc = setProgress((ULONG)(cbWrittenTotal * 100 / mSourceSize))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync : rc = setProgress(100);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* End of file reached? */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (!cbToRead)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync break;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync } /* for */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( !fCanceled
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || RT_SUCCESS(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /*
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * Even if we succeeded until here make sure to check whether we really transfered
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * everything.
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( mSourceSize > 0
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && cbWrittenTotal == 0)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync * to the destination -> access denied. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), mDest.c_str()));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else if (cbWrittenTotal < mSourceSize)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync /* If we did not copy all let the user know. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RU64 bytes transfered)"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), cbWrittenTotal, mSourceSize));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync 30 * 1000 /* Timeout */, waitRes);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( RT_FAILURE(rc)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || waitRes.mResult != ProcessWaitResult_Terminate)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_FAILURE(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed: %Rrc"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), rc));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync else
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed with wait result %ld"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), waitRes.mResult));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_SUCCESS(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync ProcessStatus_T procStatus;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LONG exitCode;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && procStatus != ProcessStatus_TerminatedNormally)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync && exitCode != 0)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync )
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync {
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %ld"),
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (RT_SUCCESS(rc))
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync rc = setProgressSuccess();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync }
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (!pProcess.isNull())
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync pProcess->uninit();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync } /* processCreateExInteral */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync if (!mSourceFile) /* Only close locally opened files. */
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync RTFileClose(*pFile);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowFuncLeaveRC(rc);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return rc;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync}
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsyncint SessionTaskCopyTo::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, mCopyFileFlags=%x\n",
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mCopyFileFlags));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mDesc = strDesc;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync mProgress = pProgress;
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyTo::taskThread, this,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "gctlCpyTo");
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowFuncLeaveRC(rc);
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return rc;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
611e5e148a74d4b54cf76c97e4d36acaa816d8c0vboxsync/* static */
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsyncint SessionTaskCopyTo::taskThread(RTTHREAD Thread, void *pvUser)
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync{
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync std::auto_ptr<SessionTaskCopyTo> task(static_cast<SessionTaskCopyTo*>(pvUser));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync LogFlowFunc(("pTask=%p\n", task.get()));
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync return task->Run();
4a1654dd5b9f0ae4e149d909843a3ab07b8bec33vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncSessionTaskCopyFrom::SessionTaskCopyFrom(GuestSession *pSession,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync : GuestSessionTask(pSession)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync mSource = strSource;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync mDest = strDest;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync mFlags = uFlags;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncSessionTaskCopyFrom::~SessionTaskCopyFrom(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsyncint SessionTaskCopyFrom::Run(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync LogFlowThisFuncEnter();
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
ComObjPtr<GuestSession> pSession = mSession;
Assert(!pSession.isNull());
AutoCaller autoCaller(pSession);
if (FAILED(autoCaller.rc())) return autoCaller.rc();
/*
* Note: There will be races between querying file size + reading the guest file's
* content because we currently *do not* lock down the guest file when doing the
* actual operations.
** @todo Implement guest file locking!
*/
GuestFsObjData objData;
int rc = pSession->fileQueryInfoInternal(Utf8Str(mSource), objData);
if (RT_FAILURE(rc))
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Querying guest file information for \"%s\" failed: %Rrc"),
mSource.c_str(), rc));
}
else if (objData.mType != FsObjType_File) /* Only single files are supported at the moment. */
{
rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Object \"%s\" on the guest is not a file"), mSource.c_str()));
}
if (RT_SUCCESS(rc))
{
RTFILE fileDest;
rc = RTFileOpen(&fileDest, mDest.c_str(),
RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); /** @todo Use the correct open modes! */
if (RT_FAILURE(rc))
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Error opening destination file \"%s\": %Rrc"),
mDest.c_str(), rc));
}
else
{
GuestProcessStartupInfo procInfo;
procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" from guest to the host to \"%s\" (%RI64 bytes)"),
mSource.c_str(), mDest.c_str(), objData.mObjectSize);
procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
procInfo.mFlags = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
/* Set arguments.*/
procInfo.mArguments.push_back(mSource); /* Which file to output? */
/* Startup process. */
ComObjPtr<GuestProcess> pProcess;
rc = pSession->processCreateExInteral(procInfo, pProcess);
if (RT_SUCCESS(rc))
rc = pProcess->startProcess();
if (RT_FAILURE(rc))
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Unable to start guest process for copying data from guest to host: %Rrc"), rc));
}
else
{
GuestProcessWaitResult waitRes;
BYTE byBuf[_64K];
BOOL fCanceled = FALSE;
uint64_t cbWrittenTotal = 0;
uint64_t cbToRead = objData.mObjectSize;
for (;;)
{
rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
30 * 1000 /* Timeout */, waitRes);
if ( waitRes.mResult == ProcessWaitResult_StdOut
|| waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
{
/* If the guest does not support waiting for stdin, we now yield in
* order to reduce the CPU load due to busy waiting. */
if (waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
RTThreadYield(); /* Optional, don't check rc. */
size_t cbRead;
rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
&cbRead);
if (RT_FAILURE(rc))
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Reading from file \"%s\" (offset %RU64) failed: %Rrc"),
mSource.c_str(), cbWrittenTotal, rc));
break;
}
if (cbRead)
{
rc = RTFileWrite(fileDest, byBuf, cbRead, NULL /* No partial writes */);
if (RT_FAILURE(rc))
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Error writing to file \"%s\" (%RU64 bytes left): %Rrc"),
mDest.c_str(), cbToRead, rc));
break;
}
/* Only subtract bytes reported written by the guest. */
Assert(cbToRead >= cbRead);
cbToRead -= cbRead;
/* Update total bytes written to the guest. */
cbWrittenTotal += cbRead;
Assert(cbWrittenTotal <= (uint64_t)objData.mObjectSize);
/* Did the user cancel the operation above? */
if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
&& fCanceled)
break;
rc = setProgress((ULONG)(cbWrittenTotal / ((uint64_t)objData.mObjectSize / 100.0)));
if (RT_FAILURE(rc))
break;
}
}
else if ( RT_FAILURE(rc)
|| waitRes.mResult == ProcessWaitResult_Terminate
|| waitRes.mResult == ProcessWaitResult_Error
|| waitRes.mResult == ProcessWaitResult_Timeout)
{
if (RT_FAILURE(waitRes.mRC))
rc = waitRes.mRC;
break;
}
} /* for */
LogFlowThisFunc(("rc=%Rrc, cbWrittenTotal=%RU64, cbSize=%RI64, cbToRead=%RU64\n",
rc, cbWrittenTotal, objData.mObjectSize, cbToRead));
if ( !fCanceled
|| RT_SUCCESS(rc))
{
/*
* Even if we succeeded until here make sure to check whether we really transfered
* everything.
*/
if ( objData.mObjectSize > 0
&& cbWrittenTotal == 0)
{
/* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
* to the destination -> access denied. */
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
mSource.c_str(), mDest.c_str()));
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
else if (cbWrittenTotal < (uint64_t)objData.mObjectSize)
{
/* If we did not copy all let the user know. */
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RI64 bytes transfered)"),
mSource.c_str(), cbWrittenTotal, objData.mObjectSize));
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
else
{
ProcessStatus_T procStatus;
LONG exitCode;
if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
&& procStatus != ProcessStatus_TerminatedNormally)
|| ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
&& exitCode != 0)
)
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %d"),
mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
else /* Yay, success! */
rc = setProgressSuccess();
}
}
if (!pProcess.isNull())
pProcess->uninit();
}
RTFileClose(fileDest);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
int SessionTaskCopyFrom::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
{
LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags));
mDesc = strDesc;
mProgress = pProgress;
int rc = RTThreadCreate(NULL, SessionTaskCopyFrom::taskThread, this,
0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
"gctlCpyFrom");
LogFlowFuncLeaveRC(rc);
return rc;
}
/* static */
int SessionTaskCopyFrom::taskThread(RTTHREAD Thread, void *pvUser)
{
std::auto_ptr<SessionTaskCopyFrom> task(static_cast<SessionTaskCopyFrom*>(pvUser));
AssertReturn(task.get(), VERR_GENERAL_FAILURE);
LogFlowFunc(("pTask=%p\n", task.get()));
return task->Run();
}
SessionTaskUpdateAdditions::SessionTaskUpdateAdditions(GuestSession *pSession,
const Utf8Str &strSource, uint32_t uFlags)
: GuestSessionTask(pSession)
{
mSource = strSource;
mFlags = uFlags;
}
SessionTaskUpdateAdditions::~SessionTaskUpdateAdditions(void)
{
}
int SessionTaskUpdateAdditions::copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
Utf8Str const &strFileSource, const Utf8Str &strFileDest,
bool fOptional, uint32_t *pcbSize)
{
AssertPtrReturn(pSession, VERR_INVALID_POINTER);
AssertPtrReturn(pISO, VERR_INVALID_POINTER);
/* pcbSize is optional. */
uint32_t cbOffset;
size_t cbSize;
int rc = RTIsoFsGetFileInfo(pISO, strFileSource.c_str(), &cbOffset, &cbSize);
if (RT_FAILURE(rc))
{
if (fOptional)
return VINF_SUCCESS;
return rc;
}
Assert(cbOffset);
Assert(cbSize);
rc = RTFileSeek(pISO->file, cbOffset, RTFILE_SEEK_BEGIN, NULL);
/* Copy over the Guest Additions file to the guest. */
if (RT_SUCCESS(rc))
{
LogRel(("Copying Guest Additions installer file \"%s\" to \"%s\" on guest ...\n",
strFileSource.c_str(), strFileDest.c_str()));
if (RT_SUCCESS(rc))
{
SessionTaskCopyTo *pTask = new SessionTaskCopyTo(pSession /* GuestSession */,
&pISO->file, cbOffset, cbSize,
strFileDest, CopyFileFlag_None);
AssertPtrReturn(pTask, VERR_NO_MEMORY);
ComObjPtr<Progress> pProgressCopyTo;
rc = pSession->startTaskAsync(Utf8StrFmt(GuestSession::tr("Copying Guest Additions installer file \"%s\" to \"%s\" on guest"),
mSource.c_str(), strFileDest.c_str()),
pTask, pProgressCopyTo);
if (RT_SUCCESS(rc))
{
BOOL fCanceled = FALSE;
HRESULT hr = pProgressCopyTo->WaitForCompletion(-1);
if ( SUCCEEDED(pProgressCopyTo->COMGETTER(Canceled)(&fCanceled))
&& fCanceled)
{
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
else if (FAILED(hr))
{
Assert(FAILED(hr));
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
}
}
}
/** @todo Note: Since there is no file locking involved at the moment, there can be modifications
* between finished copying, the verification and the actual execution. */
/* Determine where the installer image ended up and if it has the correct size. */
if (RT_SUCCESS(rc))
{
LogRel(("Verifying Guest Additions installer file \"%s\" ...\n", strFileDest.c_str()));
GuestFsObjData objData;
int64_t cbSizeOnGuest;
rc = pSession->fileQuerySizeInternal(strFileDest, &cbSizeOnGuest);
if ( RT_SUCCESS(rc)
&& cbSize == (uint64_t)cbSizeOnGuest)
{
LogRel(("Guest Additions installer file \"%s\" successfully verified\n",
strFileDest.c_str()));
}
else
{
if (RT_SUCCESS(rc)) /* Size does not match. */
{
LogRel(("Size of Guest Additions installer file \"%s\" does not match: %RI64bytes copied, %RU64bytes expected\n",
strFileDest.c_str(), cbSizeOnGuest, cbSize));
rc = VERR_BROKEN_PIPE; /** @todo Find a better error. */
}
else
LogRel(("Error copying Guest Additions installer file \"%s\": %Rrc\n",
strFileDest.c_str(), rc));
}
if (RT_SUCCESS(rc))
{
if (pcbSize)
*pcbSize = cbSizeOnGuest;
}
}
return rc;
}
int SessionTaskUpdateAdditions::runFile(GuestSession *pSession, GuestProcessStartupInfo &procInfo)
{
AssertPtrReturn(pSession, VERR_INVALID_POINTER);
ComObjPtr<GuestProcess> pProcess;
int rc = pSession->processCreateExInteral(procInfo, pProcess);
if (RT_SUCCESS(rc))
rc = pProcess->startProcess();
if (RT_SUCCESS(rc))
{
LogRel(("Running %s ...\n", procInfo.mName.c_str()));
GuestProcessWaitResult waitRes;
rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
10 * 60 * 1000 /* 10 mins Timeout */, waitRes);
if (waitRes.mResult == ProcessWaitResult_Terminate)
{
ProcessStatus_T procStatus;
LONG exitCode;
if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
&& procStatus != ProcessStatus_TerminatedNormally)
|| ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
&& exitCode != 0)
)
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Running %s failed with status %ld, exit code %ld"),
procInfo.mName.c_str(), procStatus, exitCode));
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
else /* Yay, success! */
{
LogRel(("%s successfully completed\n", procInfo.mName.c_str()));
}
}
else
{
if (RT_FAILURE(rc))
setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Error while waiting running %s: %Rrc"),
procInfo.mName.c_str(), rc));
else
{
setProgressErrorMsg(VBOX_E_IPRT_ERROR, pProcess->errorMsg());
rc = VERR_GENERAL_FAILURE; /* Fudge. */
}
}
}
if (!pProcess.isNull())
pProcess->uninit();
return rc;
}
int SessionTaskUpdateAdditions::Run(void)
{
LogFlowThisFuncEnter();
ComObjPtr<GuestSession> pSession = mSession;
Assert(!pSession.isNull());
AutoCaller autoCaller(pSession);
if (FAILED(autoCaller.rc())) return autoCaller.rc();
int rc = setProgress(10);
if (RT_FAILURE(rc))
return rc;
HRESULT hr = S_OK;
LogRel(("Automatic update of Guest Additions started, using \"%s\"\n", mSource.c_str()));
/*
* Determine guest OS type and the required installer image.
*/
ComObjPtr<Guest> pGuest(mSession->getParent());
eOSType eOSType;
Utf8Str strOSType;
rc = getGuestProperty(pGuest, "/VirtualBox/GuestInfo/OS/Product", strOSType);
if ( strOSType.contains("Microsoft", Utf8Str::CaseInsensitive)
|| strOSType.contains("Windows", Utf8Str::CaseInsensitive))
{
eOSType = eOSType_Windows;
}
else if (strOSType.contains("Solaris", Utf8Str::CaseInsensitive))
{
eOSType = eOSType_Solaris;
}
else /* Everything else hopefully means Linux :-). */
eOSType = eOSType_Linux;
#if 1 /* Only Windows is supported (and tested) at the moment. */
if (eOSType != eOSType_Windows)
{
hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Detected guest OS (%s) does not support automatic Guest Additions updating, please update manually"),
strOSType.c_str()));
rc = VERR_NOT_SUPPORTED;
}
#endif
RTISOFSFILE iso;
if (RT_SUCCESS(rc))
{
/*
* Try to open the .ISO file to extract all needed files.
*/
rc = RTIsoFsOpen(&iso, mSource.c_str());
if (RT_FAILURE(rc))
{
hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Unable to open Guest Additions .ISO file \"%s\": %Rrc"),
mSource.c_str(), rc));
}
else
{
/* Set default installation directories. */
Utf8Str strInstallerDir = "/tmp/";
if (eOSType == eOSType_Windows)
strInstallerDir = "C:\\Temp\\";
rc = setProgress(5);
/* Try looking up the Guest Additions installation directory. */
if (RT_SUCCESS(rc))
{
rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/InstallDir", strInstallerDir);
if (RT_SUCCESS(rc))
{
LogRel(("Guest Additions were installed to: %ls\n",
strInstallerDir.c_str()));
rc = setProgress(8);
}
if (RT_SUCCESS(rc))
{
if (eOSType == eOSType_Windows)
{
strInstallerDir.findReplace('/', '\\');
strInstallerDir.append("\\Update\\");
}
else
strInstallerDir.append("/update/");
}
}
LogRel(("Guest Additions update will be installed to: %s\n",
strInstallerDir.c_str()));
/* Prepare the file(s) we want to copy over to the guest and
* (maybe) want to run. */
switch (eOSType)
{
case eOSType_Windows:
{
/* Our certificate. */
mFiles.push_back(InstallerFile("CERT/ORACLE_VBOX.CER", "Oracle_VBox.cer",
UPDATEFILE_FLAG_OPTIONAL));
/* Our certificate installation utility. */
GuestProcessStartupInfo siCertUtil;
siCertUtil.mArguments.push_back(Utf8Str("add-trusted-publisher"));
siCertUtil.mArguments.push_back(Utf8Str(strInstallerDir + "oracle-vbox.cer"));
mFiles.push_back(InstallerFile("CERT/VBOXCERTUTIL.EXE", "VBoxCertUtil.exe",
UPDATEFILE_FLAG_OPTIONAL | UPDATEFILE_FLAG_EXECUTE, siCertUtil));
/* The installers in different flavors. */
mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_X86.EXE",
strInstallerDir + "VBoxWindowsAdditions_x86.exe",
UPDATEFILE_FLAG_NONE));
mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_AMD64.EXE",
strInstallerDir + "VBoxWindowsAdditions_amd64.exe",
UPDATEFILE_FLAG_NONE));
GuestProcessStartupInfo siInstaller;
siInstaller.mArguments.push_back(Utf8Str("/S")); /* We want to install in silent mode. */
siInstaller.mArguments.push_back(Utf8Str("/l")); /* ... and logging enabled. */
/* Don't quit VBoxService during upgrade because it still is used for this
* piece of code we're in right now (that is, here!) ... */
siInstaller.mArguments.push_back(Utf8Str("/no_vboxservice_exit"));
/* Tell the installer to report its current installation status
* using a running VBoxTray instance via balloon messages in the
* Windows taskbar. */
siInstaller.mArguments.push_back(Utf8Str("/post_installstatus"));
/* If the caller does not want to wait for out guest update process to end,
* complete the progress object now so that the caller can do other work. */
if (mFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly)
siInstaller.mFlags |= ProcessCreateFlag_WaitForProcessStartOnly;
mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS.EXE",
strInstallerDir + "VBoxWindowsAdditions.exe",
UPDATEFILE_FLAG_EXECUTE, siInstaller));
break;
}
case eOSType_Linux:
/** @todo Add Linux support. */
break;
case eOSType_Solaris:
/** @todo Add Solaris support. */
break;
default:
rc = VERR_INVALID_PARAMETER;
}
if (RT_SUCCESS(rc))
{
std::vector<InstallerFile>::const_iterator itFiles = mFiles.begin();
while (itFiles != mFiles.end())
{
rc = copyFileToGuest(pSession, &iso, itFiles->strSource, itFiles->strDest,
(itFiles->fFlags & UPDATEFILE_FLAG_OPTIONAL), NULL /* cbSize */);
if (RT_FAILURE(rc))
{
hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Error while copying file \"%s\" to \"%s\" on the guest: %Rrc"),
itFiles->strSource.c_str(), itFiles->strDest.c_str(), rc));
break;
}
itFiles++;
}
}
if (RT_SUCCESS(rc))
{
std::vector<InstallerFile>::iterator itFiles = mFiles.begin();
while (itFiles != mFiles.end())
{
rc = runFile(pSession, itFiles->mProcInfo);
if (RT_FAILURE(rc))
{
hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
Utf8StrFmt(GuestSession::tr("Error while running installer file \"%s\" on the guest: %Rrc"),
itFiles->strDest.c_str(), rc));
break;
}
itFiles++;
}
}
if (RT_SUCCESS(rc))
hr = setProgressSuccess();
RTIsoFsClose(&iso);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
int SessionTaskUpdateAdditions::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
{
LogFlowThisFunc(("strDesc=%s, strSource=%s, uFlags=%x\n",
strDesc.c_str(), mSource.c_str(), mFlags));
mDesc = strDesc;
mProgress = pProgress;
int rc = RTThreadCreate(NULL, SessionTaskUpdateAdditions::taskThread, this,
0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
"gctlUpGA");
LogFlowFuncLeaveRC(rc);
return rc;
}
/* static */
int SessionTaskUpdateAdditions::taskThread(RTTHREAD Thread, void *pvUser)
{
std::auto_ptr<SessionTaskUpdateAdditions> task(static_cast<SessionTaskUpdateAdditions*>(pvUser));
AssertReturn(task.get(), VERR_GENERAL_FAILURE);
LogFlowFunc(("pTask=%p\n", task.get()));
return task->Run();
}