Skip to content

Commit

Permalink
Move the OS dependant logic into a new PlasticSourceControlUtils::Fin…
Browse files Browse the repository at this point in the history
…dDesktopApplicationPath()
  • Loading branch information
SRombautsU committed Jan 18, 2024
1 parent f87459a commit 38f8bdd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
37 changes: 6 additions & 31 deletions Source/PlasticSourceControl/Private/PlasticSourceControlMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#include "PlasticSourceControlBranchesWindow.h"
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlOperations.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlStyle.h"
#include "PlasticSourceControlOperations.h"
#include "PlasticSourceControlUtils.h"
#include "SPlasticSourceControlStatusBar.h"

#include "ISourceControlModule.h"
Expand All @@ -33,12 +34,6 @@
#include "ToolMenus.h"
#include "ToolMenuMisc.h"

#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/WindowsPlatformMisc.h"
#undef GetUserName
#endif

#define LOCTEXT_NAMESPACE "PlasticSourceControl"

FName FPlasticSourceControlMenu::UnityVersionControlMainMenuOwnerName = TEXT("UnityVersionControlMenu");
Expand Down Expand Up @@ -539,35 +534,15 @@ void FPlasticSourceControlMenu::VisitLockRulesURLClicked(const FString InOrganiz

void FPlasticSourceControlMenu::OpenDeskoptApp() const
{
#if PLATFORM_WINDOWS
// On Windows, use the registry to find the install location
FString InstallLocation = TEXT("C:/Program Files/PlasticSCM5");
if (FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Unity Software Inc.\\Unity DevOps Version Control"), TEXT("Location"), InstallLocation))
{
FPaths::NormalizeDirectoryName(InstallLocation);
}

const TCHAR* PlasticExe = TEXT("client/plastic.exe");
const TCHAR* GluonExe = TEXT("client/gluon.exe");
const FString DeskoptAppPath = FPaths::Combine(InstallLocation, FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_MAC
const TCHAR* PlasticExe = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx";
const TCHAR* GluonExe = "/Applications/Gluon.app/Contents/MacOS/macgluonx";
const TCHAR* DeskoptAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_LINUX
const TCHAR* PlasticExe = "/usr/bin/plasticgui ";
const TCHAR* GluonExe = "/usr/bin/gluon";
const TCHAR* DeskoptAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#endif

const FString DesktopAppPath = PlasticSourceControlUtils::FindDesktopApplicationPath();
const FString CommandLineArguments = FString::Printf(TEXT("--wk=\"%s\""), *FPlasticSourceControlModule::Get().GetProvider().GetPathToWorkspaceRoot());

UE_LOG(LogSourceControl, Log, TEXT("Opening the Desktop application (%s %s)"), *InstallLocation, *CommandLineArguments);
UE_LOG(LogSourceControl, Log, TEXT("Opening the Desktop application (%s %s)"), *DesktopAppPath, *CommandLineArguments);

FProcHandle Proc = FPlatformProcess::CreateProc(*DeskoptAppPath, *CommandLineArguments, true, false, false, nullptr, 0, nullptr, nullptr, nullptr);
FProcHandle Proc = FPlatformProcess::CreateProc(*DesktopAppPath, *CommandLineArguments, true, false, false, nullptr, 0, nullptr, nullptr, nullptr);
if (!Proc.IsValid())
{
UE_LOG(LogSourceControl, Error, TEXT("Opening the Desktop application (%s %s) failed."), *DeskoptAppPath, *CommandLineArguments);
UE_LOG(LogSourceControl, Error, TEXT("Opening the Desktop application (%s %s) failed."), *DesktopAppPath, *CommandLineArguments);
FPlatformProcess::CloseProc(Proc);
}
}
Expand Down
34 changes: 34 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include "PlasticSourceControlChangelistState.h"
#endif

#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/WindowsPlatformMisc.h"
#undef GetUserName
#endif

namespace PlasticSourceControlUtils
{

Expand Down Expand Up @@ -58,6 +64,34 @@ FString FindPlasticBinaryPath()
#endif
}

FString FindDesktopApplicationPath()
{
FString DesktopAppPath;

#if PLATFORM_WINDOWS
// On Windows, use the registry to find the install location
FString InstallLocation = TEXT("C:/Program Files/PlasticSCM5");
if (FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Unity Software Inc.\\Unity DevOps Version Control"), TEXT("Location"), InstallLocation))
{
FPaths::NormalizeDirectoryName(InstallLocation);
}

const TCHAR* PlasticExe = TEXT("client/plastic.exe");
const TCHAR* GluonExe = TEXT("client/gluon.exe");
DesktopAppPath = FPaths::Combine(InstallLocation, FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_MAC
const TCHAR* PlasticExe = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx";
const TCHAR* GluonExe = "/Applications/Gluon.app/Contents/MacOS/macgluonx";
DesktopAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_LINUX
const TCHAR* PlasticExe = "/usr/bin/plasticgui ";
const TCHAR* GluonExe = "/usr/bin/gluon";
DesktopAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#endif

return DesktopAppPath;
}

// Find the root of the workspace, looking from the provided path and upward in its parent directories.
bool GetWorkspacePath(const FString& InPath, FString& OutWorkspaceRoot)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool RunCommand(const FString& InCommand, const TArray<FString>& InParameters, c
*/
FString FindPlasticBinaryPath();

/**
* Find the path to the Desktop Application: uses the registry on Windows.
*/
FString FindDesktopApplicationPath();

/**
* Find the root of the Plastic workspace, looking from the GameDir and upward in its parent directories
* @param InPathToGameDir The path to the Game Directory
Expand Down

0 comments on commit 38f8bdd

Please sign in to comment.