Files
UnrealEngineUWP/Engine/Source/Editor/CSVtoSVG/Private/CSVtoSVGModule.cpp
bryan sefcik b93a6cf7ed Pass 1 on editor include fixes:
Removed redundant private include paths from build.cs files.
Fixed include paths to be relative to the private or public folders.
Hid or removed includes that reached into other private module folders.
Updated PublicInclude paths when necessary.

#jira
#preflight 631e283bec5b0c765fc0ffdb

[CL 21960084 by bryan sefcik in ue5-main branch]
2022-09-11 18:33:06 -04:00

126 lines
3.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CSVtoSVGModule.h"
#include "CSVtoSVGArguments.h"
#include "Containers/UnrealString.h"
#include "Delegates/Delegate.h"
#include "Framework/Application/SlateApplication.h"
#include "Framework/Docking/TabManager.h"
#include "HAL/Platform.h"
#include "HAL/PlatformProcess.h"
#include "Internationalization/Internationalization.h"
#include "Logging/LogCategory.h"
#include "Misc/Paths.h"
#include "Modules/ModuleManager.h"
#include "SCSVtoSVG.h"
#include "Styling/AppStyle.h"
#include "Textures/SlateIcon.h"
#include "Trace/Detail/Channel.h"
#include "UObject/NameTypes.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/Docking/SDockTab.h"
#include "WorkspaceMenuStructure.h"
#include "WorkspaceMenuStructureModule.h"
#define LOCTEXT_NAMESPACE "CSVtoSVG"
IMPLEMENT_MODULE(FCSVtoSVGModule, CSVtoSVG);
DEFINE_LOG_CATEGORY(LogCSVtoSVG);
namespace FCSVtoSVG
{
static const FName CSVtoSVGApp = FName(TEXT("CSVtoSVGApp"));
}
TSharedRef<SDockTab> FCSVtoSVGModule::CreateTab(const FSpawnTabArgs& Args)
{
TSharedPtr<SDockTab> MajorTab;
SAssignNew(MajorTab, SDockTab)
.TabRole(ETabRole::MajorTab);
MajorTab->SetContent(SNew(SCSVtoSVG));
return MajorTab.ToSharedRef();
}
void FCSVtoSVGModule::StartupModule()
{
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(FCSVtoSVG::CSVtoSVGApp, FOnSpawnTab::CreateRaw(this, &FCSVtoSVGModule::CreateTab))
.SetDisplayName(NSLOCTEXT("CSVtoSVGApp", "TabTitle", "CSV to SVG"))
.SetTooltipText(NSLOCTEXT("CSVtoSVGApp", "TooltipText", "Tool for generating vector line graphs from comma-separated value files generated from CSV profiles."))
.SetGroup(WorkspaceMenu::GetMenuStructure().GetToolsCategory())
.SetIcon(FSlateIcon(FAppStyle::GetAppStyleSetName(), "ClassIcon.UserDefinedStruct"));
}
void FCSVtoSVGModule::ShutdownModule()
{
if (FSlateApplication::IsInitialized())
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(FCSVtoSVG::CSVtoSVGApp);
}
}
FFilePath GenerateSVG(const UCSVtoSVGArugments& Arguments, const TArray<FString>& StatList)
{
const FString CSVtoSVGExe = FPaths::Combine(FPaths::EngineDir(), TEXT("Binaries/DotNET/CsvTools"), TEXT("CSVToSVG.exe"));
FString CmdLine = Arguments.GetCommandLine();
if (CmdLine.IsEmpty())
{
return FFilePath();
}
// Add selected stats to the command line.
CmdLine += FString(TEXT(" -stats"));
for (const FString& Stat : StatList)
{
CmdLine += TEXT(" ") + Stat;
}
UE_LOG(LogCSVtoSVG, Display, TEXT("Generating SVG: %s %s"), *CSVtoSVGExe, *CmdLine);
// Create a read and write pipe for the child process
void* PipeRead = nullptr;
void* PipeWrite = nullptr;
if (!FPlatformProcess::CreatePipe(PipeRead, PipeWrite))
{
return FFilePath();
}
FProcHandle ProcHandle = FPlatformProcess::CreateProc(*CSVtoSVGExe, *CmdLine, true, false, false, nullptr, 0, nullptr, PipeWrite, PipeRead);
if (ProcHandle.IsValid())
{
FString CSVtoCSVOutput;
while (FPlatformProcess::IsProcRunning(ProcHandle))
{
CSVtoCSVOutput += FPlatformProcess::ReadPipe(PipeRead);
}
FPlatformProcess::WaitForProc(ProcHandle);
if (!CSVtoCSVOutput.IsEmpty())
{
UE_LOG(LogCSVtoSVG, Display, TEXT("%s"), *CSVtoCSVOutput);
}
if (!CSVtoCSVOutput.Contains(TEXT("[ERROR]")))
{
// If there was no error open the output file.
const FString OutputFileName = Arguments.GetOutputFileName();
if (!OutputFileName.IsEmpty())
{
FPlatformProcess::LaunchURL(*OutputFileName, nullptr, nullptr);
}
}
FPlatformProcess::ClosePipe(PipeRead, PipeWrite);
FPlatformProcess::CloseProc(ProcHandle);
}
return FFilePath();
}
#undef LOCTEXT_NAMESPACE