//--------------------------------------------------------------------------- HRESULT Get_Folder(HStringReference Folder_Name, ComPtr<IStorageFolder> &Folder) { //Try to access folder directly ComPtr<IStorageFolderStatics> Storage; if (SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_StorageFolder).Get(), &Storage)) && Storage) { ComPtr<IAsyncOperation<StorageFolder*> > Async_GetFolder; if (SUCCEEDED(Storage->GetFolderFromPathAsync(Folder_Name.Get(), &Async_GetFolder)) && SUCCEEDED(Await(Async_GetFolder)) && SUCCEEDED(Async_GetFolder->GetResults(&Folder)) && Folder) return S_OK; } //Try to access folder by sha256 hashed path in future access list ComPtr<IBuffer> Path_Buffer; ComPtr<IBuffer> Hash_Buffer; ComPtr<ICryptographicBufferStatics> Cryptographic_Buffer_Statics; ComPtr<IHashAlgorithmProviderStatics> Hash_Provider_Statics; ComPtr<IHashAlgorithmProvider> Hash_Provider; UINT32 Buffer_Lenght = 0; UINT32 Hash_Lenght = 0; HString Path_Hash; if (SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer).Get(), &Cryptographic_Buffer_Statics)) && Cryptographic_Buffer_Statics && SUCCEEDED(Cryptographic_Buffer_Statics->ConvertStringToBinary(Folder_Name.Get(), BinaryStringEncoding_Utf16LE, &Path_Buffer)) && Path_Buffer && SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Security_Cryptography_Core_HashAlgorithmProvider).Get(), &Hash_Provider_Statics)) && Hash_Provider_Statics && SUCCEEDED(Hash_Provider_Statics->OpenAlgorithm(HString::MakeReference(L"SHA256").Get(), &Hash_Provider)) && Hash_Provider && SUCCEEDED(Hash_Provider->HashData(*Path_Buffer.GetAddressOf(), &Hash_Buffer)) && Hash_Buffer && SUCCEEDED(Hash_Buffer->get_Length(&Buffer_Lenght)) && Buffer_Lenght && SUCCEEDED(Hash_Provider->get_HashLength(&Hash_Lenght)) && Hash_Lenght && Buffer_Lenght == Hash_Lenght && SUCCEEDED(Cryptographic_Buffer_Statics->EncodeToBase64String(*Hash_Buffer.GetAddressOf(), Path_Hash.GetAddressOf()))) { ComPtr<IStorageApplicationPermissionsStatics> Permissions_Manager; if (SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_AccessCache_StorageApplicationPermissions).Get(), &Permissions_Manager)) && Permissions_Manager) { ComPtr<IStorageItemAccessList> FutureAccess_List; ComPtr<IAsyncOperation<StorageFolder*> > Async_GetFolder_FutureAccess; if (SUCCEEDED(Permissions_Manager->get_FutureAccessList(&FutureAccess_List)) && FutureAccess_List && SUCCEEDED(FutureAccess_List->GetFolderAsync(Folder_Name.Get(), &Async_GetFolder_FutureAccess)) && Await(Async_GetFolder_FutureAccess) && SUCCEEDED(Async_GetFolder_FutureAccess->GetResults(&Folder)) && Folder) return S_OK; } } return E_FAIL; }
static bool uiColorSettings(const wchar_t *value, UIElementType type, Color *color) { static ComPtr<IApiInformationStatics> apiInformationStatics; HRESULT hr; if (!apiInformationStatics) { hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Metadata_ApiInformation).Get(), IID_PPV_ARGS(&apiInformationStatics)); RETURN_FALSE_IF_FAILED("Could not get ApiInformationStatics"); } static const HStringReference enumRef(L"Windows.UI.ViewManagement.UIElementType"); HStringReference valueRef(value); boolean exists; hr = apiInformationStatics->IsEnumNamedValuePresent(enumRef.Get(), valueRef.Get(), &exists); if (hr != S_OK || !exists) return false; return SUCCEEDED(uiSettings()->UIElementColor(type, color)); }
//--------------------------------------------------------------------------- HRESULT Add_Item_To_FUA(HStringReference Path, ComPtr<IStorageItem> &Item) { ComPtr<IBuffer> Path_Buffer; ComPtr<IBuffer> Hash_Buffer; ComPtr<ICryptographicBufferStatics> Cryptographic_Buffer_Statics; ComPtr<IHashAlgorithmProviderStatics> Hash_Provider_Statics; ComPtr<IHashAlgorithmProvider> Hash_Provider; UINT32 Buffer_Lenght = 0; UINT32 Hash_Lenght = 0; HString Path_Hash; if (SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer).Get(), &Cryptographic_Buffer_Statics)) && Cryptographic_Buffer_Statics && SUCCEEDED(Cryptographic_Buffer_Statics->ConvertStringToBinary(Path.Get(), BinaryStringEncoding_Utf16LE, &Path_Buffer)) && Path_Buffer && SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Security_Cryptography_Core_HashAlgorithmProvider).Get(), &Hash_Provider_Statics)) && Hash_Provider_Statics && SUCCEEDED(Hash_Provider_Statics->OpenAlgorithm(HString::MakeReference(L"SHA256").Get(), &Hash_Provider)) && Hash_Provider && SUCCEEDED(Hash_Provider->HashData(*Path_Buffer.GetAddressOf(), &Hash_Buffer)) && Hash_Buffer && SUCCEEDED(Hash_Buffer->get_Length(&Buffer_Lenght)) && Buffer_Lenght && SUCCEEDED(Hash_Provider->get_HashLength(&Hash_Lenght)) && Hash_Lenght && Buffer_Lenght == Hash_Lenght && SUCCEEDED(Cryptographic_Buffer_Statics->EncodeToBase64String(*Hash_Buffer.GetAddressOf(), Path_Hash.GetAddressOf()))) { ComPtr<IStorageApplicationPermissionsStatics> Permissions_Manager; ComPtr<IStorageItemAccessList> FutureAccess_List; if (SUCCEEDED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_AccessCache_StorageApplicationPermissions).Get(), &Permissions_Manager)) && Permissions_Manager && SUCCEEDED(Permissions_Manager->get_FutureAccessList(&FutureAccess_List)) && FutureAccess_List) return FutureAccess_List->AddOrReplace(Path_Hash.Get(), *Item.GetAddressOf(), HString::MakeReference(L"").Get()); } return E_FAIL; }
QWinRTIntegration::QWinRTIntegration() : d_ptr(new QWinRTIntegrationPrivate) { Q_D(QWinRTIntegration); d->fontDatabase = new QWinRTFontDatabase; HRESULT hr; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), IID_PPV_ARGS(&d->application)); Q_ASSERT_SUCCEEDED(hr); hr = d->application->add_Suspending(Callback<SuspendHandler>(this, &QWinRTIntegration::onSuspended).Get(), &d->applicationTokens[&ICoreApplication::remove_Suspending]); Q_ASSERT_SUCCEEDED(hr); hr = d->application->add_Resuming(Callback<ResumeHandler>(this, &QWinRTIntegration::onResume).Get(), &d->applicationTokens[&ICoreApplication::remove_Resuming]); Q_ASSERT_SUCCEEDED(hr); #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) d->hasHardwareButtons = false; ComPtr<IApiInformationStatics> apiInformationStatics; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Metadata_ApiInformation).Get(), IID_PPV_ARGS(&apiInformationStatics)); if (SUCCEEDED(hr)) { const HStringReference valueRef(L"Windows.Phone.UI.Input.HardwareButtons"); hr = apiInformationStatics->IsTypePresent(valueRef.Get(), &d->hasHardwareButtons); } if (d->hasHardwareButtons) { hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Phone_UI_Input_HardwareButtons).Get(), IID_PPV_ARGS(&d->hardwareButtons)); Q_ASSERT_SUCCEEDED(hr); hr = d->hardwareButtons->add_BackPressed(Callback<BackPressedHandler>(this, &QWinRTIntegration::onBackButtonPressed).Get(), &d->buttonsTokens[&IHardwareButtonsStatics::remove_BackPressed]); Q_ASSERT_SUCCEEDED(hr); hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Phone_UI_Input_HardwareButtons).Get(), IID_PPV_ARGS(&d->cameraButtons)); Q_ASSERT_SUCCEEDED(hr); if (qEnvironmentVariableIntValue("QT_QPA_ENABLE_CAMERA_KEYS")) { hr = d->cameraButtons->add_CameraPressed(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraPressed).Get(), &d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraPressed]); Q_ASSERT_SUCCEEDED(hr); hr = d->cameraButtons->add_CameraHalfPressed(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraHalfPressed).Get(), &d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraHalfPressed]); Q_ASSERT_SUCCEEDED(hr); hr = d->cameraButtons->add_CameraReleased(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraReleased).Get(), &d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraReleased]); Q_ASSERT_SUCCEEDED(hr); } d->cameraPressed = false; d->cameraHalfPressed = false; } #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) QEventDispatcherWinRT::runOnXamlThread([d]() { d->mainScreen = new QWinRTScreen; return S_OK; }); d->inputContext.reset(new QWinRTInputContext(d->mainScreen)); screenAdded(d->mainScreen); d->platformServices = new QWinRTServices; d->clipboard = new QWinRTClipboard; }