@@ -403,6 +403,175 @@ void CloseLiveBrowser(CefRefPtr<CefBrowser> browser, CefRefPtr<CefProcessMessage
403
403
}
404
404
}
405
405
406
+
407
+ static BOOL ResolveAppPathCommon (const ExtensionString& lpszKey, const ExtensionString& lpszVal, ExtensionString& appPath)
408
+ {
409
+ HKEY keyRoot = NULL ;
410
+ BOOL result = FALSE ;
411
+ ULONG regKey (REG_SZ);
412
+
413
+ if (::RegOpenKeyEx (HKEY_CLASSES_ROOT, lpszKey.c_str (), 0 , KEY_QUERY_VALUE, &keyRoot) == ERROR_SUCCESS)
414
+ {
415
+ TCHAR editorPath[255 ];
416
+ ULONG fTypeSize = 255 ;
417
+
418
+ if (::RegQueryValueEx (keyRoot, lpszVal.c_str (), NULL , ®Key, (LPBYTE)editorPath, &fTypeSize ) == ERROR_SUCCESS)
419
+ {
420
+ if (editorPath != L" " )
421
+ {
422
+ appPath = editorPath;
423
+ // appPath = appPath.substr(appPath.find_last_of(L"/\\") + 1);
424
+ int iExe = appPath.find (L" .exe" );
425
+ if (iExe == -1 )
426
+ iExe = appPath.find (L" .EXE" );
427
+ if (iExe != -1 )
428
+ appPath = appPath.substr (0 , iExe+4 );
429
+
430
+ if (appPath[0 ] == ' \" ' )
431
+ appPath = appPath.substr (1 );
432
+
433
+ result = TRUE ;
434
+ }
435
+
436
+
437
+ }
438
+ ::RegCloseKey (keyRoot);
439
+ }
440
+
441
+ return result;
442
+
443
+ }
444
+
445
+ static BOOL ResolveAppPathFromProgID (const ExtensionString& lpszProgID, ExtensionString& appPath)
446
+ {
447
+
448
+ ExtensionString key = lpszProgID + L" \\ shell\\ open\\ command" ;
449
+
450
+
451
+ if (!ResolveAppPathCommon (key, L" " , appPath))
452
+ {
453
+ key = lpszProgID + L" \\ Application" ;
454
+ if (ResolveAppPathCommon (key, L" AppUserModelID" , appPath)) {
455
+ appPath = appPath.substr (0 , appPath.find (L" _" ));
456
+ return true ;
457
+ }
458
+ return false ;
459
+ }
460
+ return true ;
461
+
462
+ }
463
+
464
+ BOOL GetShellDefaultOpenWithProgPath (const ExtensionString& fileExt, ExtensionString &appPath)
465
+ {
466
+ HKEY extKey = NULL ;
467
+ ExtensionString key = fileExt;
468
+ BOOL result = FALSE ;
469
+ ULONG regKey (REG_SZ);
470
+
471
+ if (fileExt.empty ())
472
+ return false ;
473
+
474
+ if (fileExt[0 ] != ' .' )
475
+ key = L" ." + fileExt;
476
+
477
+ key = L" Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ FileExts\\ " + key + L" \\ UserChoice" ;
478
+
479
+ if (::RegOpenKeyEx (HKEY_CURRENT_USER, key.c_str (), 0 , KEY_QUERY_VALUE, &extKey) == ERROR_SUCCESS)
480
+ {
481
+ TCHAR editorPath[255 ];
482
+ ULONG fTypeSize = 255 ;
483
+
484
+ if (::RegQueryValueEx (extKey, L" Progid" , NULL , ®Key, (LPBYTE)editorPath, &fTypeSize ) == ERROR_SUCCESS)
485
+ {
486
+ result = ResolveAppPathFromProgID (editorPath, appPath);
487
+
488
+ }
489
+
490
+ ::RegCloseKey (extKey);
491
+ }
492
+
493
+ return result;
494
+ }
495
+
496
+
497
+ BOOL GetLegacyWin32SystemEditor (const ExtensionString& fileExt, ExtensionString &appPath)
498
+ {
499
+ HKEY rootKey;
500
+ ULONG regKey (REG_SZ);
501
+ ExtensionString key = fileExt;
502
+
503
+ if (fileExt.empty ())
504
+ return false ;
505
+
506
+ if (fileExt[0 ] != ' .' )
507
+ key = L" ." + key;
508
+
509
+ // find the key for the file extension
510
+ if (RegOpenKeyEx (HKEY_CLASSES_ROOT, key.c_str (), 0 , KEY_QUERY_VALUE, &rootKey) == ERROR_SUCCESS)
511
+ {
512
+ TCHAR nextKeyStr[255 ];
513
+ ULONG strSize = 255 ;
514
+ // get the value of the key
515
+ if (RegQueryValueEx (rootKey, L" " , NULL , ®Key,
516
+ (LPBYTE)nextKeyStr, &strSize) == ERROR_SUCCESS)
517
+ {
518
+ RegCloseKey (rootKey);
519
+ return ResolveAppPathFromProgID (nextKeyStr, appPath);
520
+ }
521
+ RegCloseKey (rootKey);
522
+ }
523
+
524
+ key = key + L" \\ OpenWithProgids" ;
525
+ HKEY extKey;
526
+ // find the key for the file extension
527
+ if (RegOpenKeyEx (HKEY_CLASSES_ROOT, key.c_str (), 0 , KEY_QUERY_VALUE | KEY_READ, &extKey) == ERROR_SUCCESS)
528
+ {
529
+ TCHAR subKeyStr[255 ];
530
+ ULONG subKeySize = 255 ;
531
+ DWORD index = 0 ;
532
+ LONG err = RegEnumValue (extKey, index , subKeyStr, &subKeySize,
533
+ 0 , 0 , 0 , NULL );
534
+ if (err != ERROR_NO_MORE_ITEMS)
535
+ {
536
+ RegCloseKey (extKey);
537
+ return ResolveAppPathFromProgID (subKeyStr, appPath);
538
+ }
539
+
540
+ RegCloseKey (extKey);
541
+ }
542
+
543
+ return FALSE ;
544
+ }
545
+
546
+ int32 getSystemDefaultApp (const ExtensionString& fileTypes, ExtensionString& fileTypesWithdefaultApp)
547
+ {
548
+ wchar_t * nextPtr;
549
+ wchar_t delim[] = L" ," ;
550
+ std::vector<ExtensionString> extArray;
551
+ ExtensionString separator = L" ##" ;
552
+
553
+ wchar_t * token = std::wcstok ((wchar_t *)fileTypes.c_str (), delim, &nextPtr);
554
+
555
+ while (token) {
556
+ extArray.push_back (token);
557
+ token = wcstok (NULL , delim, &nextPtr);
558
+ }
559
+
560
+ for (std::vector<ExtensionString>::const_iterator it = extArray.begin (); it != extArray.end (); ++it) {
561
+ ExtensionString appPath;
562
+ BOOL result = GetShellDefaultOpenWithProgPath (*it, appPath);
563
+
564
+ if (!result)
565
+ result = GetLegacyWin32SystemEditor (*it, appPath);
566
+
567
+ if (result)
568
+ fileTypesWithdefaultApp = fileTypesWithdefaultApp + *it + separator + appPath + L" ," ;
569
+ }
570
+
571
+ return NO_ERROR;
572
+
573
+ }
574
+
406
575
int32 OpenURLInDefaultBrowser (ExtensionString url)
407
576
{
408
577
DWORD result = (DWORD)ShellExecute (NULL , L" open" , url.c_str (), NULL , NULL , SW_SHOWNORMAL);
0 commit comments