37 const QString &appDesc, QObject* parent)
41 setAppInfo(appRegisteredName, appPath, appIcon, appDesc);
51 _assocDescHash.insert(progId, QPair<QString, QString>(desc, QDir::toNativeSeparators(iconPath)));
54 _fileAssocHash.insert(assocName, progId);
57 _urlAssocHash.insert(assocName, progId);
67 _fileAssocHash.remove(assocName);
68 _urlAssocHash.remove(assocName);
72 const QString &appIcon,
const QString &appDesc)
74 _appRegisteredName = appRegisteredName;
75 _appPath = QDir::toNativeSeparators(appPath);
76 _appIcon = QDir::toNativeSeparators(appIcon);
82 return (_UserRootKey ==
QSL(
"HKEY_LOCAL_MACHINE"));
88 _UserRootKey =
QSL(
"HKEY_LOCAL_MACHINE");
91 _UserRootKey =
QSL(
"HKEY_CURRENT_USER");
101 QSettings regLocalMachine(
QSL(
"HKEY_LOCAL_MACHINE"), QSettings::NativeFormat);
102 QString capabilitiesKey = regLocalMachine.value(
QSL(
"Software/RegisteredApplications/") + _appRegisteredName).toString();
104 if (capabilitiesKey.isEmpty()) {
105 regLocalMachine.setValue(
QSL(
"Software/RegisteredApplications/") + _appRegisteredName,
106 QString(
QSL(
"Software\\") + _appRegisteredName +
QSL(
"\\Capabilities")));
107 capabilitiesKey = regLocalMachine.value(
QSL(
"Software/RegisteredApplications/") + _appRegisteredName).toString();
109 if (capabilitiesKey.isEmpty()) {
110 QMessageBox::warning(
mApp->getWindow(), tr(
"Warning!"),
111 tr(
"There are some problems. Please, reinstall Falkon.\n"
112 "Maybe relaunch with administrator right do a magic for you! ;)"));
117 capabilitiesKey.replace(
QSL(
"\\"),
QSL(
"/"));
119 QHash<QString, QPair<QString, QString> >::const_iterator it = _assocDescHash.constBegin();
120 while (it != _assocDescHash.constEnd()) {
125 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/ApplicationDescription"), _appDesc);
126 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/ApplicationIcon"), _appIcon);
127 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/ApplicationName"), _appRegisteredName);
129 QHash<QString, QString>::const_iterator
i = _fileAssocHash.constBegin();
130 while (
i != _fileAssocHash.constEnd()) {
131 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/FileAssociations/") +
i.key(),
i.value());
135 i = _urlAssocHash.constBegin();
136 while (
i != _urlAssocHash.constEnd()) {
137 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/URLAssociations/") +
i.key(),
i.value());
140 regLocalMachine.setValue(capabilitiesKey +
QSL(
"/Startmenu/StartMenuInternet"), _appPath);
147 return (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA &&
148 QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based);
153 return (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS10 &&
154 QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based);
161 IApplicationAssociationRegistration* pAAR;
163 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
166 __uuidof(IApplicationAssociationRegistration),
171 hr = pAAR->SetAppAsDefault(_appRegisteredName.toStdWString().c_str(),
172 assocName.toStdWString().c_str(),
176 QSettings regCurrentUserRoot(
QSL(
"HKEY_CURRENT_USER"), QSettings::NativeFormat);
177 QString currentUrlDefault =
178 regCurrentUserRoot.value(
QSL(
"Software/Microsoft/Windows/Shell/Associations/UrlAssociations/")
179 + assocName +
QSL(
"/UserChoice/Progid")).toString();
180 hr = pAAR->SetAppAsDefault(_appRegisteredName.toStdWString().c_str(),
181 assocName.toStdWString().c_str(),
184 !currentUrlDefault.isEmpty() &&
185 currentUrlDefault != _urlAssocHash.value(assocName)
187 regCurrentUserRoot.setValue(
QSL(
"Software/Classes")
189 +
QSL(
"/shell/open/command/backup_progid"), currentUrlDefault);
203 QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat);
204 regUserRoot.beginGroup(
QSL(
"Software/Classes"));
205 QSettings regClassesRoot(
QSL(
"HKEY_CLASSES_ROOT"), QSettings::NativeFormat);
208 QString progId = _fileAssocHash.value(assocName);
210 QString currentDefault = regClassesRoot.value(assocName +
QSL(
"/Default")).toString();
211 if (!currentDefault.isEmpty() &&
212 currentDefault != progId &&
213 regUserRoot.value(assocName +
QSL(
"/backup_val")).toString() != progId
215 regUserRoot.setValue(assocName +
QSL(
"/backup_val"), currentDefault);
217 regUserRoot.setValue(assocName +
QSL(
"/."), progId);
221 QString progId = _urlAssocHash.value(assocName);
223 QString currentDefault = regClassesRoot.value(assocName +
QSL(
"/shell/open/command/Default")).toString();
224 QString command =
QSL(
"\"") + _appPath +
QSL(
"\" \"%1\"");
225 if (!currentDefault.isEmpty() &&
226 currentDefault != command &&
227 regUserRoot.value(assocName +
QSL(
"/shell/open/command/backup_val")).toString() != command
229 regUserRoot.setValue(assocName +
QSL(
"/shell/open/command/backup_val"), currentDefault);
232 regUserRoot.setValue(assocName +
QSL(
"/shell/open/command/."), command);
233 regUserRoot.setValue(assocName +
QSL(
"/URL Protocol"),
QSL(
""));
239 regUserRoot.endGroup();
249 QHash<QString, QString>::const_iterator
i = _fileAssocHash.constBegin();
250 while (
i != _fileAssocHash.constEnd()) {
255 i = _urlAssocHash.constBegin();
256 while (
i != _urlAssocHash.constEnd()) {
265 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, 0 , 0);
276#ifdef _WIN32_WINNT_WIN8
277 IApplicationActivationManager* pActivator;
278 HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager,
281 IID_IApplicationActivationManager,
282 (
void**)&pActivator);
284 if (!SUCCEEDED(hr)) {
289 hr = pActivator->ActivateApplication(
290 L
"windows.immersivecontrolpanel_cw5n1h2txyewy"
291 L
"!microsoft.windows.immersivecontrolpanel",
292 L
"page=SettingsPageAppsDefaults", AO_NONE, &pid);
294 if (!SUCCEEDED(hr)) {
300 pActivator->ActivateApplication(
301 L
"windows.immersivecontrolpanel_cw5n1h2txyewy"
302 L
"!microsoft.windows.immersivecontrolpanel",
303 L
"page=SettingsPageAppsDefaults"
304 L
"&target=SystemSettings_DefaultApps_Browser", AO_NONE, &pid);
306 pActivator->Release();
308 IApplicationAssociationRegistrationUI* pAARUI = NULL;
310 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
311 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistrationUI),
312 reinterpret_cast< void**
> (&pAARUI));
314 if (!SUCCEEDED(hr)) {
318 hr = pAARUI->LaunchAdvancedAssociationUI(
reinterpret_cast<LPCWSTR
>(_appRegisteredName.utf16()));
327 QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat);
328 regUserRoot.beginGroup(
QSL(
"Software/Classes"));
329 QPair<QString, QString> pair = _assocDescHash.value(progId);
330 regUserRoot.setValue(progId +
QSL(
"/."), pair.first);
331 regUserRoot.setValue(progId +
QSL(
"/shell/."),
QSL(
"open"));
332 regUserRoot.setValue(progId +
QSL(
"/DefaultIcon/."), pair.second);
333 regUserRoot.setValue(progId +
QSL(
"/shell/open/command/."), QString(
QSL(
"\"") + _appPath +
QSL(
"\" \"%1\"")));
334 regUserRoot.endGroup();
340 QSettings regCurrentUserRoot(
QSL(
"HKEY_CURRENT_USER"), QSettings::NativeFormat);
343 regCurrentUserRoot.beginGroup(
QSL(
"Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts"));
344 if (regCurrentUserRoot.childGroups().contains(assocName, Qt::CaseInsensitive)) {
345 return (_fileAssocHash.value(assocName)
346 == regCurrentUserRoot.value(assocName +
QSL(
"/UserChoice/Progid")));
349 regCurrentUserRoot.endGroup();
355 regCurrentUserRoot.beginGroup(
QSL(
"Software/Microsoft/Windows/Shell/Associations/UrlAssociations"));
356 if (regCurrentUserRoot.childGroups().contains(assocName, Qt::CaseInsensitive)) {
357 return (_urlAssocHash.value(assocName)
358 == regCurrentUserRoot.value(assocName +
QSL(
"/UserChoice/Progid")));
361 regCurrentUserRoot.endGroup();
372 QSettings regClassesRoot(
QSL(
"HKEY_CLASSES_ROOT"), QSettings::NativeFormat);
374 if (!regClassesRoot.childGroups().contains(assocName, Qt::CaseInsensitive)) {
380 return (_fileAssocHash.value(assocName)
381 == regClassesRoot.value(assocName +
QSL(
"/Default")));
385 QString currentDefault = regClassesRoot.value(assocName +
QSL(
"/shell/open/command/Default")).toString();
386 currentDefault.remove(
QSL(
"\""));
387 currentDefault.remove(
QSL(
"%1"));
388 currentDefault = currentDefault.trimmed();
389 return (_appPath == currentDefault);
404 QHash<QString, QString>::const_iterator
i = _fileAssocHash.constBegin();
405 while (
i != _fileAssocHash.constEnd()) {
411 i = _urlAssocHash.constBegin();
412 while (
i != _urlAssocHash.constEnd()) {
bool isDefaultApp(const QString &assocName, AssociationType type)
bool showNativeDefaultAppSettingsUi()
void setAppInfo(const QString &appRegisteredName, const QString &appPath, const QString &appIcon=QString(), const QString &appDesc=QString())
bool isPerMachineRegisteration()
bool registerAppCapabilities()
void removeCapability(const QString &assocName)
void addCapability(const QString &assocName, const QString &progId, const QString &desc, const QString &iconPath, AssociationType type)
void registerAssociation(const QString &assocName, AssociationType type)
~RegisterQAppAssociation()
bool isDefaultForAllCapabilities()
void registerAllAssociation()
void setPerMachineRegisteration(bool enable)
RegisterQAppAssociation(QObject *parent=nullptr)
void createProgId(const QString &progId)