src/video/windowsrt/DirectXHelper.h
changeset 8322 839cd578a474
child 8384 bc7a52629e1e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/windowsrt/DirectXHelper.h	Sat Oct 27 21:20:00 2012 -0400
     1.3 @@ -0,0 +1,36 @@
     1.4 +#pragma once
     1.5 +
     1.6 +#include <wrl/client.h>
     1.7 +#include <ppl.h>
     1.8 +#include <ppltasks.h>
     1.9 +
    1.10 +namespace DX
    1.11 +{
    1.12 +	inline void ThrowIfFailed(HRESULT hr)
    1.13 +	{
    1.14 +		if (FAILED(hr))
    1.15 +		{
    1.16 +			// Set a breakpoint on this line to catch Win32 API errors.
    1.17 +			throw Platform::Exception::CreateException(hr);
    1.18 +		}
    1.19 +	}
    1.20 +
    1.21 +	// Function that reads from a binary file asynchronously.
    1.22 +	inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
    1.23 +	{
    1.24 +		using namespace Windows::Storage;
    1.25 +		using namespace Concurrency;
    1.26 +		
    1.27 +		auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    1.28 +		
    1.29 +		return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
    1.30 +		{
    1.31 +			return FileIO::ReadBufferAsync(file);
    1.32 +		}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
    1.33 +		{
    1.34 +			auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
    1.35 +			Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
    1.36 +			return fileData;
    1.37 +		});
    1.38 +	}
    1.39 +}