From 13c3f7ac2b563596a74811590239ebee535a0889 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 12 Jun 2015 15:06:59 +0200 Subject: [PATCH] qmgr: Implement IBackgroundCopyJob::Cancel. --- dlls/qmgr/file.c | 1 + dlls/qmgr/job.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c index a5a41d1c655..0321ab63c72 100644 --- a/dlls/qmgr/file.c +++ b/dlls/qmgr/file.c @@ -201,6 +201,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner, This->fileProgress.Completed = FALSE; This->owner = owner; This->read_size = 0; + This->tempFileName[0] = 0; IBackgroundCopyJob3_AddRef(&owner->IBackgroundCopyJob3_iface); *file = This; diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c index bf484808b10..37ef5f9615d 100644 --- a/dlls/qmgr/job.c +++ b/dlls/qmgr/job.c @@ -259,6 +259,9 @@ static ULONG WINAPI BackgroundCopyJob_Release(IBackgroundCopyJob3 *iface) HeapFree(GetProcessHeap(), 0, cred->Credentials.Basic.Password); } } + CloseHandle(This->wait); + CloseHandle(This->cancel); + CloseHandle(This->done); HeapFree(GetProcessHeap(), 0, This); } @@ -365,8 +368,48 @@ static HRESULT WINAPI BackgroundCopyJob_Cancel( IBackgroundCopyJob3 *iface) { BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob3(iface); - FIXME("(%p): stub\n", This); - return E_NOTIMPL; + HRESULT rv = S_OK; + + TRACE("(%p)\n", This); + + EnterCriticalSection(&This->cs); + + if (is_job_done(This)) + { + rv = BG_E_INVALID_STATE; + } + else + { + BackgroundCopyFileImpl *file; + + if (This->state == BG_JOB_STATE_CONNECTING || This->state == BG_JOB_STATE_TRANSFERRING) + { + This->state = BG_JOB_STATE_CANCELLED; + SetEvent(This->cancel); + + LeaveCriticalSection(&This->cs); + WaitForSingleObject(This->done, INFINITE); + EnterCriticalSection(&This->cs); + } + + LIST_FOR_EACH_ENTRY(file, &This->files, BackgroundCopyFileImpl, entryFromJob) + { + if (file->tempFileName[0] && !DeleteFileW(file->tempFileName)) + { + WARN("Couldn't delete %s (%u)\n", debugstr_w(file->tempFileName), GetLastError()); + rv = BG_S_UNABLE_TO_DELETE_FILES; + } + if (file->info.LocalName && !DeleteFileW(file->info.LocalName)) + { + WARN("Couldn't delete %s (%u)\n", debugstr_w(file->info.LocalName), GetLastError()); + rv = BG_S_UNABLE_TO_DELETE_FILES; + } + } + This->state = BG_JOB_STATE_CANCELLED; + } + + LeaveCriticalSection(&This->cs); + return rv; } static HRESULT WINAPI BackgroundCopyJob_Complete( @@ -1193,6 +1236,10 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID memset(&This->http_options, 0, sizeof(This->http_options)); + This->wait = CreateEventW(NULL, FALSE, FALSE, NULL); + This->cancel = CreateEventW(NULL, FALSE, FALSE, NULL); + This->done = CreateEventW(NULL, FALSE, FALSE, NULL); + *job = This; TRACE("created job %s:%p\n", debugstr_guid(&This->jobId), This);