Merging //UE4/Release-4.18 @ CL 3709383 to Release-Staging-4.18 (//UE4/Release-Staging-4.18)

#rb none
#jira

[CL 3715930 by Ben Marsh in Staging-4.18 branch]
This commit is contained in:
Ben Marsh
2017-10-24 10:14:07 -04:00
parent 78a8df58c1
commit d832dacf48
635 changed files with 16341 additions and 9333 deletions

View File

@@ -7,6 +7,7 @@
#include "DesktopPlatformModule.h"
#include "Misc/Paths.h"
#include "Misc/ScopeLock.h"
#include "Misc/UProjectInfo.h"
#if PLATFORM_WINDOWS
#include "AllowWindowsPlatformTypes.h"
@@ -17,17 +18,25 @@ DEFINE_LOG_CATEGORY_STATIC(LogVSCodeAccessor, Log, All);
#define LOCTEXT_NAMESPACE "VisualStudioCodeSourceCodeAccessor"
static FString MakePath(const FString& InPath)
{
return TEXT("\"") + InPath + TEXT("\"");
}
FString FVisualStudioCodeSourceCodeAccessor::GetSolutionPath() const
{
FScopeLock Lock(&CachedSolutionPathCriticalSection);
if (IsInGameThread())
{
FString SolutionPath;
if (FDesktopPlatformModule::Get()->GetSolutionPath(SolutionPath))
CachedSolutionPath = FPaths::ProjectDir();
if (!FUProjectDictionary(FPaths::RootDir()).IsForeignProject(CachedSolutionPath))
{
CachedSolutionPath = FPaths::ConvertRelativePathToFull(SolutionPath);
CachedSolutionPath = FPaths::RootDir();
}
}
return CachedSolutionPath;
}
@@ -46,8 +55,9 @@ void FVisualStudioCodeSourceCodeAccessor::Startup()
void FVisualStudioCodeSourceCodeAccessor::RefreshAvailability()
{
FString IDEPath;
#if PLATFORM_WINDOWS
FString IDEPath;
if (!FWindowsPlatformMisc::QueryRegKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command\\"), TEXT(""), IDEPath))
{
FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command\\"), TEXT(""), IDEPath);
@@ -58,18 +68,25 @@ void FVisualStudioCodeSourceCodeAccessor::RefreshAvailability()
FRegexMatcher Matcher(Pattern, IDEPath);
if (Matcher.FindNext())
{
IDEPath = Matcher.GetCaptureGroup(1);
FString URL = Matcher.GetCaptureGroup(1);
if (FPaths::FileExists(URL))
{
Location.URL = URL;
}
}
#elif PLATFORM_LINUX
FString URL = TEXT("/usr/bin/code");
if (FPaths::FileExists(URL))
{
Location.URL = URL;
}
#elif PLATFORM_MAC
NSURL* AppURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.microsoft.VSCode"];
if (AppURL != nullptr)
{
Location.URL = FString([AppURL path]);
}
#endif
if (IDEPath.Len() > 0 && FPaths::FileExists(IDEPath))
{
Location = IDEPath;
}
else
{
Location = TEXT("");
}
}
void FVisualStudioCodeSourceCodeAccessor::Shutdown()
@@ -78,16 +95,18 @@ void FVisualStudioCodeSourceCodeAccessor::Shutdown()
bool FVisualStudioCodeSourceCodeAccessor::OpenSourceFiles(const TArray<FString>& AbsoluteSourcePaths)
{
if (Location.Len() > 0)
if (Location.IsValid())
{
FString Args;
FString SolutionDir = GetSolutionPath();
TArray<FString> Args;
Args.Add(MakePath(SolutionDir));
for (const FString& SourcePath : AbsoluteSourcePaths)
{
Args += TEXT("\"") + SourcePath + TEXT("\" ");
Args.Add(MakePath(SourcePath));
}
return FPlatformProcess::ExecProcess(*Location, *Args, nullptr, nullptr, nullptr);
return Launch(Args);
}
return false;
@@ -100,18 +119,31 @@ bool FVisualStudioCodeSourceCodeAccessor::AddSourceFiles(const TArray<FString>&
bool FVisualStudioCodeSourceCodeAccessor::OpenFileAtLine(const FString& FullPath, int32 LineNumber, int32 ColumnNumber)
{
if (Location.IsValid())
{
// Column & line numbers are 1-based, so dont allow zero
LineNumber = LineNumber > 0 ? LineNumber : 1;
ColumnNumber = ColumnNumber > 0 ? ColumnNumber : 1;
FString SolutionDir = GetSolutionPath();
TArray<FString> Args;
Args.Add(MakePath(SolutionDir));
Args.Add(TEXT("-g ") + MakePath(FullPath) + FString::Printf(TEXT(":%d:%d"), LineNumber, ColumnNumber));
return Launch(Args);
}
return false;
}
bool FVisualStudioCodeSourceCodeAccessor::CanAccessSourceCode() const
{
// True if we have any versions of VS installed
return Location.Len() > 0;
return Location.IsValid();
}
FName FVisualStudioCodeSourceCodeAccessor::GetFName() const
{
return FName("VisualStudioCodeSourceCodeAccessor");
return FName("VisualStudioCode");
}
FText FVisualStudioCodeSourceCodeAccessor::GetNameText() const
@@ -130,21 +162,59 @@ void FVisualStudioCodeSourceCodeAccessor::Tick(const float DeltaTime)
bool FVisualStudioCodeSourceCodeAccessor::OpenSolution()
{
if (Location.Len() > 0)
if (Location.IsValid())
{
FString SolutionDir = FPaths::GetPath(GetSolutionPath());
uint32 ProcessID;
FProcHandle hProcess = FPlatformProcess::CreateProc(*Location, *SolutionDir, true, false, false, &ProcessID, 0, nullptr, nullptr, nullptr);
return hProcess.IsValid();
FString SolutionDir = FPaths::Combine(GetSolutionPath(), TEXT("UE4"));
return OpenSolutionAtPath(SolutionDir);
}
return false;
}
bool FVisualStudioCodeSourceCodeAccessor::OpenSolutionAtPath(const FString& InSolutionPath)
{
if (Location.IsValid())
{
// Strip top element from the path. When creating new projects, this will be the base name of the solution which we don't need,
// or if being called from OpenSolution() it will be a dummy "UE4" element that we added just so it can be stripped here
FString SolutionPath = FPaths::GetPath(InSolutionPath);
TArray<FString> Args;
Args.Add(MakePath(SolutionPath));
return Launch(Args);
}
return false;
}
bool FVisualStudioCodeSourceCodeAccessor::DoesSolutionExist() const
{
FString VSCodeDir = FPaths::Combine(GetSolutionPath(), TEXT(".vscode"));
return FPaths::DirectoryExists(VSCodeDir);
}
bool FVisualStudioCodeSourceCodeAccessor::SaveAllOpenDocuments() const
{
return false;
}
bool FVisualStudioCodeSourceCodeAccessor::Launch(const TArray<FString>& InArgs)
{
if (Location.IsValid())
{
FString ArgsString;
for (const FString& Arg : InArgs)
{
ArgsString.Append(Arg);
ArgsString.Append(TEXT(" "));
}
#undef LOCTEXT_NAMESPACE
uint32 ProcessID;
FProcHandle hProcess = FPlatformProcess::CreateProc(*Location.URL, *ArgsString, true, false, false, &ProcessID, 0, nullptr, nullptr, nullptr);
return hProcess.IsValid();
}
return false;
}
#undef LOCTEXT_NAMESPACE

View File

@@ -23,6 +23,8 @@ public:
virtual FText GetNameText() const override;
virtual FText GetDescriptionText() const override;
virtual bool OpenSolution() override;
virtual bool OpenSolutionAtPath(const FString& InSolutionPath) override;
virtual bool DoesSolutionExist() const override;
virtual bool OpenFileAtLine(const FString& FullPath, int32 LineNumber, int32 ColumnNumber = 0) override;
virtual bool OpenSourceFiles(const TArray<FString>& AbsoluteSourcePaths) override;
virtual bool AddSourceFiles(const TArray<FString>& AbsoluteSourcePaths, const TArray<FString>& AvailableModules) override;
@@ -31,8 +33,19 @@ public:
private:
/** The versions of VS we support, in preference order */
FString Location;
/** Wrapper for vscode executable launch information */
struct FLocation
{
bool IsValid() const
{
return URL.Len() > 0;
}
FString URL;
};
/** Location instance */
FLocation Location;
/** String storing the solution path obtained from the module manager to avoid having to use it on a thread */
mutable FString CachedSolutionPath;
@@ -42,4 +55,7 @@ private:
/** Accessor for SolutionPath. Will try to update it when called from the game thread, otherwise will use the cached value */
FString GetSolutionPath() const;
/** Helper function for launching the VSCode instance with the given list of arguments */
bool Launch(const TArray<FString>& InArgs);
};