forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamURIResolverFromFile.cpp
More file actions
26 lines (21 loc) · 996 Bytes
/
StreamURIResolverFromFile.cpp
File metadata and controls
26 lines (21 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "pch.h"
#include "StreamUriResolverFromFile.h"
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();
std::wstring myuri = uri.Path().c_str();
myuri.erase(0, 1); // Removes the first slash from the URI
std::replace(myuri.begin(), myuri.end(), '/', '\\');
winrt::Windows::Storage::StorageFile file = nullptr;
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);
}
return file.OpenSequentialReadAsync();
}