Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/UWPHelpers/StorageAsync.cpp
5670 views
1
// Thanks to RetroArch/Libretro team for this idea
2
// This is improved version of the original idea
3
4
#include "pch.h"
5
#include "StorageAsync.h"
6
7
bool ActionPass(winrt::Windows::Foundation::IAsyncAction action) {
8
bool result = false;
9
bool done = false;
10
11
action.Completed([&](auto&& sender, winrt::Windows::Foundation::AsyncStatus status) {
12
if (status == winrt::Windows::Foundation::AsyncStatus::Completed) {
13
result = true;
14
}
15
else {
16
ERROR_LOG(Log::FileSystem, "Async action failed with status %d", (int)status);
17
result = false;
18
}
19
done = true;
20
});
21
22
winrt::Windows::UI::Core::CoreWindow corewindow = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread();
23
while (!done) {
24
try {
25
if (corewindow) {
26
corewindow.Dispatcher().ProcessEvents(winrt::Windows::UI::Core::CoreProcessEventsOption::ProcessAllIfPresent);
27
}
28
else {
29
corewindow = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread();
30
}
31
}
32
catch (...) {
33
}
34
}
35
36
return result;
37
}
38
39
// Async action such as 'Delete' file
40
// @action: async action
41
// return false when action failed
42
bool ExecuteTask(winrt::Windows::Foundation::IAsyncAction action) {
43
try {
44
return ActionPass(action);
45
}
46
catch (...) {
47
return false;
48
}
49
}
50
51