in PhotoEditor/MainPage.cpp [148:201]
IAsyncAction MainPage::GetItemsAsync()
{
// Show the loading progress bar.
LoadProgressIndicator().Visibility(Windows::UI::Xaml::Visibility::Visible);
NoPicsText().Visibility(Windows::UI::Xaml::Visibility::Collapsed);
// File type filter.
QueryOptions options{};
options.FolderDepth(FolderDepth::Deep);
options.FileTypeFilter().Append(L".jpg");
options.FileTypeFilter().Append(L".png");
options.FileTypeFilter().Append(L".gif");
// Get the Pictures library.
StorageFolder picturesFolder = KnownFolders::PicturesLibrary();
auto result = picturesFolder.CreateFileQueryWithOptions(options);
auto imageFiles = co_await result.GetFilesAsync();
auto unsupportedFilesFound = false;
// Populate Photos collection.
for (auto&& file : imageFiles)
{
// Only files on the local computer are supported.
// Files on OneDrive or a network location are excluded.
if (file.Provider().Id() == L"computer")
{
auto image = co_await LoadImageInfoAsync(file);
Photos().Append(image);
}
else
{
unsupportedFilesFound = true;
}
}
if (Photos().Size() == 0)
{
// No pictures were found in the library, so show message.
NoPicsText().Visibility(Windows::UI::Xaml::Visibility::Visible);
}
// Hide the loading progress bar.
LoadProgressIndicator().Visibility(Windows::UI::Xaml::Visibility::Collapsed);
if (unsupportedFilesFound)
{
ContentDialog unsupportedFilesDialog{};
unsupportedFilesDialog.Title(box_value(L"Unsupported images found"));
unsupportedFilesDialog.Content(box_value(L"This sample app only supports images stored locally on the computer. We found files in your library that are stored in OneDrive or another network location. We didn't load those images."));
unsupportedFilesDialog.CloseButtonText(L"Ok");
co_await unsupportedFilesDialog.ShowAsync();
}
}