Files
UnrealEngineUWP/Engine/Source/Editor/CSVtoSVG/Private/CSVtoSVGModule.cpp
Lauren Barnes 6248f8d412 Replacing legacy EditorStyle calls with AppStyle
#preflight 6272a74d2f6d177be3c6fdda
#rb Matt.Kuhlenschmidt

#ROBOMERGE-OWNER: Lauren.Barnes
#ROBOMERGE-AUTHOR: lauren.barnes
#ROBOMERGE-SOURCE: CL 20057269 via CL 20070159 via CL 20072035 via CL 20072203
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)
#ROBOMERGE-CONFLICT from-shelf

[CL 20105363 by Lauren Barnes in ue5-main branch]
2022-05-09 13:12:28 -04:00

121 lines
3.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CSVtoSVGModule.h"
#include "CSVtoSVGArguments.h"
#include "Modules/ModuleManager.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Framework/Application/SlateApplication.h"
#include "Textures/SlateIcon.h"
#include "Framework/Docking/TabManager.h"
#include "Styling/AppStyle.h"
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructure.h"
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructureModule.h"
#include "Widgets/Docking/SDockTab.h"
#include "Modules/ModuleManager.h"
#include "Widgets/Docking/SDockTab.h"
#include "SCSVtoSVG.h"
#include "ISettingsModule.h"
#include "HAL/PlatformProcess.h"
#include "Misc/Paths.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