2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-05-21 08:45:24 -04:00
|
|
|
|
|
|
|
|
#include "UnrealSync.h"
|
|
|
|
|
|
|
|
|
|
#include "P4DataCache.h"
|
|
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
#include "P4Env.h"
|
|
|
|
|
#include "Internationalization/Regex.h"
|
|
|
|
|
|
2014-05-21 08:45:24 -04:00
|
|
|
bool FP4DataCache::LoadFromLog(const FString& UnrealSyncListLog)
|
|
|
|
|
{
|
2014-06-04 11:01:22 -04:00
|
|
|
const FRegexPattern Pattern(TEXT("Label ([^ ]+) (\\d{4})/(\\d{2})/(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})")); // '.+\\n
|
2014-05-21 08:45:24 -04:00
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
FRegexMatcher Matcher(Pattern, UnrealSyncListLog);
|
2014-05-21 08:45:24 -04:00
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
while (Matcher.FindNext())
|
2014-05-21 08:45:24 -04:00
|
|
|
{
|
2014-06-04 11:01:22 -04:00
|
|
|
Labels.Add(FP4Label(
|
2015-04-27 02:46:47 -04:00
|
|
|
Matcher.GetCaptureGroup(1),
|
2014-06-04 11:01:22 -04:00
|
|
|
FDateTime(
|
2015-04-27 02:46:47 -04:00
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(2)),
|
|
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(3)),
|
|
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(4)),
|
|
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(5)),
|
|
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(6)),
|
|
|
|
|
FCString::Atoi(*Matcher.GetCaptureGroup(7))
|
2014-06-04 11:01:22 -04:00
|
|
|
)));
|
2014-05-21 08:45:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Labels.Sort(
|
|
|
|
|
[](const FP4Label& LabelA, const FP4Label& LabelB)
|
|
|
|
|
{
|
|
|
|
|
return LabelA.GetDate() > LabelB.GetDate();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TArray<FP4Label>& FP4DataCache::GetLabels()
|
|
|
|
|
{
|
|
|
|
|
return Labels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FP4Label::FP4Label(const FString& Name, const FDateTime& Date)
|
|
|
|
|
: Name(Name), Date(Date)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FString& FP4Label::GetName() const
|
|
|
|
|
{
|
|
|
|
|
return Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FDateTime& FP4Label::GetDate() const
|
|
|
|
|
{
|
|
|
|
|
return Date;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
FP4DataLoader::FP4DataLoader(const FOnLoadingFinished& OnLoadingFinished)
|
2014-05-21 08:45:24 -04:00
|
|
|
: OnLoadingFinished(OnLoadingFinished), bTerminate(false)
|
|
|
|
|
{
|
|
|
|
|
Thread = FRunnableThread::Create(this, TEXT("P4 Data Loading"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32 FP4DataLoader::Run()
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FP4DataCache> Data = MakeShareable(new FP4DataCache());
|
|
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
class P4Progress
|
2014-05-21 08:45:24 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2014-06-04 11:01:22 -04:00
|
|
|
P4Progress(const bool& bTerminate)
|
2014-05-21 08:45:24 -04:00
|
|
|
: bTerminate(bTerminate)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OnProgress(const FString& Input)
|
|
|
|
|
{
|
|
|
|
|
Output += Input;
|
|
|
|
|
|
|
|
|
|
return !bTerminate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString Output;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const bool &bTerminate;
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-04 11:01:22 -04:00
|
|
|
P4Progress Progress(bTerminate);
|
|
|
|
|
if (!FP4Env::RunP4Progress(FString::Printf(TEXT("labels -t -e%s/*"), *FP4Env::Get().GetBranch()),
|
|
|
|
|
FP4Env::FOnP4MadeProgress::CreateRaw(&Progress, &P4Progress::OnProgress)))
|
2014-05-21 08:45:24 -04:00
|
|
|
{
|
|
|
|
|
OnLoadingFinished.ExecuteIfBound(nullptr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Data->LoadFromLog(Progress.Output))
|
|
|
|
|
{
|
|
|
|
|
OnLoadingFinished.ExecuteIfBound(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnLoadingFinished.ExecuteIfBound(Data);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FP4DataLoader::Terminate()
|
|
|
|
|
{
|
|
|
|
|
bTerminate = true;
|
|
|
|
|
Thread->WaitForCompletion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FP4DataLoader::~FP4DataLoader()
|
|
|
|
|
{
|
|
|
|
|
Terminate();
|
|
|
|
|
}
|
2014-05-29 16:59:04 -04:00
|
|
|
|
|
|
|
|
bool FP4DataLoader::IsInProgress() const
|
|
|
|
|
{
|
|
|
|
|
return bInProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FP4DataLoader::Exit()
|
|
|
|
|
{
|
|
|
|
|
bInProgress = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FP4DataLoader::Init()
|
|
|
|
|
{
|
|
|
|
|
bInProgress = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|