PowerToys/src/settings/StreamURIResolverFromFile.cpp

27 lines
996 B
C++
Raw Normal View History

#include "pch.h"
#include "StreamUriResolverFromFile.h"
2019-12-27 00:25:56 +08:00
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::Streams::IInputStream> StreamUriResolverFromFile::UriToStreamAsync(const winrt::Windows::Foundation::Uri& uri) const
{
winrt::Windows::Storage::StorageFolder folder = winrt::Windows::Storage::StorageFolder::GetFolderFromPathAsync(winrt::param::hstring(base_path)).get();
2019-12-27 00:25:56 +08:00
std::wstring myuri = uri.Path().c_str();
myuri.erase(0, 1); // Removes the first slash from the URI
2019-12-27 00:25:56 +08:00
std::replace(myuri.begin(), myuri.end(), '/', '\\');
winrt::Windows::Storage::StorageFile file = nullptr;
2019-12-27 00:25:56 +08:00
try
{
file = folder.GetFileAsync(winrt::param::hstring(myuri)).get();
}
catch (winrt::hresult_error const& e)
{
WCHAR message[1024] = L"";
StringCchPrintf(message, ARRAYSIZE(message), L"failed: %ls", e.message().c_str());
MessageBox(NULL, message, L"Error", MB_OK);
}
2019-12-27 00:25:56 +08:00
return file.OpenSequentialReadAsync();
}