From d12d6b29786575d261bcd41236c0937daf291627 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 26 Jan 2022 22:37:14 +0100 Subject: [PATCH] d3dcompiler: Implement D3DWriteBlobToFile(). Signed-off-by: Nikolay Sivov Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- dlls/d3dcompiler_43/blob.c | 25 ++++++++++++++++++++++--- dlls/d3dcompiler_43/tests/blob.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/dlls/d3dcompiler_43/blob.c b/dlls/d3dcompiler_43/blob.c index 5cc49fe5699..ee23893576d 100644 --- a/dlls/d3dcompiler_43/blob.c +++ b/dlls/d3dcompiler_43/blob.c @@ -514,9 +514,28 @@ HRESULT WINAPI D3DReadFileToBlob(const WCHAR *filename, ID3DBlob **contents) return S_OK; } -HRESULT WINAPI D3DWriteBlobToFile(ID3DBlob* blob, const WCHAR *filename, BOOL overwrite) +HRESULT WINAPI D3DWriteBlobToFile(ID3DBlob *blob, const WCHAR *filename, BOOL overwrite) { - FIXME("blob %p, filename %s, overwrite %d\n", blob, debugstr_w(filename), overwrite); + DWORD written_size; + SIZE_T data_size; + HANDLE file; + BOOL ret; - return E_NOTIMPL; + TRACE("blob %p, filename %s, overwrite %#x.\n", blob, debugstr_w(filename), overwrite); + + file = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, overwrite ? CREATE_ALWAYS : CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + return HRESULT_FROM_WIN32(GetLastError()); + + data_size = ID3D10Blob_GetBufferSize(blob); + ret = WriteFile(file, ID3D10Blob_GetBufferPointer(blob), data_size, &written_size, NULL); + CloseHandle(file); + if (!ret || data_size != written_size) + { + WARN("Failed to write blob contents.\n"); + return E_FAIL; + } + + return S_OK; } diff --git a/dlls/d3dcompiler_43/tests/blob.c b/dlls/d3dcompiler_43/tests/blob.c index 9369fcd97f5..400d5940bf7 100644 --- a/dlls/d3dcompiler_43/tests/blob.c +++ b/dlls/d3dcompiler_43/tests/blob.c @@ -859,6 +859,37 @@ static void test_D3DReadFileToBlob(void) DeleteFileW(filename); ID3D10Blob_Release(blob); } + +static void test_D3DWriteBlobToFile(void) +{ + WCHAR temp_dir[MAX_PATH], filename[MAX_PATH]; + ID3DBlob *blob; + HRESULT hr; + + GetTempPathW(ARRAY_SIZE(temp_dir), temp_dir); + GetTempFileNameW(temp_dir, NULL, 0, filename); + + hr = D3DCreateBlob(16, &blob); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = D3DWriteBlobToFile(blob, filename, FALSE); + ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "Unexpected hr %#x.\n", hr); + + hr = D3DWriteBlobToFile(blob, filename, TRUE); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + DeleteFileW(filename); + + hr = D3DWriteBlobToFile(blob, filename, FALSE); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = D3DWriteBlobToFile(blob, filename, FALSE); + ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "Unexpected hr %#x.\n", hr); + + DeleteFileW(filename); + + ID3D10Blob_Release(blob); +} #endif #endif @@ -870,6 +901,7 @@ START_TEST(blob) test_get_blob_part2(); #if D3D_COMPILER_VERSION >= 46 test_D3DReadFileToBlob(); + test_D3DWriteBlobToFile(); #endif #endif }