-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microsoft.Windows.Storage.Pickers.FileOpenPicker.PickSingleFileAsync (#…
…4945) Creating new API Microsoft.Windows.Storage.Pickers.FileOpenPicker.PickSingleFileAsync
- Loading branch information
1 parent
d99c353
commit a243907
Showing
11 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
#include "pch.h" | ||
#include "FileOpenPicker.h" | ||
#include "Microsoft.Windows.Storage.Pickers.FileOpenPicker.g.cpp" | ||
#include <windows.h> | ||
#include <shobjidl.h> | ||
#include <wil/cppwinrt.h> | ||
#include <wil/com.h> | ||
#include <wil/resource.h> | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFile> FileOpenPicker::PickSingleFileAsync() | ||
{ | ||
winrt::apartment_context ui_thread; | ||
|
||
co_await winrt::resume_background(); | ||
|
||
// Handle cancellation. | ||
auto cancellationToken = co_await winrt::get_cancellation_token(); | ||
if (cancellationToken()) | ||
{ | ||
co_return nullptr; | ||
} | ||
|
||
// TODO: should we initialize COM? | ||
//wil::com_initialize_ex initializeCom{ COINIT_APARTMENTTHREADED }; | ||
|
||
wil::com_ptr<IFileOpenDialog> fileOpenDialog; | ||
THROW_IF_FAILED(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&fileOpenDialog))); | ||
|
||
HRESULT hr = fileOpenDialog->Show(nullptr); | ||
if (FAILED(hr) || cancellationToken()) | ||
{ | ||
co_return nullptr; | ||
} | ||
|
||
wil::com_ptr<IShellItem> shellItem; | ||
THROW_IF_FAILED(fileOpenDialog->GetResult(shellItem.put())); | ||
|
||
wil::unique_cotaskmem_string filePath; | ||
THROW_IF_FAILED(shellItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath)); | ||
|
||
// Convert the file path to a StorageFile. | ||
auto const& file = co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(filePath.get()); | ||
if (cancellationToken()) { | ||
co_return nullptr; | ||
} | ||
|
||
co_await ui_thread; | ||
if (cancellationToken()) { | ||
co_return nullptr; | ||
} | ||
|
||
co_return file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
#pragma once | ||
#include "Microsoft.Windows.Storage.Pickers.FileOpenPicker.g.h" | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
struct FileOpenPicker : FileOpenPickerT<FileOpenPicker> | ||
{ | ||
FileOpenPicker() = default; | ||
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFile> PickSingleFileAsync(); | ||
}; | ||
} | ||
namespace winrt::Microsoft::Windows::Storage::Pickers::factory_implementation | ||
{ | ||
struct FileOpenPicker : FileOpenPickerT<FileOpenPicker, implementation::FileOpenPicker> | ||
{ | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Microsoft.Windows.Storage.Pickers | ||
{ | ||
[contractversion(1)] | ||
apicontract FileOpenPickerContract {}; | ||
|
||
[contract(FileOpenPickerContract, 1)] | ||
runtimeclass FileOpenPicker | ||
{ | ||
FileOpenPicker(); | ||
|
||
Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile> PickSingleFileAsync(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<ItemsProjectGuid>{a39e7b2f-5f67-47dd-8443-531d095ca7f3}</ItemsProjectGuid> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup> | ||
<ClCompile> | ||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ProjectCapability Include="SourceItemsFromImports" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="$(MSBuildThisFileDirectory)FileOpenPicker.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="$(MSBuildThisFileDirectory)FileOpenPicker.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Midl Include="$(MSBuildThisFileDirectory)FileOpenPicker.idl" /> | ||
</ItemGroup> | ||
</Project> |
58 changes: 58 additions & 0 deletions
58
...ft.Windows.Storage.Pickers.Projection/Microsoft.Windows.Storage.Pickers.Projection.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework> | ||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> | ||
<Platforms>x64;x86;arm64</Platforms> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer> | ||
<IsTrimmable>true</IsTrimmable> | ||
</PropertyGroup> | ||
|
||
<!-- Suppress CS8305: Feature is for evaluation purposes only and is subject to change or removal in future updates. --> | ||
<PropertyGroup> | ||
<NoWarn>8305</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.Common"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Windows.CsWinRT" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<CSWinRTIncludes>Microsoft.Windows.Storage.Pickers</CSWinRTIncludes> | ||
<CSWinRTWindowsMetadata>10.0.17763.0</CSWinRTWindowsMetadata> | ||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly> | ||
</PropertyGroup> | ||
|
||
<!-- Configure the release build binary to be as required by internal API scanning tools. --> | ||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> | ||
<DebugType>pdbonly</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<CsWinRTInputs Include="$(OutDir)/**/*.winmd" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(RepoRoot)\build\VersionInfo\AssemblyInfo.cs" Link="AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.Windows.Storage.Pickers"> | ||
<HintPath>$(OutDir)..\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Storage.Pickers.winmd</HintPath> | ||
<IsWinMDFile>true</IsWinMDFile> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters