Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/UWPHelpers/StoragePickers.cpp
5647 views
1
// Copyright (c) 2023- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "pch.h"
19
20
#include "StorageAsync.h"
21
#include "StorageAccess.h"
22
23
using namespace winrt;
24
using namespace winrt::Windows::Storage;
25
using namespace winrt::Windows::Storage::Pickers;
26
using namespace winrt::Windows::Foundation;
27
28
// Call folder picker (the selected folder will be added to future list)
29
std::string PickSingleFolder()
30
{
31
FolderPicker folderPicker;
32
folderPicker.SuggestedStartLocation(PickerLocationId::Desktop);
33
folderPicker.FileTypeFilter().Append(L"*");
34
35
StorageFolder folder{ nullptr };
36
ExecuteTask(folder, folderPicker.PickSingleFolderAsync());
37
38
std::string path;
39
if (folder) {
40
AddItemToFutureList(folder);
41
path = winrt::to_string(folder.Path());
42
}
43
return path;
44
}
45
46
// Call file picker (the selected file will be added to future list)
47
std::string PickSingleFile(std::vector<std::string> exts)
48
{
49
FileOpenPicker filePicker;
50
filePicker.SuggestedStartLocation(PickerLocationId::Desktop);
51
filePicker.ViewMode(PickerViewMode::List);
52
53
if (!exts.empty()) {
54
for (const auto& ext : exts) {
55
filePicker.FileTypeFilter().Append(winrt::to_hstring(ext));
56
}
57
}
58
else {
59
filePicker.FileTypeFilter().Append(L"*");
60
}
61
62
StorageFile file{ nullptr };
63
ExecuteTask(file, filePicker.PickSingleFileAsync());
64
65
std::string path;
66
if (file) {
67
AddItemToFutureList(file);
68
path = winrt::to_string(file.Path());
69
}
70
return path;
71
}
72
73
std::string ChooseFile(std::vector<std::string> exts) {
74
return PickSingleFile(exts);
75
}
76
77
std::string ChooseFolder() {
78
return PickSingleFolder();
79
}
80
81