CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/UWPHelpers/StoragePickers.cpp
Views: 1401
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 Platform;
24
using namespace Windows::Storage;
25
using namespace Windows::Foundation;
26
27
extern void AddItemToFutureList(IStorageItem^ folder);
28
29
// Call folder picker (the selected folder will be added to future list)
30
concurrency::task<Platform::String^> PickSingleFolder()
31
{
32
auto folderPicker = ref new Windows::Storage::Pickers::FolderPicker();
33
folderPicker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::Desktop;
34
folderPicker->FileTypeFilter->Append("*");
35
36
return concurrency::create_task(folderPicker->PickSingleFolderAsync()).then([](StorageFolder^ folder) {
37
auto path = ref new Platform::String();
38
if (folder != nullptr)
39
{
40
AddItemToFutureList(folder);
41
path = folder->Path;
42
}
43
return path;
44
});
45
}
46
47
// Call file picker (the selected file will be added to future list)
48
concurrency::task<Platform::String^> PickSingleFile(std::vector<std::string> exts)
49
{
50
auto filePicker = ref new Windows::Storage::Pickers::FileOpenPicker();
51
filePicker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::Desktop;
52
filePicker->ViewMode = Pickers::PickerViewMode::List;
53
54
if (exts.size() > 0) {
55
for each (auto ext in exts) {
56
filePicker->FileTypeFilter->Append(ToPlatformString(ext));
57
}
58
}
59
else
60
{
61
filePicker->FileTypeFilter->Append("*");
62
}
63
return concurrency::create_task(filePicker->PickSingleFileAsync()).then([](StorageFile^ file) {
64
auto path = ref new Platform::String();
65
if (file != nullptr)
66
{
67
AddItemToFutureList(file);
68
path = file->Path;
69
}
70
return path;
71
});
72
}
73
74
75
concurrency::task<std::string> ChooseFile(std::vector<std::string> exts) {
76
return PickSingleFile(exts).then([](Platform::String^ filePath) {
77
return FromPlatformString(filePath);
78
});
79
}
80
81
concurrency::task<std::string> ChooseFolder() {
82
return PickSingleFolder().then([](Platform::String^ folderPath) {
83
return FromPlatformString(folderPath);
84
});
85
86
}
87
88