Files
UnrealEngineUWP/Engine/Source/Programs/UnrealSync/Private/ProcessHelper.cpp
Jaroslaw Palczynski 2477b5bd67 UnrealSync3 improvements:
- Moved UAT functionality to US3 -- now the GUI doesn't need UAT anymore.
- The tool is syncing itself at startup and by default runs from copy. It assumes that Binaries/Win64 is writable, but I think its fine cause this tool is needed for syncing anyway.
- User have to provide P4 port and P4 user from command line or from environment variables. It is also assumed that p4.exe is runnable from standard cmd.exe without providing a path.

[CL 2094445 by Jaroslaw Palczynski in Main branch]
2014-06-04 11:01:22 -04:00

94 lines
2.3 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "UnrealSync.h"
#include "ProcessHelper.h"
/**
* Triggers progress event.
*
* @param Input Input string to pass.
* @param OnProcessMadeProgress Progress delegate to pass input.
*
* @returns Passes down the result of OnUATMadeProgress which tells if process should continue.
*/
bool TriggerProgress(const FString& Input, const FOnProcessMadeProgress& OnProcessMadeProgress)
{
if (OnProcessMadeProgress.IsBound())
{
return OnProcessMadeProgress.Execute(Input);
}
return true;
}
bool RunProcess(const FString& ExecutablePath, const FString& CommandLine)
{
return RunProcessProgress(ExecutablePath, CommandLine, nullptr);
}
bool RunProcessOutput(const FString& ExecutablePath, const FString& CommandLine, FString& Output)
{
class FOutputCollector
{
public:
bool Progress(const FString& Chunk)
{
Output += Chunk;
return true;
}
FString Output;
};
FOutputCollector OC;
if (!RunProcessProgress(ExecutablePath, CommandLine, FOnProcessMadeProgress::CreateRaw(&OC, &FOutputCollector::Progress)))
{
return false;
}
Output = OC.Output;
return true;
}
bool RunProcessProgress(const FString& ExecutablePath, const FString& CommandLine, const FOnProcessMadeProgress& OnProcessMadeProgress)
{
if (!OnProcessMadeProgress.IsBound())
{
FPlatformProcess::CreateProc(*ExecutablePath, *CommandLine, true, false, false, NULL, 0, NULL, NULL);
return true;
}
void* ReadPipe;
void* WritePipe;
FPlatformProcess::CreatePipe(ReadPipe, WritePipe);
FProcHandle ProcessHandle = FPlatformProcess::CreateProc(*ExecutablePath, *CommandLine, false, true, true, NULL, 0, NULL, WritePipe);
while (FPlatformProcess::IsProcRunning(ProcessHandle))
{
if (!TriggerProgress(FPlatformProcess::ReadPipe(ReadPipe), OnProcessMadeProgress))
{
FPlatformProcess::TerminateProc(ProcessHandle);
FPlatformProcess::WaitForProc(ProcessHandle);
return false;
}
FPlatformProcess::Sleep(0.25);
}
FPlatformProcess::WaitForProc(ProcessHandle);
TriggerProgress(FPlatformProcess::ReadPipe(ReadPipe), OnProcessMadeProgress);
FPlatformProcess::ClosePipe(ReadPipe, WritePipe);
int32 ReturnCode;
if (!FPlatformProcess::GetProcReturnCode(ProcessHandle, &ReturnCode))
{
return false;
}
return ReturnCode == 0;
}