ZenLib
OS_Utils.h
Go to the documentation of this file.
1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  * Use of this source code is governed by a zlib-style license that can
4  * be found in the License.txt file in the root of the source tree.
5  */
6 
7 //---------------------------------------------------------------------------
8 #ifndef ZenOS_UtilsH
9 #define ZenOS_UtilsH
10 //---------------------------------------------------------------------------
11 
12 //---------------------------------------------------------------------------
13 #include "ZenLib/Ztring.h"
14 //---------------------------------------------------------------------------
15 
16 //---------------------------------------------------------------------------
17 #ifdef WINDOWS_UWP
18 #include <wrl.h>
19 #include <windows.foundation.h>
20 #include <windows.storage.h>
21 #endif
22 //---------------------------------------------------------------------------
23 
24 namespace ZenLib
25 {
26 
27 //***************************************************************************
28 // OS Information
29 //***************************************************************************
30 
31 //---------------------------------------------------------------------------
32 bool IsWin9X ();
33 // Execute
34 //***************************************************************************
35 
36 void Shell_Execute(const Ztring &ToExecute);
37 
38 //***************************************************************************
39 // File names
40 //***************************************************************************
41 
42 // Names for the narrow functions of the C library or of the system (e.g. fopen(), the arguments of main()), in the encoding of the locale
43 // (the code page on Windows), or UTF-8 where the file names are UTF-8 (e.g. macOS). Without Unicode, the strings of ZenLib, also the names
44 // it gives (e.g. Dir::GetAllFileNames()), are UTF-8 text: a name for these functions, or to show in the encoding of the locale, must be
45 // converted with FileName_To_Native() or Ztring::To_Local()
46 std::string FileName_To_Native(const Ztring &File_Name);
47 Ztring FileName_From_Native(const char* File_Name);
48 
49 #if defined(WINDOWS) && !defined(WINDOWS_UWP) && !defined(UNICODE) && !defined(ZENLIB_USEWX)
50 // Without Unicode on Windows, name of an existing file or directory for the wide functions, as File and Dir open it: UTF-8 text, or the
51 // bytes of the code page given as they are (see Ztring::To_Unicode()), also when these bytes are valid UTF-8 but only the name in the code
52 // page exists. Ztring::From_Unicode() gives this name as UTF-8 text, as FileName_From_Native(FileName_To_Native()) on the other systems.
53 std::wstring FileName_To_Wide_Existing(const Ztring &File_Name);
54 #endif
55 
56 //***************************************************************************
57 // Directorues
58 //***************************************************************************
59 
60 Ztring OpenFolder_Show(void* Handle, const Ztring &Title, const Ztring &Caption);
61 
62 //***************************************************************************
63 // WinRT Helpers
64 //***************************************************************************
65 #ifdef WINDOWS_UWP
66 template <typename T>
67 inline HRESULT Await(const Microsoft::WRL::ComPtr<T> &Operation)
68 {
69  if (!Operation)
70  return E_POINTER;
71 
72  Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> Info;
73  HRESULT Result=Operation.As(&Info);
74  if (FAILED(Result))
75  return Result;
76 
77  ABI::Windows::Foundation::AsyncStatus Status;
78  while (SUCCEEDED(Result=Info->get_Status(&Status)) && Status==Started)
79  Sleep(0); //Yield
80 
81  if (FAILED(Result) || Status!=Completed) {
82  HRESULT Error_Code;
83  Result=Info->get_ErrorCode(&Error_Code);
84  if (FAILED(Result))
85  return Result;
86  return Error_Code;
87  }
88 
89  return Result;
90 }
91 
92 HRESULT Add_Item_To_FUA(Microsoft::WRL::Wrappers::HStringReference Path, Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageItem> &Item);
93 HRESULT Get_File(Microsoft::WRL::Wrappers::HStringReference File_Name, Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFile> &File);
94 HRESULT Get_Folder(Microsoft::WRL::Wrappers::HStringReference Folder_Name, Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFolder> &Folder);
95 #endif
96 
97 } //namespace ZenLib
98 #endif
ZenLib::FileName_From_Native
Ztring FileName_From_Native(const char *File_Name)
ZenLib::Shell_Execute
void Shell_Execute(const Ztring &ToExecute)
ZenLib::OpenFolder_Show
Ztring OpenFolder_Show(void *Handle, const Ztring &Title, const Ztring &Caption)
ZenLib::IsWin9X
bool IsWin9X()
ZenLib
Definition: BitStream.h:23
ZenLib::FileName_To_Native
std::string FileName_To_Native(const Ztring &File_Name)
Ztring.h