2008-02-27 02:50:43 +01:00
|
|
|
/*
|
|
|
|
* Queue Manager (BITS) File
|
|
|
|
*
|
2008-03-13 23:57:19 +01:00
|
|
|
* Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
|
2008-02-27 02:50:43 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-03-13 23:57:19 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-03-13 23:57:54 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2008-03-13 23:57:19 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "urlmon.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
|
2008-02-27 02:50:43 +01:00
|
|
|
#include "qmgr.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
static inline BackgroundCopyFileImpl *impl_from_IBackgroundCopyFile(IBackgroundCopyFile *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BackgroundCopyFileImpl, IBackgroundCopyFile_iface);
|
|
|
|
}
|
|
|
|
|
2008-02-27 02:50:43 +01:00
|
|
|
static HRESULT WINAPI BITS_IBackgroundCopyFile_QueryInterface(
|
|
|
|
IBackgroundCopyFile* iface,
|
|
|
|
REFIID riid,
|
2013-01-18 05:38:49 +01:00
|
|
|
void **obj)
|
2008-02-27 02:50:43 +01:00
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
2008-02-27 02:50:43 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IBackgroundCopyFile))
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
*obj = iface;
|
|
|
|
IBackgroundCopyFile_AddRef(iface);
|
2008-02-27 02:50:43 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
*obj = NULL;
|
2008-02-27 02:50:43 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
static ULONG WINAPI BITS_IBackgroundCopyFile_AddRef(IBackgroundCopyFile* iface)
|
|
|
|
{
|
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
2008-02-27 02:50:43 +01:00
|
|
|
|
|
|
|
static ULONG WINAPI BITS_IBackgroundCopyFile_Release(
|
|
|
|
IBackgroundCopyFile* iface)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
2008-02-27 02:50:43 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
2008-02-27 02:50:43 +01:00
|
|
|
if (ref == 0)
|
2013-01-18 05:39:15 +01:00
|
|
|
{
|
|
|
|
IBackgroundCopyJob2_Release(&This->owner->IBackgroundCopyJob2_iface);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->info.LocalName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2008-02-27 02:50:43 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2008-02-29 03:59:26 +01:00
|
|
|
/* Get the remote name of a background copy file */
|
2008-02-27 02:50:43 +01:00
|
|
|
static HRESULT WINAPI BITS_IBackgroundCopyFile_GetRemoteName(
|
|
|
|
IBackgroundCopyFile* iface,
|
|
|
|
LPWSTR *pVal)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
2008-02-29 03:59:26 +01:00
|
|
|
int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
*pVal = CoTaskMemAlloc(n);
|
|
|
|
if (!*pVal)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memcpy(*pVal, This->info.RemoteName, n);
|
|
|
|
return S_OK;
|
2008-02-27 02:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
|
|
|
|
IBackgroundCopyFile* iface,
|
|
|
|
LPWSTR *pVal)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
2008-02-29 03:59:26 +01:00
|
|
|
int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
*pVal = CoTaskMemAlloc(n);
|
|
|
|
if (!*pVal)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memcpy(*pVal, This->info.LocalName, n);
|
|
|
|
return S_OK;
|
2008-02-27 02:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
|
|
|
|
IBackgroundCopyFile* iface,
|
|
|
|
BG_FILE_PROGRESS *pVal)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
|
2008-02-29 04:00:12 +01:00
|
|
|
|
2008-03-12 19:56:13 +01:00
|
|
|
EnterCriticalSection(&This->owner->cs);
|
2008-02-29 04:00:12 +01:00
|
|
|
pVal->BytesTotal = This->fileProgress.BytesTotal;
|
|
|
|
pVal->BytesTransferred = This->fileProgress.BytesTransferred;
|
|
|
|
pVal->Completed = This->fileProgress.Completed;
|
2008-03-12 19:56:13 +01:00
|
|
|
LeaveCriticalSection(&This->owner->cs);
|
2008-02-29 04:00:12 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2008-02-27 02:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IBackgroundCopyFileVtbl BITS_IBackgroundCopyFile_Vtbl =
|
|
|
|
{
|
|
|
|
BITS_IBackgroundCopyFile_QueryInterface,
|
|
|
|
BITS_IBackgroundCopyFile_AddRef,
|
|
|
|
BITS_IBackgroundCopyFile_Release,
|
|
|
|
BITS_IBackgroundCopyFile_GetRemoteName,
|
|
|
|
BITS_IBackgroundCopyFile_GetLocalName,
|
|
|
|
BITS_IBackgroundCopyFile_GetProgress
|
|
|
|
};
|
|
|
|
|
2008-03-12 19:56:13 +01:00
|
|
|
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
|
|
|
|
LPCWSTR remoteName, LPCWSTR localName,
|
2013-01-18 05:38:49 +01:00
|
|
|
BackgroundCopyFileImpl **file)
|
2008-02-27 02:50:43 +01:00
|
|
|
{
|
|
|
|
BackgroundCopyFileImpl *This;
|
|
|
|
int n;
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
TRACE("(%s, %s, %p)\n", debugstr_w(remoteName), debugstr_w(localName), file);
|
2008-02-27 02:50:43 +01:00
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
n = (lstrlenW(remoteName) + 1) * sizeof(WCHAR);
|
|
|
|
This->info.RemoteName = HeapAlloc(GetProcessHeap(), 0, n);
|
|
|
|
if (!This->info.RemoteName)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy(This->info.RemoteName, remoteName, n);
|
|
|
|
|
|
|
|
n = (lstrlenW(localName) + 1) * sizeof(WCHAR);
|
|
|
|
This->info.LocalName = HeapAlloc(GetProcessHeap(), 0, n);
|
|
|
|
if (!This->info.LocalName)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy(This->info.LocalName, localName, n);
|
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
This->IBackgroundCopyFile_iface.lpVtbl = &BITS_IBackgroundCopyFile_Vtbl;
|
2008-02-27 02:50:43 +01:00
|
|
|
This->ref = 1;
|
|
|
|
|
2008-02-29 04:00:12 +01:00
|
|
|
This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
|
|
|
|
This->fileProgress.BytesTransferred = 0;
|
|
|
|
This->fileProgress.Completed = FALSE;
|
2008-03-12 19:56:13 +01:00
|
|
|
This->owner = owner;
|
2013-01-17 19:39:26 +01:00
|
|
|
IBackgroundCopyJob2_AddRef(&owner->IBackgroundCopyJob2_iface);
|
2008-02-29 04:00:12 +01:00
|
|
|
|
2013-01-18 05:38:49 +01:00
|
|
|
*file = This;
|
2008-02-27 02:50:43 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2008-03-13 23:54:35 +01:00
|
|
|
|
|
|
|
static DWORD CALLBACK copyProgressCallback(LARGE_INTEGER totalSize,
|
|
|
|
LARGE_INTEGER totalTransferred,
|
|
|
|
LARGE_INTEGER streamSize,
|
|
|
|
LARGE_INTEGER streamTransferred,
|
|
|
|
DWORD streamNum,
|
|
|
|
DWORD reason,
|
|
|
|
HANDLE srcFile,
|
|
|
|
HANDLE dstFile,
|
|
|
|
LPVOID obj)
|
|
|
|
{
|
2009-01-22 09:51:39 +01:00
|
|
|
BackgroundCopyFileImpl *file = obj;
|
2008-03-13 23:54:35 +01:00
|
|
|
BackgroundCopyJobImpl *job = file->owner;
|
|
|
|
ULONG64 diff;
|
|
|
|
|
|
|
|
EnterCriticalSection(&job->cs);
|
|
|
|
diff = (file->fileProgress.BytesTotal == BG_SIZE_UNKNOWN
|
|
|
|
? totalTransferred.QuadPart
|
|
|
|
: totalTransferred.QuadPart - file->fileProgress.BytesTransferred);
|
|
|
|
file->fileProgress.BytesTotal = totalSize.QuadPart;
|
|
|
|
file->fileProgress.BytesTransferred = totalTransferred.QuadPart;
|
|
|
|
job->jobProgress.BytesTransferred += diff;
|
|
|
|
LeaveCriticalSection(&job->cs);
|
|
|
|
|
|
|
|
return (job->state == BG_JOB_STATE_TRANSFERRING
|
|
|
|
? PROGRESS_CONTINUE
|
|
|
|
: PROGRESS_CANCEL);
|
|
|
|
}
|
|
|
|
|
2008-03-13 23:57:54 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
IBindStatusCallback IBindStatusCallback_iface;
|
2008-03-13 23:57:54 +01:00
|
|
|
BackgroundCopyFileImpl *file;
|
|
|
|
LONG ref;
|
|
|
|
} DLBindStatusCallback;
|
|
|
|
|
2010-12-04 22:16:22 +01:00
|
|
|
static inline DLBindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, DLBindStatusCallback, IBindStatusCallback_iface);
|
|
|
|
}
|
|
|
|
|
2008-03-13 23:57:54 +01:00
|
|
|
static ULONG WINAPI DLBindStatusCallback_AddRef(IBindStatusCallback *iface)
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
DLBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DLBindStatusCallback_Release(IBindStatusCallback *iface)
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
DLBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
IBackgroundCopyFile_Release(&This->file->IBackgroundCopyFile_iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_QueryInterface(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
DLBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IBindStatusCallback))
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
*ppvObject = &This->IBindStatusCallback_iface;
|
2008-03-13 23:57:54 +01:00
|
|
|
DLBindStatusCallback_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_GetBindInfo(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
DWORD *grfBINDF,
|
|
|
|
BINDINFO *pbindinfo)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_GetPriority(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
LONG *pnPriority)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnDataAvailable(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
DWORD grfBSCF,
|
|
|
|
DWORD dwSize,
|
|
|
|
FORMATETC *pformatetc,
|
|
|
|
STGMEDIUM *pstgmed)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnLowResource(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
DWORD reserved)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnObjectAvailable(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
REFIID riid,
|
|
|
|
IUnknown *punk)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnProgress(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
ULONG progress,
|
|
|
|
ULONG progressMax,
|
|
|
|
ULONG statusCode,
|
|
|
|
LPCWSTR statusText)
|
|
|
|
{
|
2010-12-04 22:16:22 +01:00
|
|
|
DLBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
BackgroundCopyFileImpl *file = This->file;
|
|
|
|
BackgroundCopyJobImpl *job = file->owner;
|
|
|
|
ULONG64 diff;
|
|
|
|
|
|
|
|
EnterCriticalSection(&job->cs);
|
|
|
|
diff = (file->fileProgress.BytesTotal == BG_SIZE_UNKNOWN
|
|
|
|
? progress
|
|
|
|
: progress - file->fileProgress.BytesTransferred);
|
|
|
|
file->fileProgress.BytesTotal = progressMax ? progressMax : BG_SIZE_UNKNOWN;
|
|
|
|
file->fileProgress.BytesTransferred = progress;
|
|
|
|
job->jobProgress.BytesTransferred += diff;
|
|
|
|
LeaveCriticalSection(&job->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnStartBinding(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
DWORD dwReserved,
|
|
|
|
IBinding *pib)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DLBindStatusCallback_OnStopBinding(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
HRESULT hresult,
|
|
|
|
LPCWSTR szError)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IBindStatusCallbackVtbl DLBindStatusCallback_Vtbl =
|
|
|
|
{
|
|
|
|
DLBindStatusCallback_QueryInterface,
|
|
|
|
DLBindStatusCallback_AddRef,
|
|
|
|
DLBindStatusCallback_Release,
|
|
|
|
DLBindStatusCallback_OnStartBinding,
|
|
|
|
DLBindStatusCallback_GetPriority,
|
|
|
|
DLBindStatusCallback_OnLowResource,
|
|
|
|
DLBindStatusCallback_OnProgress,
|
|
|
|
DLBindStatusCallback_OnStopBinding,
|
|
|
|
DLBindStatusCallback_GetBindInfo,
|
|
|
|
DLBindStatusCallback_OnDataAvailable,
|
|
|
|
DLBindStatusCallback_OnObjectAvailable
|
|
|
|
};
|
|
|
|
|
|
|
|
static DLBindStatusCallback *DLBindStatusCallbackConstructor(
|
|
|
|
BackgroundCopyFileImpl *file)
|
|
|
|
{
|
2008-05-10 17:25:29 +02:00
|
|
|
DLBindStatusCallback *This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
|
2008-03-13 23:57:54 +01:00
|
|
|
if (!This)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-04 22:16:22 +01:00
|
|
|
This->IBindStatusCallback_iface.lpVtbl = &DLBindStatusCallback_Vtbl;
|
2013-01-18 05:38:49 +01:00
|
|
|
IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
This->file = file;
|
|
|
|
This->ref = 1;
|
|
|
|
return This;
|
|
|
|
}
|
|
|
|
|
2008-03-13 23:54:35 +01:00
|
|
|
BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job)
|
|
|
|
{
|
2008-06-19 23:51:55 +02:00
|
|
|
static const WCHAR prefix[] = {'B','I','T', 0};
|
2010-12-04 22:16:22 +01:00
|
|
|
DLBindStatusCallback *callbackObj;
|
2008-03-13 23:54:35 +01:00
|
|
|
WCHAR tmpDir[MAX_PATH];
|
|
|
|
WCHAR tmpName[MAX_PATH];
|
2008-03-13 23:57:19 +01:00
|
|
|
HRESULT hr;
|
2008-03-13 23:54:35 +01:00
|
|
|
|
|
|
|
if (!GetTempPathW(MAX_PATH, tmpDir))
|
|
|
|
{
|
|
|
|
ERR("Couldn't create temp file name: %d\n", GetLastError());
|
|
|
|
/* Guessing on what state this should give us */
|
|
|
|
transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetTempFileNameW(tmpDir, prefix, 0, tmpName))
|
|
|
|
{
|
|
|
|
ERR("Couldn't create temp file: %d\n", GetLastError());
|
|
|
|
/* Guessing on what state this should give us */
|
|
|
|
transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-04 22:16:22 +01:00
|
|
|
callbackObj = DLBindStatusCallbackConstructor(file);
|
2008-03-13 23:57:54 +01:00
|
|
|
if (!callbackObj)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-13 23:54:35 +01:00
|
|
|
EnterCriticalSection(&job->cs);
|
|
|
|
file->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
|
|
|
|
file->fileProgress.BytesTransferred = 0;
|
|
|
|
file->fileProgress.Completed = FALSE;
|
|
|
|
LeaveCriticalSection(&job->cs);
|
|
|
|
|
|
|
|
TRACE("Transferring: %s -> %s -> %s\n",
|
|
|
|
debugstr_w(file->info.RemoteName),
|
|
|
|
debugstr_w(tmpName),
|
|
|
|
debugstr_w(file->info.LocalName));
|
|
|
|
|
|
|
|
transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSFERRING);
|
2008-03-13 23:57:19 +01:00
|
|
|
|
|
|
|
DeleteUrlCacheEntryW(file->info.RemoteName);
|
2010-12-04 22:16:22 +01:00
|
|
|
hr = URLDownloadToFileW(NULL, file->info.RemoteName, tmpName, 0,
|
|
|
|
&callbackObj->IBindStatusCallback_iface);
|
|
|
|
IBindStatusCallback_Release(&callbackObj->IBindStatusCallback_iface);
|
2008-03-13 23:57:54 +01:00
|
|
|
if (hr == INET_E_DOWNLOAD_FAILURE)
|
2008-03-13 23:57:19 +01:00
|
|
|
{
|
|
|
|
TRACE("URLDownload failed, trying local file copy\n");
|
|
|
|
if (!CopyFileExW(file->info.RemoteName, tmpName, copyProgressCallback,
|
|
|
|
file, NULL, 0))
|
|
|
|
{
|
|
|
|
ERR("Local file copy failed: error %d\n", GetLastError());
|
|
|
|
transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-10-08 01:33:25 +02:00
|
|
|
else if (FAILED(hr))
|
2008-03-13 23:54:35 +01:00
|
|
|
{
|
2008-03-13 23:57:19 +01:00
|
|
|
ERR("URLDownload failed: eh 0x%08x\n", hr);
|
2008-03-13 23:54:35 +01:00
|
|
|
transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_QUEUED))
|
|
|
|
{
|
|
|
|
lstrcpyW(file->tempFileName, tmpName);
|
|
|
|
|
|
|
|
EnterCriticalSection(&job->cs);
|
|
|
|
file->fileProgress.Completed = TRUE;
|
|
|
|
job->jobProgress.FilesTransferred++;
|
|
|
|
LeaveCriticalSection(&job->cs);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DeleteFileW(tmpName);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|