Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
winrt_helpers.h
1 #pragma once
2 
3 #include "FilePathManager.h"
4 #include <pplawait.h>
5 
6 #include "Platform/Main/BaseApp.h"
7 #include <winrt/Windows.UI.Core.h>
8 
9 template<typename TLambda>
10 auto invoke_async_lambda(TLambda lambda) -> decltype(lambda())
11 {
12  return co_await lambda();
13 }
14 
15 template<typename T>
16 winrt::fire_and_forget no_await_lambda(T t)
17 {
18  co_await t();
19 }
20 
21 template<typename T>
22 winrt::fire_and_forget no_await(T t)
23 {
24  co_await t;
25 }
26 
27 inline concurrency::task<SmartPointer<FileHandle>> MakeHandleFromStorageFile(winrt::Windows::Storage::StorageFile file)
28 {
29  SmartPointer<FileHandle> result;
30  auto name = file.Name();
31  /*result = FilePathManager::CreateFileHandle(to_utf8(name.c_str()));
32  result->myVirtualFileAccess = new StorageFileFileAccess(file);
33  result->myUseVirtualFileAccess = true;
34  co_return result;*/
35 
36  auto file_copy = co_await file.CopyAsync(winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder(), name, winrt::Windows::Storage::NameCollisionOption::ReplaceExisting);
37  if (file_copy)
38  {
39  result = FilePathManager::CreateFileHandle(to_utf8(file_copy.Path().data()));
40  }
41  co_return result;
42 }
43 
44 inline SmartPointer<FileHandle> MakeHandleFromStorageFileNoCopy(winrt::Windows::Storage::StorageFile file)
45 {
46  SmartPointer<FileHandle> result;
47  result = FilePathManager::CreateFileHandle(to_utf8(file.Path().data()));
48  return result;
49 }
50 
51 
52 inline auto resume_on_kigs_thread()
53 {
54  return winrt::resume_foreground(App::GetApp()->GetWindow().Dispatcher());
55 }
FilePathManager.h
Platform agnostic FileHandle.