Skip to content

Commit a9ce78e

Browse files
committed
feat: using embedded SDK (if available) in editor
1 parent c27862e commit a9ce78e

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

Source/EcsactEditor/EcsactEditor.Build.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public EcsactEditor(ReadOnlyTargetRules Target) : base(Target) {
3434
"Slate",
3535
"SlateCore",
3636
"Json",
37+
"Projects",
3738
});
3839

3940
DynamicallyLoadedModuleNames.AddRange(new string[] {});

Source/EcsactEditor/Private/EcsactEditor.cpp

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "EcsactEditor.h"
88
#include "Async/Async.h"
99
#include "Async/TaskGraphInterfaces.h"
10+
#include "Interfaces/IPluginManager.h"
1011
#include "CoreGlobals.h"
1112
#include "EcsactUnreal/Ecsact.h"
1213
#include "Editor.h"
@@ -89,26 +90,61 @@ static auto PlatformEcsactPluginExtension() -> FString {
8990
return TEXT("");
9091
}
9192

92-
static auto PluginBinariesDir() -> FString {
93-
auto& fm = FPlatformFileManager::Get().GetPlatformFile();
94-
auto plugins_dir = FPaths::ProjectPluginsDir();
95-
auto plugin_dir = plugins_dir + "/" + "Ecsact";
96-
97-
return FPaths::Combine( //
98-
FPaths::ProjectPluginsDir(),
99-
"Ecsact",
100-
"Binaries",
101-
PlatformBinariesDirname()
102-
);
103-
}
104-
10593
static auto GetDirectoryWatcher() -> IDirectoryWatcher* {
10694
auto& watcher = FModuleManager::LoadModuleChecked<FDirectoryWatcherModule>( //
10795
TEXT("DirectoryWatcher")
10896
);
10997
return watcher.Get();
11098
}
11199

100+
auto FEcsactEditorModule::GetInstalledPluginDir() -> FString {
101+
auto Plugin = IPluginManager::Get().FindPlugin(TEXT("Ecsact"));
102+
if(Plugin.IsValid()) {
103+
return Plugin->GetBaseDir();
104+
}
105+
return FString{};
106+
}
107+
108+
auto FEcsactEditorModule::GetEcsactSdkBinaryPath( //
109+
FString BinaryName
110+
) -> FString {
111+
auto plugin_install_dir = GetInstalledPluginDir();
112+
if(plugin_install_dir.IsEmpty()) {
113+
return BinaryName;
114+
}
115+
116+
auto ecsact_sdk_dir = FPaths::Combine( //
117+
plugin_install_dir,
118+
"Source",
119+
"ThirdParty",
120+
"EcsactSDK"
121+
);
122+
if(!FPaths::DirectoryExists(ecsact_sdk_dir)) {
123+
return BinaryName;
124+
}
125+
126+
#ifdef _WIN32
127+
FString exe_suffix = ".exe";
128+
#else
129+
FString exe_suffix = "";
130+
#endif
131+
132+
auto binary_path = FPaths::Combine( //
133+
ecsact_sdk_dir,
134+
"bin",
135+
BinaryName + exe_suffix
136+
);
137+
if(!FPaths::FileExists(binary_path)) {
138+
return BinaryName;
139+
}
140+
141+
return binary_path;
142+
}
143+
144+
auto FEcsactEditorModule::GetEcsactCli() -> FString {
145+
return GetEcsactSdkBinaryPath("ecsact");
146+
}
147+
112148
auto FEcsactEditorModule::SpawnEcsactCli(
113149
const TArray<FString>& Args,
114150
FOnReceiveLine OnReceiveLine,
@@ -123,7 +159,7 @@ auto FEcsactEditorModule::SpawnEcsactCli(
123159

124160
AsyncTask(
125161
ENamedThreads::AnyBackgroundThreadNormalTask,
126-
[=, OnExit = std::move(OnExit)] {
162+
[=, this, OnExit = std::move(OnExit)] {
127163
void* PipeWriteChild;
128164
void* PipeReadChild;
129165
void* PipeWriteParent;
@@ -133,7 +169,7 @@ auto FEcsactEditorModule::SpawnEcsactCli(
133169

134170
auto proc_id = uint32{};
135171
auto proc_handle = FPlatformProcess::CreateProc(
136-
TEXT("ecsact"),
172+
*GetEcsactCli(),
137173
*args_str,
138174
false,
139175
true,
@@ -263,12 +299,7 @@ auto FEcsactEditorModule::ShutdownModule() -> void {
263299
SourceDir(),
264300
SourcesWatchHandle
265301
);
266-
watcher->UnregisterDirectoryChangedCallback_Handle(
267-
PluginBinariesDir(),
268-
PluginBinariesWatchHandle
269-
);
270302
SourcesWatchHandle = {};
271-
PluginBinariesWatchHandle = {};
272303
FEditorDelegates::OnEditorInitialized.RemoveAll(this);
273304
}
274305

@@ -396,7 +427,6 @@ auto FEcsactEditorModule::OnAssetsRemoved( //
396427
}
397428

398429
auto FEcsactEditorModule::OnAssetRegistryFilesLoaded() -> void {
399-
UE_LOG(LogTemp, Log, TEXT("OnAssetRegistryFilesLoaded"));
400430
}
401431

402432
auto FEcsactEditorModule::AddMenuEntry(FMenuBuilder& MenuBuilder) -> void {

Source/EcsactEditor/Public/EcsactEditor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DECLARE_LOG_CATEGORY_EXTERN(EcsactEditor, Log, All);
1616

1717
class ECSACTEDITOR_API FEcsactEditorModule : public IModuleInterface {
1818
FDelegateHandle SourcesWatchHandle;
19-
FDelegateHandle PluginBinariesWatchHandle;
2019

2120
public:
2221
using FOnExitDelegate = TDelegate<void(int32)>;
@@ -39,8 +38,12 @@ class ECSACTEDITOR_API FEcsactEditorModule : public IModuleInterface {
3938
auto OnAssetsUpdatedOnDisk(TConstArrayView<FAssetData> Assets) -> void;
4039
auto OnAssetsRemoved(TConstArrayView<FAssetData> Assets) -> void;
4140
auto OnAssetRegistryFilesLoaded() -> void;
41+
auto GetInstalledPluginDir() -> FString;
42+
auto GetEcsactSdkBinaryPath(FString BinaryName) -> FString;
4243

4344
public:
45+
auto GetEcsactCli() -> FString;
46+
4447
auto SpawnEcsactCli( //
4548
const TArray<FString>& Args,
4649
FOnReceiveLine OnReceiveLine,

0 commit comments

Comments
 (0)