Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1.  
  2. FString FCLionSourceCodeAccessor::FindExecutablePath()
  3. {
  4. #if PLATFORM_WINDOWS
  5. // Search from JetBrainsToolbox folder
  6. FString ToolboxBinPath;
  7.  
  8. if (FWindowsPlatformMisc::QueryRegKey(HKEY_CURRENT_USER, TEXT("Software\\JetBrains s.r.o.\\JetBrainsToolbox\\"), TEXT(""), ToolboxBinPath))
  9. {
  10. FPaths::NormalizeDirectoryName(ToolboxBinPath);
  11. FString PatternString(TEXT("(.*)/bin"));
  12. FRegexPattern Pattern(PatternString);
  13. FRegexMatcher Matcher(Pattern, ToolboxBinPath);
  14. if (Matcher.FindNext())
  15. {
  16. FString ToolboxPath = Matcher.GetCaptureGroup(1);
  17.  
  18. FString SettingJsonPath = FPaths::Combine(ToolboxPath, FString(".settings.json"));
  19. if (FPaths::FileExists(SettingJsonPath))
  20. {
  21. FString JsonStr;
  22. FFileHelper::LoadFileToString(JsonStr, *SettingJsonPath);
  23. TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonStr);
  24. TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
  25. if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
  26. {
  27. FString InstallLocation;
  28. if (JsonObject->TryGetStringField(TEXT("install_location"), InstallLocation))
  29. {
  30. if (!InstallLocation.IsEmpty())
  31. {
  32. ToolboxPath = InstallLocation;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. FString CLionHome = FPaths::Combine(ToolboxPath, FString("apps"), FString("CLion"));
  39. if (FPaths::DirectoryExists(CLionHome))
  40. {
  41. TArray<FString> IDEPaths;
  42. IFileManager::Get().FindFilesRecursive(IDEPaths, *CLionHome, TEXT("clion64.exe"), true, false);
  43. if (IDEPaths.Num() > 0)
  44. {
  45. return IDEPaths[0];
  46. }
  47. }
  48. }
  49. }
  50.  
  51. // Search from ProgID
  52. FString OpenCommand;
  53. if (!FWindowsPlatformMisc::QueryRegKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\clion64.exe\\shell\\open\\command\\"), TEXT(""), OpenCommand))
  54. {
  55. FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\clion64.exe\\shell\\open\\command\\"), TEXT(""), OpenCommand);
  56. }
  57.  
  58. FString PatternString(TEXT("\"(.*)\" \".*\""));
  59. FRegexPattern Pattern(PatternString);
  60. FRegexMatcher Matcher(Pattern, OpenCommand);
  61. if (Matcher.FindNext())
  62. {
  63. FString IDEPath = Matcher.GetCaptureGroup(1);
  64. if (FPaths::FileExists(IDEPath))
  65. {
  66. return IDEPath;
  67. }
  68. }
  69.  
  70. #elif PLATFORM_MAC
  71.  
  72. // Check for EAP
  73. NSURL* CLionPreviewURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.jetbrains.CLion-EAP"];
  74. if (CLionPreviewURL != nullptr)
  75. {
  76. return FString([CLionPreviewURL path]);
  77. }
  78.  
  79. // Standard CLion Install
  80. NSURL* CLionURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.jetbrains.CLion"];
  81. if (CLionURL != nullptr)
  82. {
  83. return FString([CLionURL path]);
  84. }
  85.  
  86. // Failsafe
  87. if (FPaths::FileExists(TEXT("/Applications/CLion.app/Contents/MacOS/clion")))
  88. {
  89. return TEXT("/Applications/CLion.app/Contents/MacOS/clion");
  90. }
  91.  
  92. #else
  93.  
  94. // Linux Default Install
  95. if(FPaths::FileExists(TEXT("/opt/clion/bin/clion.sh")))
  96. {
  97. return TEXT("/opt/clion/bin/clion.sh");
  98. }
  99. #endif
  100.  
  101. // Nothing was found, return nothing as well
  102. return TEXT("");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement