bool WindowsPlatformIntegration::setAsDefaultBrowser() { if (!isBrowserRegistered() && !registerToSystem()) { return false; } QSettings registry(QLatin1String("HKEY_CURRENT_USER\\Software"), QSettings::NativeFormat); for (int i = 0; i < m_registrationPairs.count(); ++i) { if (m_registrationPairs.at(i).second == ProtocolType) { registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/DefaultIcon/."), m_applicationFilePath + QLatin1String(",1")); registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/shell/open/command/."), QLatin1String("\"") + m_applicationFilePath + QLatin1String("\" \"%1\"")); } else { registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/."), m_registrationIdentifier); } } registry.setValue(QLatin1String("Clients/StartmenuInternet/."), m_registrationIdentifier); registry.sync(); if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { IApplicationAssociationRegistrationUI *applicationAssociationRegistrationUI = NULL; HRESULT result = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, NULL, CLSCTX_INPROC_SERVER, IID_IApplicationAssociationRegistrationUI, (LPVOID*)&applicationAssociationRegistrationUI); if (result == S_OK && applicationAssociationRegistrationUI) { result = applicationAssociationRegistrationUI->LaunchAdvancedAssociationUI(m_registrationIdentifier.toStdWString().c_str()); applicationAssociationRegistrationUI->Release(); if (result == S_OK) { return true; } } Console::addMessage(QCoreApplication::translate("main", "Failed to run File Associations Manager, error code: %1").arg(result), Otter::OtherMessageCategory, ErrorMessageLevel); } else { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_DWORD | SHCNF_FLUSH, NULL, NULL); Sleep(1000); } return true; }
bool CFileAssoc::ShowWindowsAssocDialog() const { IApplicationAssociationRegistrationUI* pAARUI; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&pAARUI)); bool success = (SUCCEEDED(hr) && pAARUI != nullptr); if (success) { pAARUI->LaunchAdvancedAssociationUI(m_strRegisteredAppName); pAARUI->Release(); } return success; }