GuestSessionImplTasks.cpp revision f75c6db919d277952ca03b7acf643e5e3ac96caf
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* $Id$ */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @file
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox Main - XXX.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copyright (C) 2012 Oracle Corporation
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * available from http://www.virtualbox.org. This file is free software;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * General Public License (GPL) as published by the Free Software
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Header Files *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "GuestImpl.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "GuestSessionImpl.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "GuestCtrlImplPrivate.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "Global.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "AutoCaller.h"
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include "ConsoleImpl.h"
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include "MachineImpl.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "ProgressImpl.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <memory> /* For auto_ptr. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/env.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/file.h> /* For CopyTo/From. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#ifdef LOG_GROUP
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync #undef LOG_GROUP
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#endif
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/log.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/*******************************************************************************
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync* Defines *
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync*******************************************************************************/
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/**
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Update file flags.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#define UPDATEFILE_FLAG_NONE RT_BIT(0)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/** Copy over the file from host to the
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * guest. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#define UPDATEFILE_FLAG_COPY_FROM_ISO RT_BIT(1)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/** Execute file on the guest after it has
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * been successfully transfered. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#define UPDATEFILE_FLAG_EXECUTE RT_BIT(7)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/** File is optional, does not have to be
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * existent on the .ISO. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#define UPDATEFILE_FLAG_OPTIONAL RT_BIT(8)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync// session task classes
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/////////////////////////////////////////////////////////////////////////////
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncGuestSessionTask::GuestSessionTask(GuestSession *pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSession = pSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncGuestSessionTask::~GuestSessionTask(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncint GuestSessionTask::getGuestProperty(const ComObjPtr<Guest> &pGuest,
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync const Utf8Str &strPath, Utf8Str &strValue)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync ComObjPtr<Console> pConsole = pGuest->getConsole();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync const ComPtr<IMachine> pMachine = pConsole->machine();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync Assert(!pMachine.isNull());
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync Bstr strTemp, strFlags;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync LONG64 i64Timestamp;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync HRESULT hr = pMachine->GetGuestProperty(Bstr(strPath).raw(),
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync strTemp.asOutParam(),
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync &i64Timestamp, strFlags.asOutParam());
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (SUCCEEDED(hr))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync strValue = strTemp;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return VINF_SUCCESS;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return VERR_NOT_FOUND;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync}
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint GuestSessionTask::setProgress(ULONG uPercent)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (mProgress.isNull()) /* Progress is optional. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && fCanceled)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_CANCELLED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCompleted;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
ffb50166c9adb4ae583b914d405197035cf890advboxsync && fCompleted)
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync AssertMsgFailed(("Setting value of an already completed progress\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HRESULT hr = mProgress->SetCurrentOperationProgress(uPercent);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(hr))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_COM_UNEXPECTED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint GuestSessionTask::setProgressSuccess(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (mProgress.isNull()) /* Progress is optional. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCompleted;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && !fCanceled
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && !fCompleted)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HRESULT hr = mProgress->notifyComplete(S_OK);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(hr))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_COM_UNEXPECTED; /** @todo Find a better rc. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncHRESULT GuestSessionTask::setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (mProgress.isNull()) /* Progress is optional. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return hr; /* Return original rc. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCompleted;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && !fCanceled
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && !fCompleted)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HRESULT hr2 = mProgress->notifyComplete(hr,
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync COM_IIDOF(IGuestSession),
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync GuestSession::getStaticComponentName(),
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync strMsg.c_str());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(hr2))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return hr2;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return hr; /* Return original rc. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync : GuestSessionTask(pSession),
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync mSource(strSource),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceFile(NULL),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceOffset(0),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceSize(0),
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync mDest(strDest)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mCopyFileFlags = uFlags;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @todo Merge this and the above call and let the above call do the open/close file handling so that the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * inner code only has to deal with file handles. No time now ... */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync const Utf8Str &strDest, uint32_t uFlags)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync : GuestSessionTask(pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceFile = pSourceFile;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceOffset = cbSourceOffset;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceSize = cbSourceSize;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDest = strDest;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mCopyFileFlags = uFlags;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskCopyTo::~SessionTaskCopyTo(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyTo::Run(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFuncEnter();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestSession> pSession = mSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(!pSession.isNull());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AutoCaller autoCaller(pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (mCopyFileFlags)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Copy flags (%#x) not implemented yet"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mCopyFileFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFILE fileLocal;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PRTFILE pFile = &fileLocal;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!mSourceFile)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Does our source file exist? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!RTFileExists(mSource.c_str()))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Source file \"%s\" does not exist or is not a file"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileOpen(pFile, mSource.c_str(),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Could not open source file \"%s\" for reading: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileGetSize(*pFile, &mSourceSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Could not query file size of \"%s\": %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pFile = mSourceFile;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Size + offset are optional. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestProcessStartupInfo procInfo;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" to the guest to \"%s\" (%RU64 bytes)"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), mDest.c_str(), mSourceSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mFlags = ProcessCreateFlag_Hidden;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Set arguments.*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mArguments.push_back(Utf8StrFmt("--output=%s", mDest.c_str())); /** @todo Do we need path conversion? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Startup process. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestProcess> pProcess;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->startProcess();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Unable to start guest process: %Rrc"), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestProcessWaitResult waitRes;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BYTE byBuf[_64K];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled = FALSE;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint64_t cbWrittenTotal = 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint64_t cbToRead = mSourceSize;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync for (;;)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_StdIn,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 30 * 1000 /* Timeout */, waitRes);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( RT_FAILURE(rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ( waitRes.mResult != ProcessWaitResult_StdIn
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && waitRes.mResult != ProcessWaitResult_WaitFlagNotSupported))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If the guest does not support waiting for stdin, we now yield in
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * order to reduce the CPU load due to busy waiting. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTThreadYield(); /* Optional, don't check rc. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync size_t cbRead = 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (mSourceSize) /* If we have nothing to write, take a shortcut. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo Not very efficient, but works for now. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileSeek(*pFile, mSourceOffset + cbWrittenTotal,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFILE_SEEK_BEGIN, NULL /* poffActual */);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileRead(*pFile, (uint8_t*)byBuf,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RT_MIN(cbToRead, sizeof(byBuf)), &cbRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Some other error occured? There might be a chance that RTFileRead
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * could not resolve/map the native error code to an IPRT code, so just
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * print a generic error.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Could not read from file \"%s\" (%Rrc)"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Seeking file \"%s\" offset %RU64 failed: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), cbWrittenTotal, rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint32_t fFlags = ProcessInputFlag_None;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Did we reach the end of the content we want to transfer (last chunk)? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( (cbRead < sizeof(byBuf))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Did we reach the last block which is exactly _64K? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || (cbToRead - cbRead == 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* ... or does the user want to cancel? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && fCanceled)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync )
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync fFlags |= ProcessInputFlag_EndOfFile;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint32_t cbWritten;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(sizeof(byBuf) >= cbRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->writeData(0 /* StdIn */, fFlags,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync byBuf, cbRead,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 30 * 1000 /* Timeout */, &cbWritten);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Writing to file \"%s\" (offset %RU64) failed: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDest.c_str(), cbWrittenTotal, rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFunc(("cbWritten=%RU32, cbToRead=%RU64, cbWrittenTotal=%RU64, cbFileSize=%RU64\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbWritten, cbToRead - cbWritten, cbWrittenTotal + cbWritten, mSourceSize));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Only subtract bytes reported written by the guest. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbToRead >= cbWritten);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbToRead -= cbWritten;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Update total bytes written to the guest. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbWrittenTotal += cbWritten;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbWrittenTotal <= mSourceSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Did the user cancel the operation above? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (fCanceled)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Update the progress.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Watch out for division by zero. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSourceSize > 0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ? rc = setProgress((ULONG)(cbWrittenTotal * 100 / mSourceSize))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync : rc = setProgress(100);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* End of file reached? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!cbToRead)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync } /* for */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( !fCanceled
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Even if we succeeded until here make sure to check whether we really transfered
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * everything.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( mSourceSize > 0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && cbWrittenTotal == 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * to the destination -> access denied. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), mDest.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if (cbWrittenTotal < mSourceSize)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If we did not copy all let the user know. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RU64 bytes transfered)"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), cbWrittenTotal, mSourceSize));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 30 * 1000 /* Timeout */, waitRes);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( RT_FAILURE(rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || waitRes.mResult != ProcessWaitResult_Terminate)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed with wait result %ld"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), waitRes.mResult));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ProcessStatus_T procStatus;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LONG exitCode;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && procStatus != ProcessStatus_TerminatedNormally)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && exitCode != 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync )
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %ld"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressSuccess();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (!pProcess.isNull())
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pProcess->uninit();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync } /* processCreateExInteral */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!mSourceFile) /* Only close locally opened files. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFileClose(*pFile);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyTo::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, mCopyFileFlags=%x\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mCopyFileFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDesc = strDesc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mProgress = pProgress;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyTo::taskThread, this,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "gctlCpyTo");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* static */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyTo::taskThread(RTTHREAD Thread, void *pvUser)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync std::auto_ptr<SessionTaskCopyTo> task(static_cast<SessionTaskCopyTo*>(pvUser));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFunc(("pTask=%p\n", task.get()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return task->Run();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskCopyFrom::SessionTaskCopyFrom(GuestSession *pSession,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync : GuestSessionTask(pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource = strSource;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDest = strDest;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mFlags = uFlags;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskCopyFrom::~SessionTaskCopyFrom(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyFrom::Run(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFuncEnter();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestSession> pSession = mSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(!pSession.isNull());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AutoCaller autoCaller(pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Note: There will be races between querying file size + reading the guest file's
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * content because we currently *do not* lock down the guest file when doing the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * actual operations.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ** @todo Implement guest file locking!
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestFsObjData objData;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = pSession->fileQueryInfoInternal(Utf8Str(mSource), objData);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Querying guest file information for \"%s\" failed: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if (objData.mType != FsObjType_File) /* Only single files are supported at the moment. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Object \"%s\" on the guest is not a file"), mSource.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFILE fileDest;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileOpen(&fileDest, mDest.c_str(),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); /** @todo Use the correct open modes! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Error opening destination file \"%s\": %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDest.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestProcessStartupInfo procInfo;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" from guest to the host to \"%s\" (%RI64 bytes)"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), mDest.c_str(), objData.mObjectSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mFlags = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Set arguments.*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mArguments.push_back(mSource); /* Which file to output? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Startup process. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestProcess> pProcess;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->startProcess();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Unable to start guest process for copying data from guest to host: %Rrc"), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestProcessWaitResult waitRes;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BYTE byBuf[_64K];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled = FALSE;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint64_t cbWrittenTotal = 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint64_t cbToRead = objData.mObjectSize;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync for (;;)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 30 * 1000 /* Timeout */, waitRes);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( waitRes.mResult == ProcessWaitResult_StdOut
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If the guest does not support waiting for stdin, we now yield in
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * order to reduce the CPU load due to busy waiting. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (waitRes.mResult == ProcessWaitResult_WaitFlagNotSupported)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTThreadYield(); /* Optional, don't check rc. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync size_t cbRead;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync &cbRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Reading from file \"%s\" (offset %RU64) failed: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), cbWrittenTotal, rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (cbRead)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileWrite(fileDest, byBuf, cbRead, NULL /* No partial writes */);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Error writing to file \"%s\" (%RU64 bytes left): %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDest.c_str(), cbToRead, rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Only subtract bytes reported written by the guest. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbToRead >= cbRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbToRead -= cbRead;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Update total bytes written to the guest. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbWrittenTotal += cbRead;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbWrittenTotal <= (uint64_t)objData.mObjectSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Did the user cancel the operation above? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && fCanceled)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgress((ULONG)(cbWrittenTotal / ((uint64_t)objData.mObjectSize / 100.0)));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if ( RT_FAILURE(rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || waitRes.mResult == ProcessWaitResult_Terminate
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || waitRes.mResult == ProcessWaitResult_Error
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || waitRes.mResult == ProcessWaitResult_Timeout)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(waitRes.mRC))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = waitRes.mRC;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync } /* for */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFunc(("rc=%Rrc, cbWrittenTotal=%RU64, cbSize=%RI64, cbToRead=%RU64\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc, cbWrittenTotal, objData.mObjectSize, cbToRead));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( !fCanceled
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Even if we succeeded until here make sure to check whether we really transfered
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * everything.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( objData.mObjectSize > 0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && cbWrittenTotal == 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * to the destination -> access denied. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), mDest.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if (cbWrittenTotal < (uint64_t)objData.mObjectSize)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* If we did not copy all let the user know. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RI64 bytes transfered)"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), cbWrittenTotal, objData.mObjectSize));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ProcessStatus_T procStatus;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LONG exitCode;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && procStatus != ProcessStatus_TerminatedNormally)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && exitCode != 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync )
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %d"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else /* Yay, success! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = setProgressSuccess();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (!pProcess.isNull())
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pProcess->uninit();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTFileClose(fileDest);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyFrom::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDesc = strDesc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mProgress = pProgress;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyFrom::taskThread, this,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "gctlCpyFrom");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* static */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskCopyFrom::taskThread(RTTHREAD Thread, void *pvUser)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync std::auto_ptr<SessionTaskCopyFrom> task(static_cast<SessionTaskCopyFrom*>(pvUser));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFunc(("pTask=%p\n", task.get()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return task->Run();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskUpdateAdditions::SessionTaskUpdateAdditions(GuestSession *pSession,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync const Utf8Str &strSource, uint32_t uFlags)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync : GuestSessionTask(pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource = strSource;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mFlags = uFlags;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncSessionTaskUpdateAdditions::~SessionTaskUpdateAdditions(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskUpdateAdditions::copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8Str const &strFileSource, const Utf8Str &strFileDest,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync bool fOptional, uint32_t *pcbSize)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertPtrReturn(pSession, VERR_INVALID_POINTER);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertPtrReturn(pISO, VERR_INVALID_POINTER);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* pcbSize is optional. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint32_t cbOffset;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync size_t cbSize;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = RTIsoFsGetFileInfo(pISO, strFileSource.c_str(), &cbOffset, &cbSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (fOptional)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbOffset);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(cbSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTFileSeek(pISO->file, cbOffset, RTFILE_SEEK_BEGIN, NULL);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Copy over the Guest Additions file to the guest. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("Copying Guest Additions installer file \"%s\" to \"%s\" on guest ...\n",
ffb50166c9adb4ae583b914d405197035cf890advboxsync strFileSource.c_str(), strFileDest.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SessionTaskCopyTo *pTask = new SessionTaskCopyTo(pSession /* GuestSession */,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync &pISO->file, cbOffset, cbSize,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync strFileDest, CopyFileFlag_None);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertPtrReturn(pTask, VERR_NO_MEMORY);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<Progress> pProgressCopyTo;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pSession->startTaskAsync(Utf8StrFmt(GuestSession::tr("Copying Guest Additions installer file \"%s\" to \"%s\" on guest"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), strFileDest.c_str()),
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync pTask, pProgressCopyTo);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync BOOL fCanceled = FALSE;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HRESULT hr = pProgressCopyTo->WaitForCompletion(-1);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( SUCCEEDED(pProgressCopyTo->COMGETTER(Canceled)(&fCanceled))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && fCanceled)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if (FAILED(hr))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(FAILED(hr));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo Note: Since there is no file locking involved at the moment, there can be modifications
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * between finished copying, the verification and the actual execution. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Determine where the installer image ended up and if it has the correct size. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("Verifying Guest Additions installer file \"%s\" ...\n",
ffb50166c9adb4ae583b914d405197035cf890advboxsync strFileDest.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestFsObjData objData;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int64_t cbSizeOnGuest;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pSession->fileQuerySizeInternal(strFileDest, &cbSizeOnGuest);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( RT_SUCCESS(rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && cbSize == (uint64_t)cbSizeOnGuest)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("Guest Additions installer file \"%s\" successfully verified\n",
ffb50166c9adb4ae583b914d405197035cf890advboxsync strFileDest.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc)) /* Size does not match. */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("Size of Guest Additions installer file \"%s\" does not match: %RI64bytes copied, %RU64bytes expected\n",
ffb50166c9adb4ae583b914d405197035cf890advboxsync strFileDest.c_str(), cbSizeOnGuest, cbSize));
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync rc = VERR_BROKEN_PIPE; /** @todo Find a better error. */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync else
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("Error copying Guest Additions installer file \"%s\": %Rrc\n",
ffb50166c9adb4ae583b914d405197035cf890advboxsync strFileDest.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pcbSize)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *pcbSize = cbSizeOnGuest;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncint SessionTaskUpdateAdditions::runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertPtrReturn(pSession, VERR_INVALID_POINTER);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestProcess> pProcess;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync int rc = pSession->processCreateExInteral(procInfo, pProcess);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->startProcess();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync LogRel(("Running %s ...\n", procInfo.mName.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GuestProcessWaitResult waitRes;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 10 * 60 * 1000 /* 10 mins Timeout */, waitRes);
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync LogFlowThisFunc(("waitFor rc=%Rrc, waitRes=%ld\n", rc, waitRes));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (waitRes.mResult == ProcessWaitResult_Terminate)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ProcessStatus_T procStatus;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LONG exitCode;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && procStatus != ProcessStatus_TerminatedNormally)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && exitCode != 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync )
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Running %s failed with status %ld, exit code %ld"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mName.c_str(), procStatus, exitCode));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else /* Yay, success! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlowThisFunc(("%s successfully completed\n", procInfo.mName.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync /** @todo Unify error handling. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Error while waiting running %s: %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync procInfo.mName.c_str(), rc));
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync if (pProcess->errorMsg().isEmpty())
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync {
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync Utf8StrFmt(GuestSession::tr("Running %s returned unexpectedly with status %ld"),
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync procInfo.mName.c_str(), waitRes.mResult));
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync }
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync else
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR, pProcess->errorMsg());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!pProcess.isNull())
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pProcess->uninit();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskUpdateAdditions::Run(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFuncEnter();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ComObjPtr<GuestSession> pSession = mSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(!pSession.isNull());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AutoCaller autoCaller(pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = setProgress(10);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HRESULT hr = S_OK;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("Automatic update of Guest Additions started, using \"%s\"\n", mSource.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync ComObjPtr<Guest> pGuest(mSession->getParent());
0dd3967035b8a02985920baa57f948dc542b9388vboxsync#if 0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Wait for the guest being ready within 30 seconds.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync AdditionsRunLevelType_T addsRunLevel;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync uint64_t tsStart = RTTimeSystemMilliTS();
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync while ( SUCCEEDED(hr = pGuest->COMGETTER(AdditionsRunLevel)(&addsRunLevel))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync && ( addsRunLevel != AdditionsRunLevelType_Userland
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync && addsRunLevel != AdditionsRunLevelType_Desktop))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ((RTTimeSystemMilliTS() - tsStart) > 30 * 1000)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = VERR_TIMEOUT;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync break;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync RTThreadSleep(100); /* Wait a bit. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (FAILED(hr)) rc = VERR_TIMEOUT;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (rc == VERR_TIMEOUT)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8StrFmt(GuestSession::tr("Guest Additions were not ready within time, giving up")));
0dd3967035b8a02985920baa57f948dc542b9388vboxsync#else
0dd3967035b8a02985920baa57f948dc542b9388vboxsync /*
0dd3967035b8a02985920baa57f948dc542b9388vboxsync * For use with the GUI we don't want to wait, just return so that the manual .ISO mounting
0dd3967035b8a02985920baa57f948dc542b9388vboxsync * can continue.
0dd3967035b8a02985920baa57f948dc542b9388vboxsync */
0dd3967035b8a02985920baa57f948dc542b9388vboxsync AdditionsRunLevelType_T addsRunLevel;
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if ( FAILED(hr = pGuest->COMGETTER(AdditionsRunLevel)(&addsRunLevel))
0dd3967035b8a02985920baa57f948dc542b9388vboxsync || ( addsRunLevel != AdditionsRunLevelType_Userland
0dd3967035b8a02985920baa57f948dc542b9388vboxsync && addsRunLevel != AdditionsRunLevelType_Desktop))
0dd3967035b8a02985920baa57f948dc542b9388vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if (addsRunLevel == AdditionsRunLevelType_System)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Utf8StrFmt(GuestSession::tr("Guest Additions are installed but not fully loaded yet, aborting automatic update")));
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync else
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Utf8StrFmt(GuestSession::tr("Guest Additions not installed or ready, aborting automatic update")));
0dd3967035b8a02985920baa57f948dc542b9388vboxsync rc = VERR_NOT_SUPPORTED;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync }
0dd3967035b8a02985920baa57f948dc542b9388vboxsync#endif
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_SUCCESS(rc))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Determine if we are able to update automatically. This only works
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * if there are recent Guest Additions installed already.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8Str strAddsVer;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/Version", strAddsVer);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( RT_SUCCESS(rc)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync && RTStrVersionCompare(strAddsVer.c_str(), "4.1") < 0)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8StrFmt(GuestSession::tr("Guest has too old Guest Additions (%s) installed for automatic updating, please update manually"),
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strAddsVer.c_str()));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = VERR_NOT_SUPPORTED;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
0dd3967035b8a02985920baa57f948dc542b9388vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync Utf8Str strOSVer;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync eOSType osType;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (RT_SUCCESS(rc))
0dd3967035b8a02985920baa57f948dc542b9388vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Determine guest OS type and the required installer image.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8Str strOSType;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestInfo/OS/Product", strOSType);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_SUCCESS(rc))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( strOSType.contains("Microsoft", Utf8Str::CaseInsensitive)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || strOSType.contains("Windows", Utf8Str::CaseInsensitive))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync osType = eOSType_Windows;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync /*
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync * Determine guest OS version.
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync */
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestInfo/OS/Release", strOSVer);
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (RT_FAILURE(rc))
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync {
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync Utf8StrFmt(GuestSession::tr("Unable to detected guest OS version, please update manually")));
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync rc = VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync }
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync /* Because Windows 2000 + XP and is bitching with WHQL popups even if we have signed drivers we
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync * can't do automated updates here. */
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if ( RT_SUCCESS(rc)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync && ( strOSVer.contains("5.0") /* Exclude the build number. */
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync || strOSVer.contains("5.1")) /* Exclude the build number. */
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync )
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync {
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync Utf8StrFmt(GuestSession::tr("Windows 2000 and XP are not supported for automatic updating due to WHQL popups, please update manually")));
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync rc = VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync else if (strOSType.contains("Solaris", Utf8Str::CaseInsensitive))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync osType = eOSType_Solaris;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync else /* Everything else hopefully means Linux :-). */
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync osType = eOSType_Linux;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#if 1 /* Only Windows is supported (and tested) at the moment. */
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync if (osType != eOSType_Windows)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8StrFmt(GuestSession::tr("Detected guest OS (%s) does not support automatic Guest Additions updating, please update manually"),
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strOSType.c_str()));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = VERR_NOT_SUPPORTED;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#endif
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTISOFSFILE iso;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Try to open the .ISO file to extract all needed files.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = RTIsoFsOpen(&iso, mSource.c_str());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Utf8StrFmt(GuestSession::tr("Unable to open Guest Additions .ISO file \"%s\": %Rrc"),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mSource.c_str(), rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /* Set default installation directories. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8Str strUpdateDir = "/tmp/";
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync if (osType == eOSType_Windows)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir = "C:\\Temp\\";
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync rc = setProgress(5);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /* Try looking up the Guest Additions installation directory. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Try getting the installed Guest Additions version to know whether we
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * can install our temporary Guest Addition data into the original installation
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * directory.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Because versions prior to 4.2 had bugs wrt spaces in paths we have to choose
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * a different location then.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync bool fUseInstallDir = false;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Utf8Str strAddsVer;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/Version", strAddsVer);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( RT_SUCCESS(rc)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync && RTStrVersionCompare(strAddsVer.c_str(), "4.2") >= 0)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync fUseInstallDir = true;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (fUseInstallDir)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_SUCCESS(rc))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/InstallDir", strUpdateDir);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync if (osType == eOSType_Windows)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir.findReplace('/', '\\');
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir.append("\\Update\\");
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync else
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir.append("/update/");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_SUCCESS(rc))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync LogRel(("Guest Additions update directory is: %s\n",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir.c_str()));
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* Create the installation directory. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = pSession->directoryCreateInternal(strUpdateDir,
ffb50166c9adb4ae583b914d405197035cf890advboxsync 755 /* Mode */, DirectoryCreateFlag_Parents);
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_FAILURE(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
ffb50166c9adb4ae583b914d405197035cf890advboxsync Utf8StrFmt(GuestSession::tr("Error creating installation directory \"%s\" on the guest: %Rrc"),
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir.c_str(), rc));
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_SUCCESS(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = setProgress(10);
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* Prepare the file(s) we want to copy over to the guest and
ffb50166c9adb4ae583b914d405197035cf890advboxsync * (maybe) want to run. */
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync switch (osType)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync case eOSType_Windows:
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Do we need to install our certificates? We do this for W2K and up. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync bool fInstallCert = false;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync /* Only Windows 2000 and up need certificates to be installed. */
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (RTStrVersionCompare(strOSVer.c_str(), "5.0") >= 0)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync fInstallCert = true;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync LogRel(("Certificates for auto updating WHQL drivers will be installed\n"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync else
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync LogRel(("Skipping installation of certificates for WHQL drivers\n"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (fInstallCert)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Our certificate. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync mFiles.push_back(InstallerFile("CERT/ORACLE_VBOX.CER",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "oracle-vbox.cer",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_OPTIONAL));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Our certificate installation utility. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* First pass: Copy over the file + execute it to remove any existing
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * VBox certificates. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync GuestProcessStartupInfo siCertUtilRem;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync siCertUtilRem.mName = "VirtualBox Certificate Utility, removing old VirtualBox certificates";
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilRem.mArguments.push_back(Utf8Str("remove-trusted-publisher"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilRem.mArguments.push_back(Utf8Str("--root")); /* Add root certificate as well. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilRem.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilRem.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync mFiles.push_back(InstallerFile("CERT/VBOXCERTUTIL.EXE",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "VBoxCertUtil.exe",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_EXECUTE | UPDATEFILE_FLAG_OPTIONAL,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilRem));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Second pass: Only execute (but don't copy) again, this time installng the
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * recent certificates just copied over. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync GuestProcessStartupInfo siCertUtilAdd;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync siCertUtilAdd.mName = "VirtualBox Certificate Utility, installing VirtualBox certificates";
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str("add-trusted-publisher"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str("--root")); /* Add root certificate as well. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync mFiles.push_back(InstallerFile("CERT/VBOXCERTUTIL.EXE",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "VBoxCertUtil.exe",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_EXECUTE | UPDATEFILE_FLAG_OPTIONAL,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siCertUtilAdd));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* The installers in different flavors, as we don't know (and can't assume)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * the guest's bitness. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_X86.EXE",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "VBoxWindowsAdditions-x86.exe",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO));
ffb50166c9adb4ae583b914d405197035cf890advboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_AMD64.EXE",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "VBoxWindowsAdditions-amd64.exe",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* The stub loader which decides which flavor to run. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync GuestProcessStartupInfo siInstaller;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync siInstaller.mName = "VirtualBox Windows Guest Additions Installer";
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync /* Set a running timeout of 5 minutes -- the Windows Guest Additions
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync * setup can take quite a while, so be on the safe side. */
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync siInstaller.mTimeoutMS = 5 * 60 * 1000;
ffb50166c9adb4ae583b914d405197035cf890advboxsync siInstaller.mArguments.push_back(Utf8Str("/S")); /* We want to install in silent mode. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync siInstaller.mArguments.push_back(Utf8Str("/l")); /* ... and logging enabled. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* Don't quit VBoxService during upgrade because it still is used for this
ffb50166c9adb4ae583b914d405197035cf890advboxsync * piece of code we're in right now (that is, here!) ... */
ffb50166c9adb4ae583b914d405197035cf890advboxsync siInstaller.mArguments.push_back(Utf8Str("/no_vboxservice_exit"));
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* Tell the installer to report its current installation status
ffb50166c9adb4ae583b914d405197035cf890advboxsync * using a running VBoxTray instance via balloon messages in the
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Windows taskbar. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync siInstaller.mArguments.push_back(Utf8Str("/post_installstatus"));
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* If the caller does not want to wait for out guest update process to end,
ffb50166c9adb4ae583b914d405197035cf890advboxsync * complete the progress object now so that the caller can do other work. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (mFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly)
ffb50166c9adb4ae583b914d405197035cf890advboxsync siInstaller.mFlags |= ProcessCreateFlag_WaitForProcessStartOnly;
ffb50166c9adb4ae583b914d405197035cf890advboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS.EXE",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync strUpdateDir + "VBoxWindowsAdditions.exe",
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_EXECUTE, siInstaller));
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync case eOSType_Linux:
ffb50166c9adb4ae583b914d405197035cf890advboxsync /** @todo Add Linux support. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
ffb50166c9adb4ae583b914d405197035cf890advboxsync case eOSType_Solaris:
ffb50166c9adb4ae583b914d405197035cf890advboxsync /** @todo Add Solaris support. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
ffb50166c9adb4ae583b914d405197035cf890advboxsync default:
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync AssertReleaseMsgFailed(("Unsupported guest type: %d\n", osType));
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* We want to spend 40% total for all copying operations. So roughly
ffb50166c9adb4ae583b914d405197035cf890advboxsync * calculate the specific percentage step of each copied file. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync uint8_t uOffset = 20; /* Start at 20%. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync uint8_t uStep = 40 / mFiles.size();
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogRel(("Copying over Guest Additions update files to the guest ...\n"));
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync std::vector<InstallerFile>::const_iterator itFiles = mFiles.begin();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync while (itFiles != mFiles.end())
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_COPY_FROM_ISO)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync bool fOptional = false;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_OPTIONAL)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync fOptional = true;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = copyFileToGuest(pSession, &iso, itFiles->strSource, itFiles->strDest,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync fOptional, NULL /* cbSize */);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (RT_FAILURE(rc))
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync Utf8StrFmt(GuestSession::tr("Error while copying file \"%s\" to \"%s\" on the guest: %Rrc"),
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync itFiles->strSource.c_str(), itFiles->strDest.c_str(), rc));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync break;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = setProgress(uOffset);
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_FAILURE(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
ffb50166c9adb4ae583b914d405197035cf890advboxsync uOffset += uStep;
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync itFiles++;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Done copying, close .ISO file. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync RTIsoFsClose(&iso);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* We want to spend 35% total for all copying operations. So roughly
ffb50166c9adb4ae583b914d405197035cf890advboxsync * calculate the specific percentage step of each copied file. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync uint8_t uOffset = 60; /* Start at 60%. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync uint8_t uStep = 35 / mFiles.size();
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogRel(("Executing Guest Additions update files ...\n"));
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync std::vector<InstallerFile>::iterator itFiles = mFiles.begin();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync while (itFiles != mFiles.end())
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_EXECUTE)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = runFileOnGuest(pSession, itFiles->mProcInfo);
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_FAILURE(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = setProgress(uOffset);
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_FAILURE(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync break;
ffb50166c9adb4ae583b914d405197035cf890advboxsync uOffset += uStep;
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync itFiles++;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (RT_SUCCESS(rc))
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogRel(("Automatic update of Guest Additions succeeded\n"));
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = setProgressSuccess();
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if (RT_FAILURE(rc))
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if (rc == VERR_CANCELLED)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync LogRel(("Automatic update of Guest Additions was canceled\n"));
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Utf8StrFmt(GuestSession::tr("Installation was canceled")));
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync else
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Utf8Str strError = Utf8StrFmt("No further error information available (%Rrc)", rc);
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if (!mProgress.isNull()) /* Progress object is optional. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync ComPtr<IVirtualBoxErrorInfo> pError;
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync hr = mProgress->COMGETTER(ErrorInfo)(pError.asOutParam());
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Assert(!pError.isNull());
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if (SUCCEEDED(hr))
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync Bstr strVal;
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync hr = pError->COMGETTER(Text)(strVal.asOutParam());
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if ( SUCCEEDED(hr)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync && strVal.isNotEmpty())
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync strError = strVal;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync LogRel(("Automatic update of Guest Additions failed: %s\n", strError.c_str()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync LogRel(("Please install Guest Additions manually\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskUpdateAdditions::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, uFlags=%x\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync strDesc.c_str(), mSource.c_str(), mFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mDesc = strDesc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync mProgress = pProgress;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = RTThreadCreate(NULL, SessionTaskUpdateAdditions::taskThread, this,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "gctlUpGA");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFuncLeaveRC(rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* static */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncint SessionTaskUpdateAdditions::taskThread(RTTHREAD Thread, void *pvUser)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync std::auto_ptr<SessionTaskUpdateAdditions> task(static_cast<SessionTaskUpdateAdditions*>(pvUser));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlowFunc(("pTask=%p\n", task.get()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return task->Run();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync