Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FString FCLionSourceCodeAccessor::FindExecutablePath()
- {
- #if PLATFORM_WINDOWS
- // Search from JetBrainsToolbox folder
- FString ToolboxBinPath;
- if (FWindowsPlatformMisc::QueryRegKey(HKEY_CURRENT_USER, TEXT("Software\\JetBrains s.r.o.\\JetBrainsToolbox\\"), TEXT(""), ToolboxBinPath))
- {
- FPaths::NormalizeDirectoryName(ToolboxBinPath);
- FString PatternString(TEXT("(.*)/bin"));
- FRegexPattern Pattern(PatternString);
- FRegexMatcher Matcher(Pattern, ToolboxBinPath);
- if (Matcher.FindNext())
- {
- FString ToolboxPath = Matcher.GetCaptureGroup(1);
- FString SettingJsonPath = FPaths::Combine(ToolboxPath, FString(".settings.json"));
- if (FPaths::FileExists(SettingJsonPath))
- {
- FString JsonStr;
- FFileHelper::LoadFileToString(JsonStr, *SettingJsonPath);
- TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonStr);
- TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
- if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
- {
- FString InstallLocation;
- if (JsonObject->TryGetStringField(TEXT("install_location"), InstallLocation))
- {
- if (!InstallLocation.IsEmpty())
- {
- ToolboxPath = InstallLocation;
- }
- }
- }
- }
- FString CLionHome = FPaths::Combine(ToolboxPath, FString("apps"), FString("CLion"));
- if (FPaths::DirectoryExists(CLionHome))
- {
- TArray<FString> IDEPaths;
- IFileManager::Get().FindFilesRecursive(IDEPaths, *CLionHome, TEXT("clion64.exe"), true, false);
- if (IDEPaths.Num() > 0)
- {
- return IDEPaths[0];
- }
- }
- }
- }
- // Search from ProgID
- FString OpenCommand;
- if (!FWindowsPlatformMisc::QueryRegKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\clion64.exe\\shell\\open\\command\\"), TEXT(""), OpenCommand))
- {
- FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\clion64.exe\\shell\\open\\command\\"), TEXT(""), OpenCommand);
- }
- FString PatternString(TEXT("\"(.*)\" \".*\""));
- FRegexPattern Pattern(PatternString);
- FRegexMatcher Matcher(Pattern, OpenCommand);
- if (Matcher.FindNext())
- {
- FString IDEPath = Matcher.GetCaptureGroup(1);
- if (FPaths::FileExists(IDEPath))
- {
- return IDEPath;
- }
- }
- #elif PLATFORM_MAC
- // Check for EAP
- NSURL* CLionPreviewURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.jetbrains.CLion-EAP"];
- if (CLionPreviewURL != nullptr)
- {
- return FString([CLionPreviewURL path]);
- }
- // Standard CLion Install
- NSURL* CLionURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.jetbrains.CLion"];
- if (CLionURL != nullptr)
- {
- return FString([CLionURL path]);
- }
- // Failsafe
- if (FPaths::FileExists(TEXT("/Applications/CLion.app/Contents/MacOS/clion")))
- {
- return TEXT("/Applications/CLion.app/Contents/MacOS/clion");
- }
- #else
- // Linux Default Install
- if(FPaths::FileExists(TEXT("/opt/clion/bin/clion.sh")))
- {
- return TEXT("/opt/clion/bin/clion.sh");
- }
- #endif
- // Nothing was found, return nothing as well
- return TEXT("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement