MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / registerFileAssociation

Function registerFileAssociation

app/src/Platform/AppPlatform.cpp:515–554  ·  view source on GitHub ↗

* @brief Registers .ssproj with this executable in the Windows registry (HKCU). */

Source from the content-addressed store, hash-verified

513 * @brief Registers .ssproj with this executable in the Windows registry (HKCU).
514 */
515void registerFileAssociation()
516{
517#ifdef Q_OS_WIN
518 const QString exePath = QCoreApplication::applicationFilePath().replace('/', '\\');
519 const QString progId = QStringLiteral("SerialStudio.ssproj");
520 const QString openCmd =
521 QStringLiteral("\"%1\" --project \"%2\"").arg(exePath, QStringLiteral("%1"));
522
523 auto writeKey = [](const QString& path, const QString& value) {
524 HKEY hKey = nullptr;
525 auto status = RegCreateKeyExW(HKEY_CURRENT_USER,
526 reinterpret_cast<LPCWSTR>(path.utf16()),
527 0,
528 nullptr,
529 0,
530 KEY_WRITE,
531 nullptr,
532 &hKey,
533 nullptr);
534
535 if (status == ERROR_SUCCESS) {
536 RegSetValueExW(hKey,
537 nullptr,
538 0,
539 REG_SZ,
540 reinterpret_cast<const BYTE*>(value.utf16()),
541 static_cast<DWORD>((value.size() + 1) * sizeof(wchar_t)));
542 RegCloseKey(hKey);
543 }
544 };
545
546 const QString progIdPath = QStringLiteral("Software\\Classes\\%1").arg(progId);
547 writeKey(progIdPath, QStringLiteral("Serial Studio Project"));
548 writeKey(progIdPath + QStringLiteral("\\DefaultIcon"), QStringLiteral("\"%1\",0").arg(exePath));
549 writeKey(progIdPath + QStringLiteral("\\shell\\open\\command"), openCmd);
550 writeKey(QStringLiteral("Software\\Classes\\.ssproj"), progId);
551
552 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
553#endif
554}
555
556// code-verify off (mirrors malloc above; pair with adjustArgumentsForFreeType / injectPlatformArg)
557/**

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected