#include "pch.h"
#include "StorageAsync.h"
#include "StorageAccess.h"
using namespace winrt;
using namespace winrt::Windows::Storage;
using namespace winrt::Windows::Storage::Pickers;
using namespace winrt::Windows::Foundation;
std::string PickSingleFolder()
{
FolderPicker folderPicker;
folderPicker.SuggestedStartLocation(PickerLocationId::Desktop);
folderPicker.FileTypeFilter().Append(L"*");
StorageFolder folder{ nullptr };
ExecuteTask(folder, folderPicker.PickSingleFolderAsync());
std::string path;
if (folder) {
AddItemToFutureList(folder);
path = winrt::to_string(folder.Path());
}
return path;
}
std::string PickSingleFile(std::vector<std::string> exts)
{
FileOpenPicker filePicker;
filePicker.SuggestedStartLocation(PickerLocationId::Desktop);
filePicker.ViewMode(PickerViewMode::List);
if (!exts.empty()) {
for (const auto& ext : exts) {
filePicker.FileTypeFilter().Append(winrt::to_hstring(ext));
}
}
else {
filePicker.FileTypeFilter().Append(L"*");
}
StorageFile file{ nullptr };
ExecuteTask(file, filePicker.PickSingleFileAsync());
std::string path;
if (file) {
AddItemToFutureList(file);
path = winrt::to_string(file.Path());
}
return path;
}
std::string ChooseFile(std::vector<std::string> exts) {
return PickSingleFile(exts);
}
std::string ChooseFolder() {
return PickSingleFolder();
}