ue-mcp 1.4.13 → 1.4.14-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/bridge/bridge-timeouts.js +4 -0
- package/dist/bridge/bridge-timeouts.js.map +1 -1
- package/dist/cli/cli-commands.js +1 -0
- package/dist/cli/cli-commands.js.map +1 -1
- package/dist/cli/doctor.js +2 -1
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/init.js +1 -1
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/projects-cli.d.ts +3 -0
- package/dist/cli/projects-cli.js +72 -0
- package/dist/cli/projects-cli.js.map +1 -0
- package/dist/config/user-state.d.ts +10 -0
- package/dist/config/user-state.js +21 -0
- package/dist/config/user-state.js.map +1 -1
- package/dist/core/env.d.ts +2 -0
- package/dist/core/env.js +2 -0
- package/dist/core/env.js.map +1 -1
- package/dist/core/types.d.ts +27 -0
- package/dist/daemon/daemon.js +44 -5
- package/dist/daemon/daemon.js.map +1 -1
- package/dist/daemon/extension-api.d.ts +8 -5
- package/dist/daemon-api.d.ts +2 -1
- package/dist/daemon-api.js +1 -0
- package/dist/daemon-api.js.map +1 -1
- package/dist/dispatch/offline.js +1 -0
- package/dist/dispatch/offline.js.map +1 -1
- package/dist/editor/dialog-guard.d.ts +12 -2
- package/dist/editor/dialog-guard.js +68 -2
- package/dist/editor/dialog-guard.js.map +1 -1
- package/dist/editor/editor-control.js +1 -1
- package/dist/editor/editor-control.js.map +1 -1
- package/dist/flow/write-methods.js +1 -1
- package/dist/flow/write-methods.js.map +1 -1
- package/dist/machine/projects.d.ts +85 -0
- package/dist/machine/projects.js +286 -0
- package/dist/machine/projects.js.map +1 -0
- package/dist/pie/script-events.d.ts +4 -1
- package/dist/pie/script-events.js.map +1 -1
- package/dist/surface/context/instructions.js +20 -0
- package/dist/surface/context/instructions.js.map +1 -1
- package/dist/tool-counts.json +12 -12
- package/dist/tools/asset.js +2 -1
- package/dist/tools/asset.js.map +1 -1
- package/dist/tools/editor.js +1 -1
- package/dist/tools/editor.js.map +1 -1
- package/dist/tools/epic/effects.js +11 -0
- package/dist/tools/epic/effects.js.map +1 -1
- package/dist/tools/epic/fab.generated.d.ts +6 -0
- package/dist/tools/epic/fab.generated.js +67 -0
- package/dist/tools/epic/fab.generated.js.map +1 -0
- package/dist/tools/epic/index.d.ts +2 -0
- package/dist/tools/epic/index.js +2 -0
- package/dist/tools/epic/index.js.map +1 -1
- package/dist/tools/epic/toolset-routes.js +2 -0
- package/dist/tools/epic/toolset-routes.js.map +1 -1
- package/dist/tools/epic.js +4 -4
- package/dist/tools/epic.js.map +1 -1
- package/dist/tools/fab-epic.d.ts +23 -0
- package/dist/tools/fab-epic.js +109 -0
- package/dist/tools/fab-epic.js.map +1 -0
- package/dist/tools/fab.js +27 -18
- package/dist/tools/fab.js.map +1 -1
- package/dist/tools/level.js +9 -2
- package/dist/tools/level.js.map +1 -1
- package/dist/tools/material.js +1 -1
- package/dist/tools/material.js.map +1 -1
- package/dist/tools/pie.js +1 -1
- package/dist/tools/pie.js.map +1 -1
- package/dist/tools/specs/asset.generated.js +92 -3
- package/dist/tools/specs/asset.generated.js.map +1 -1
- package/dist/tools/specs/fab.generated.js +143 -3
- package/dist/tools/specs/fab.generated.js.map +1 -1
- package/dist/tools/specs/level.generated.js +183 -9
- package/dist/tools/specs/level.generated.js.map +1 -1
- package/dist/tools/specs/pie.generated.js +28 -8
- package/dist/tools/specs/pie.generated.js.map +1 -1
- package/dist/tools/specs/widget.generated.js +8 -1
- package/dist/tools/specs/widget.generated.js.map +1 -1
- package/dist/ue-mcp.default.yml +522 -76
- package/package.json +2 -2
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgeServer.cpp +26 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.cpp +24 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.h +7 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers_Mesh.cpp +483 -10
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Dialog/DialogHandlers.cpp +345 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers_AIAssistant.cpp +34 -6
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabDownloads.cpp +766 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabDownloads.h +26 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabHandlers.cpp +159 -55
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabHandlers.h +23 -12
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabLibrary.cpp +306 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabLibrary.h +55 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.cpp +34 -2
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.h +9 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Blockout.cpp +12 -8
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_PerfAudit.cpp +3 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Refresh.cpp +479 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_ReplaceActors.cpp +2 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_WorldPartition.cpp +824 -12
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Material/MaterialHandlers.cpp +95 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers.cpp +13 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/MCPPIETestScript.h +8 -3
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers.cpp +2 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Record.cpp +6 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Replay.cpp +1 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Script.cpp +2 -2
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputRecorder.cpp +52 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputRecorder.h +16 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputReplayer.cpp +65 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputReplayer.h +15 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEReplayInputLock.cpp +146 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEReplayInputLock.h +53 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptRunner.cpp +351 -14
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptRunner.h +55 -6
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptValidation.cpp +8 -1
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIESequenceFormat.cpp +59 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIESequenceFormat.h +15 -2
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEUIPointer.cpp +567 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEUIPointer.h +173 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/SMCPPIEStudioPanel.cpp +41 -6
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Widget/WidgetHandlers.cpp +92 -32
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabDownloadTests.cpp +140 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabEndToEndTests.cpp +365 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabLibraryTests.cpp +52 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PCGGraphAuthoringTests.cpp +5 -2
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEReplayInputLockTests.cpp +77 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEScriptTests.cpp +256 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEScriptValidationTests.cpp +18 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEUIPointerTests.cpp +246 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/UE_MCP_Bridge.cpp +4 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/UE_MCP_Bridge.Build.cs +85 -13
- package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Private/MCPPIEActionTrigger.cpp +48 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Private/MCPPIERemoteControl.cpp +93 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Public/MCPPIEActionTrigger.h +52 -0
- package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Public/MCPPIERemoteControl.h +54 -0
- package/plugin/ue_mcp_bridge/UE_MCP_Bridge.uplugin +2 -2
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
#include "FabDownloads.h"
|
|
2
|
+
#include "FabHandlers.h"
|
|
3
|
+
#include "FabLibrary.h"
|
|
4
|
+
#include "HandlerUtils.h"
|
|
5
|
+
|
|
6
|
+
#include "AssetRegistry/AssetRegistryModule.h"
|
|
7
|
+
#include "Async/Async.h"
|
|
8
|
+
#include "BuildPatchSettings.h"
|
|
9
|
+
#include "BuildPatchMessage.h"
|
|
10
|
+
#include "HAL/FileManager.h"
|
|
11
|
+
#include "HAL/CriticalSection.h"
|
|
12
|
+
#include "HAL/PlatformProcess.h"
|
|
13
|
+
#include "HAL/PlatformTime.h"
|
|
14
|
+
#include "HAL/PlatformFileManager.h"
|
|
15
|
+
#include "HttpModule.h"
|
|
16
|
+
#include "Interfaces/IHttpRequest.h"
|
|
17
|
+
#include "Interfaces/IHttpResponse.h"
|
|
18
|
+
#include "Interfaces/IBuildInstaller.h"
|
|
19
|
+
#include "Interfaces/IBuildPatchServicesModule.h"
|
|
20
|
+
#include "Misc/FileHelper.h"
|
|
21
|
+
#include "Misc/Paths.h"
|
|
22
|
+
#include "Misc/PackageName.h"
|
|
23
|
+
#include "Misc/SecureHash.h"
|
|
24
|
+
#include "Modules/ModuleManager.h"
|
|
25
|
+
#include "Serialization/JsonReader.h"
|
|
26
|
+
#include "Serialization/JsonSerializer.h"
|
|
27
|
+
#include "Runtime/Launch/Resources/Version.h"
|
|
28
|
+
|
|
29
|
+
#if WITH_FAB_PLUGIN
|
|
30
|
+
#include "Utilities/FabAssetsCache.h"
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
namespace MCPFab
|
|
34
|
+
{
|
|
35
|
+
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 8
|
|
36
|
+
namespace DownloadPrivate
|
|
37
|
+
{
|
|
38
|
+
bool FileHash(const FString& Path, FSHAHash& Hash)
|
|
39
|
+
{
|
|
40
|
+
TUniquePtr<FArchive> File(IFileManager::Get().CreateFileReader(*Path));
|
|
41
|
+
if (!File) return false;
|
|
42
|
+
FSHA1 Hasher; TArray<uint8> Buffer; Buffer.SetNumUninitialized(1024 * 1024);
|
|
43
|
+
while (!File->AtEnd())
|
|
44
|
+
{
|
|
45
|
+
const int64 Size = FMath::Min<int64>(Buffer.Num(), File->TotalSize() - File->Tell());
|
|
46
|
+
File->Serialize(Buffer.GetData(), Size); if (File->IsError()) return false;
|
|
47
|
+
Hasher.Update(Buffer.GetData(), Size);
|
|
48
|
+
}
|
|
49
|
+
Hash = Hasher.Finalize(); return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool ContainsString(const TSharedPtr<FJsonObject>& Object, const TCHAR* Field, const FString& Value)
|
|
53
|
+
{
|
|
54
|
+
const TArray<TSharedPtr<FJsonValue>>* Array = nullptr;
|
|
55
|
+
if (!Object->TryGetArrayField(Field, Array)) return false;
|
|
56
|
+
for (const auto& Entry : *Array) { FString Text; if (Entry && Entry->TryGetString(Text) && Text == Value) return true; }
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bool IsListing(const TSharedPtr<FJsonObject>& Item, const FString& Id)
|
|
61
|
+
{
|
|
62
|
+
FString Url;
|
|
63
|
+
if (Item->TryGetStringField(TEXT("url"), Url))
|
|
64
|
+
{
|
|
65
|
+
Url.RemoveFromEnd(TEXT("/"));
|
|
66
|
+
if (Url.EndsWith(TEXT("/") + Id, ESearchCase::CaseSensitive)) return true;
|
|
67
|
+
}
|
|
68
|
+
const TArray<TSharedPtr<FJsonValue>>* Attributes = nullptr;
|
|
69
|
+
if (Item->TryGetArrayField(TEXT("customAttributes"), Attributes)) for (const auto& Attribute : *Attributes)
|
|
70
|
+
{
|
|
71
|
+
FString Value;
|
|
72
|
+
if (Attribute && Attribute->Type == EJson::Object && Attribute->AsObject()->TryGetStringField(TEXT("ListingIdentifier"), Value) && Value == Id) return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The listing UUID download takes, read the same two ways IsListing matches
|
|
78
|
+
// it: the listing URL's last segment, or the ListingIdentifier attribute.
|
|
79
|
+
FString ListingIdOf(const TSharedPtr<FJsonObject>& Item)
|
|
80
|
+
{
|
|
81
|
+
FGuid Guid;
|
|
82
|
+
const TArray<TSharedPtr<FJsonValue>>* Attributes = nullptr;
|
|
83
|
+
if (Item->TryGetArrayField(TEXT("customAttributes"), Attributes)) for (const auto& Attribute : *Attributes)
|
|
84
|
+
{
|
|
85
|
+
FString Value;
|
|
86
|
+
if (Attribute && Attribute->Type == EJson::Object && Attribute->AsObject()->TryGetStringField(TEXT("ListingIdentifier"), Value)
|
|
87
|
+
&& FGuid::ParseExact(Value, EGuidFormats::DigitsWithHyphens, Guid)) return Value;
|
|
88
|
+
}
|
|
89
|
+
FString Url;
|
|
90
|
+
if (Item->TryGetStringField(TEXT("url"), Url))
|
|
91
|
+
{
|
|
92
|
+
Url.RemoveFromEnd(TEXT("/"));
|
|
93
|
+
const FString Last = FPaths::GetCleanFilename(Url);
|
|
94
|
+
if (FGuid::ParseExact(Last, EGuidFormats::DigitsWithHyphens, Guid)) return Last;
|
|
95
|
+
}
|
|
96
|
+
return FString();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// This editor's engine as Fab names it in projectVersions, e.g. UE_5.8.
|
|
100
|
+
FString RunningEngine() { return FString::Printf(TEXT("UE_%d.%d"), ENGINE_MAJOR_VERSION, ENGINE_MINOR_VERSION); }
|
|
101
|
+
|
|
102
|
+
// This editor's platform as Fab names it in projectVersions.targetPlatforms.
|
|
103
|
+
FString RunningPlatform()
|
|
104
|
+
{
|
|
105
|
+
#if PLATFORM_WINDOWS
|
|
106
|
+
return TEXT("Windows");
|
|
107
|
+
#elif PLATFORM_MAC
|
|
108
|
+
return TEXT("Mac");
|
|
109
|
+
#else
|
|
110
|
+
return TEXT("Linux");
|
|
111
|
+
#endif
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Every engine/platform pair a listing offers, for an error that names the choices.
|
|
115
|
+
FString DescribeVersions(const TSharedPtr<FJsonObject>& Item)
|
|
116
|
+
{
|
|
117
|
+
TArray<FString> Pairs;
|
|
118
|
+
const TArray<TSharedPtr<FJsonValue>>* Versions = nullptr;
|
|
119
|
+
if (Item->TryGetArrayField(TEXT("projectVersions"), Versions)) for (const auto& Version : *Versions)
|
|
120
|
+
{
|
|
121
|
+
if (!Version || Version->Type != EJson::Object) continue;
|
|
122
|
+
const TArray<TSharedPtr<FJsonValue>>* Engines = nullptr;
|
|
123
|
+
const TArray<TSharedPtr<FJsonValue>>* Platforms = nullptr;
|
|
124
|
+
if (!Version->AsObject()->TryGetArrayField(TEXT("engineVersions"), Engines) || !Version->AsObject()->TryGetArrayField(TEXT("targetPlatforms"), Platforms)) continue;
|
|
125
|
+
for (const auto& E : *Engines) for (const auto& P : *Platforms)
|
|
126
|
+
{
|
|
127
|
+
FString EngineText, PlatformText;
|
|
128
|
+
if (E && P && E->TryGetString(EngineText) && P->TryGetString(PlatformText)) Pairs.AddUnique(EngineText + TEXT("/") + PlatformText);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return Pairs.IsEmpty() ? FString(TEXT("none")) : FString::Join(Pairs, TEXT(", "));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// A signed-in session whose owned library this editor has synced, or the
|
|
135
|
+
// refusal that says which of the two steps is missing.
|
|
136
|
+
bool RequireSyncedSession(FSession& Out, TSharedPtr<FJsonValue>& OutError)
|
|
137
|
+
{
|
|
138
|
+
FString Reason;
|
|
139
|
+
if (!ReadSession(Out, Reason))
|
|
140
|
+
{
|
|
141
|
+
OutError = MCPErrorWithCode(TEXT("FAB_NOT_SIGNED_IN"), FString::Printf(
|
|
142
|
+
TEXT("%s Sign in to the account that owns the content, then call fab(sync_library)."), *Reason));
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
// A failed or running resync keeps the previous snapshot, which still answers.
|
|
146
|
+
if (Out.AccountId != Library().AccountId || (Library().State != TEXT("complete") && Library().Items.IsEmpty()))
|
|
147
|
+
{
|
|
148
|
+
OutError = MCPErrorWithCode(TEXT("FAB_LIBRARY_NOT_SYNCED"), FString::Printf(
|
|
149
|
+
TEXT("The owned library of the signed-in account is not synced in this editor (librarySync.state %s). Call fab(sync_library) and poll fab(status) until librarySync.state is complete."),
|
|
150
|
+
*Library().State));
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
bool NoSymlinkParents(const FString& Path)
|
|
157
|
+
{
|
|
158
|
+
auto& Files = FPlatformFileManager::Get().GetPlatformFile();
|
|
159
|
+
FString Current = Path;
|
|
160
|
+
while (!Current.IsEmpty())
|
|
161
|
+
{
|
|
162
|
+
if (Files.IsSymlink(*Current) == ESymlinkResult::Symlink) return false;
|
|
163
|
+
const FString Parent = FPaths::GetPath(Current);
|
|
164
|
+
if (Parent == Current) break;
|
|
165
|
+
Current = Parent;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
FString EncodeJson(const TSharedPtr<FJsonObject>& Object)
|
|
171
|
+
{
|
|
172
|
+
FString Text; FJsonSerializer::Serialize(Object.ToSharedRef(), TJsonWriterFactory<>::Create(&Text)); return Text;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// BPS asks for chunk paths after the manifest URL has been resolved. Keep
|
|
176
|
+
// its signature on each path, not in the middle of a concatenated URL.
|
|
177
|
+
class FCdnHandler final : public BuildPatchServices::FMessageHandler
|
|
178
|
+
{
|
|
179
|
+
public:
|
|
180
|
+
explicit FCdnHandler(FString InUrl) : FMessageHandler(BuildPatchServices::EMessageRequests::ChunkUriRequest), Url(MoveTemp(InUrl)) {}
|
|
181
|
+
bool HandleRequest(const BuildPatchServices::FChunkUriRequest& Request, TFunction<void(BuildPatchServices::FChunkUriResponse)> Respond) override
|
|
182
|
+
{
|
|
183
|
+
BuildPatchServices::FChunkUriResponse Response;
|
|
184
|
+
Response.Uri = ChunkUrl(Url, Request.ChunkCloudSubdirectory, Request.ChunkPath);
|
|
185
|
+
Response.bFailed = Response.Uri.IsEmpty(); Respond(MoveTemp(Response)); return true;
|
|
186
|
+
}
|
|
187
|
+
private:
|
|
188
|
+
FString Url;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
struct FReadOnlyVerification
|
|
192
|
+
{
|
|
193
|
+
TAtomic<bool> Cancel{false}, Done{false};
|
|
194
|
+
TAtomic<int32> CheckedFiles{0};
|
|
195
|
+
FString Error;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
struct FJob : TSharedFromThis<FJob>
|
|
199
|
+
{
|
|
200
|
+
FString Id = FGuid::NewGuid().ToString(EGuidFormats::Digits);
|
|
201
|
+
FString State = TEXT("resolving"), Error, Output, Owner;
|
|
202
|
+
FAssetVersion Asset;
|
|
203
|
+
#if WITH_DEV_AUTOMATION_TESTS
|
|
204
|
+
FString FixtureCloud;
|
|
205
|
+
#endif
|
|
206
|
+
TMap<FString, FSHAHash> CreatedFiles;
|
|
207
|
+
bool bVerifyOnly = false;
|
|
208
|
+
bool bPauseRequested = false;
|
|
209
|
+
FHttpRequestPtr Request;
|
|
210
|
+
IBuildManifestPtr Manifest;
|
|
211
|
+
IBuildInstallerPtr Installer;
|
|
212
|
+
TUniquePtr<FCdnHandler> Cdn;
|
|
213
|
+
TUniquePtr<FSystemWideCriticalSection> OutputLock;
|
|
214
|
+
TSharedPtr<FReadOnlyVerification, ESPMode::ThreadSafe> Verify;
|
|
215
|
+
TFuture<void> Verification;
|
|
216
|
+
|
|
217
|
+
void Refresh()
|
|
218
|
+
{
|
|
219
|
+
if (Verify && Verify->Done.Load() && (State == TEXT("downloading") || State == TEXT("pausing") || State == TEXT("cancelling")))
|
|
220
|
+
{
|
|
221
|
+
OutputLock.Reset();
|
|
222
|
+
if (Verify->Cancel.Load()) State = bPauseRequested ? TEXT("paused") : TEXT("cancelled");
|
|
223
|
+
else if (!Verify->Error.IsEmpty()) Fail(Verify->Error);
|
|
224
|
+
else State = TEXT("complete");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (!Installer || !Installer->IsComplete() || (State != TEXT("downloading") && State != TEXT("pausing") && State != TEXT("cancelling"))) return;
|
|
228
|
+
Installer->UnregisterMessageHandler(Cdn.Get()); OutputLock.Reset();
|
|
229
|
+
if (Installer->CompletedSuccessfully()) State = TEXT("complete");
|
|
230
|
+
else if (bPauseRequested && Installer->IsCanceled()) State = TEXT("paused");
|
|
231
|
+
else if (Installer->IsCanceled()) State = TEXT("cancelled");
|
|
232
|
+
else Fail(TEXT("Native BuildPatch verification or download failed. See errorCode; resume_download retries with a fresh signed URL."));
|
|
233
|
+
}
|
|
234
|
+
bool Active() { Refresh(); return State == TEXT("resolving") || State == TEXT("downloading") || State == TEXT("pausing") || State == TEXT("cancelling"); }
|
|
235
|
+
void Fail(const FString& Message) { State = TEXT("failed"); Error = Message; Request.Reset(); OutputLock.Reset(); }
|
|
236
|
+
TSharedPtr<FJsonObject> Describe() const
|
|
237
|
+
{
|
|
238
|
+
auto Result = MakeShared<FJsonObject>();
|
|
239
|
+
Result->SetStringField(TEXT("jobId"), Id); Result->SetStringField(TEXT("state"), State);
|
|
240
|
+
Result->SetStringField(TEXT("listingId"), Asset.ListingId); Result->SetStringField(TEXT("artifactId"), Asset.ArtifactId);
|
|
241
|
+
Result->SetStringField(TEXT("engineVersion"), Asset.EngineVersion); Result->SetStringField(TEXT("platform"), Asset.Platform);
|
|
242
|
+
Result->SetStringField(TEXT("outputDirectory"), Output); Result->SetBoolField(TEXT("verifyOnly"), bVerifyOnly);
|
|
243
|
+
if (!Error.IsEmpty()) Result->SetStringField(TEXT("error"), Error);
|
|
244
|
+
if (Manifest) { Result->SetNumberField(TEXT("files"), Manifest->GetBuildFileList().Num()); Result->SetNumberField(TEXT("installedBytes"), double(Manifest->GetBuildSize())); }
|
|
245
|
+
if (Verify)
|
|
246
|
+
{
|
|
247
|
+
const int32 Total = Manifest->GetBuildFileList().Num();
|
|
248
|
+
Result->SetNumberField(TEXT("progress"), Total ? double(Verify->CheckedFiles.Load()) / Total : 0.0);
|
|
249
|
+
Result->SetStringField(TEXT("phase"), State == TEXT("complete") ? TEXT("Completed") : TEXT("CheckingFiles"));
|
|
250
|
+
Result->SetNumberField(TEXT("downloadedBytes"), 0); Result->SetNumberField(TEXT("downloadRequiredBytes"), 0); Result->SetNumberField(TEXT("bytesPerSecond"), 0);
|
|
251
|
+
if (State == TEXT("failed")) Result->SetStringField(TEXT("errorCode"), TEXT("FILE_VERIFICATION_FAILED"));
|
|
252
|
+
}
|
|
253
|
+
if (Installer)
|
|
254
|
+
{
|
|
255
|
+
Result->SetNumberField(TEXT("progress"), Installer->GetUpdateProgress());
|
|
256
|
+
Result->SetStringField(TEXT("phase"), LexToString(Installer->GetState()));
|
|
257
|
+
Result->SetNumberField(TEXT("downloadedBytes"), double(Installer->GetTotalDownloaded()));
|
|
258
|
+
Result->SetNumberField(TEXT("downloadRequiredBytes"), double(Installer->GetTotalDownloadRequired()));
|
|
259
|
+
Result->SetNumberField(TEXT("bytesPerSecond"), Installer->GetDownloadSpeed());
|
|
260
|
+
if (Installer->IsComplete() && Installer->HasError()) Result->SetStringField(TEXT("errorCode"), Installer->GetErrorCode());
|
|
261
|
+
}
|
|
262
|
+
return Result;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
void StopRequest()
|
|
266
|
+
{
|
|
267
|
+
if (Request) { Request->OnProcessRequestComplete().Unbind(); Request->CancelRequest(); Request.Reset(); }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
bool PrepareOutput(FString& OutError)
|
|
271
|
+
{
|
|
272
|
+
if (!NoSymlinkParents(Output) || !NoSymlinkParents(Output / TEXT(".ue-mcp-fab/staging"))) { OutError = TEXT("Output path contains a symlink."); return false; }
|
|
273
|
+
const FString Marker = Output / TEXT(".ue-mcp-fab/asset.json");
|
|
274
|
+
TArray<FString> Existing;
|
|
275
|
+
IFileManager::Get().FindFiles(Existing, *(Output / TEXT("*")), true, true);
|
|
276
|
+
if (!Existing.IsEmpty() && !bVerifyOnly)
|
|
277
|
+
{
|
|
278
|
+
FString Text; TSharedPtr<FJsonObject> Previous;
|
|
279
|
+
if (!FFileHelper::LoadFileToString(Text, *Marker) || !FJsonSerializer::Deserialize(TJsonReaderFactory<>::Create(Text), Previous) || !Previous
|
|
280
|
+
|| Previous->GetStringField(TEXT("artifactId")) != Asset.ArtifactId)
|
|
281
|
+
{ OutError = TEXT("Output is not an empty directory or this artifact's resumable download. Choose a separate directory; verifyOnly can inspect an existing pack."); return false; }
|
|
282
|
+
}
|
|
283
|
+
for (const FString& File : Manifest->GetBuildFileList()) if (!NoSymlinkParents(Output / File)) { OutError = TEXT("Output contains a symlink at a manifest path."); return false; }
|
|
284
|
+
if (bVerifyOnly) return true;
|
|
285
|
+
bool bSafeStaging = true;
|
|
286
|
+
FPlatformFileManager::Get().GetPlatformFile().IterateDirectoryRecursively(*(Output / TEXT(".ue-mcp-fab")), [&bSafeStaging](const TCHAR* Path, bool)
|
|
287
|
+
{
|
|
288
|
+
if (!NoSymlinkParents(Path)) { bSafeStaging = false; return false; } return true;
|
|
289
|
+
});
|
|
290
|
+
if (!bSafeStaging) { OutError = TEXT("Staging contains a symlink."); return false; }
|
|
291
|
+
if (!IFileManager::Get().MakeDirectory(*(Output / TEXT(".ue-mcp-fab")), true)) { OutError = TEXT("Cannot create download staging directory."); return false; }
|
|
292
|
+
auto Metadata = MakeShared<FJsonObject>();
|
|
293
|
+
Metadata->SetStringField(TEXT("artifactId"), Asset.ArtifactId); Metadata->SetStringField(TEXT("listingId"), Asset.ListingId);
|
|
294
|
+
Metadata->SetStringField(TEXT("engineVersion"), Asset.EngineVersion); Metadata->SetStringField(TEXT("platform"), Asset.Platform);
|
|
295
|
+
// Never persist tokens, distribution responses or signed URLs.
|
|
296
|
+
if (!FFileHelper::SaveStringToFile(EncodeJson(Metadata), *Marker)) { OutError = TEXT("Cannot persist download identity."); return false; }
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
void StartReadOnlyVerification()
|
|
301
|
+
{
|
|
302
|
+
if (Verification.IsValid()) Verification.Wait();
|
|
303
|
+
Verify = MakeShared<FReadOnlyVerification, ESPMode::ThreadSafe>();
|
|
304
|
+
State = TEXT("downloading");
|
|
305
|
+
// BPS may delete failed files even for MakeVerifyOnly. Read the native
|
|
306
|
+
// manifest with Core's streaming SHA here, without any install operation.
|
|
307
|
+
Verification = Async(EAsyncExecution::ThreadPool, [Task = Verify.ToSharedRef(), Snapshot = Manifest.ToSharedRef(), Directory = Output]()
|
|
308
|
+
{
|
|
309
|
+
for (const FString& File : Snapshot->GetBuildFileList())
|
|
310
|
+
{
|
|
311
|
+
if (Task->Cancel.Load()) break;
|
|
312
|
+
FSHAHash Hash; const FSHAHash* Expected = Snapshot->GetFileSHA1Hash(File);
|
|
313
|
+
if (!Expected || !FileHash(Directory / File, Hash) || Hash != *Expected)
|
|
314
|
+
{ Task->Error = TEXT("Read-only SHA verification failed for ") + File + TEXT(". Original file retained."); break; }
|
|
315
|
+
Task->CheckedFiles.Store(Task->CheckedFiles.Load() + 1);
|
|
316
|
+
}
|
|
317
|
+
Task->Done.Store(true);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
void StartInstaller(const FString& ManifestUrl)
|
|
322
|
+
{
|
|
323
|
+
FString Reason;
|
|
324
|
+
OutputLock = MakeUnique<FSystemWideCriticalSection>(TEXT("UE_MCP_Fab_") + FMD5::HashAnsiString(*Output.ToLower()));
|
|
325
|
+
if (!OutputLock->IsValid()) { Fail(TEXT("Another process owns this output directory.")); return; }
|
|
326
|
+
if (!Manifest || !ValidatePackManifest(Manifest.ToSharedRef(), Reason) || !PrepareOutput(Reason)) { Fail(Reason); return; }
|
|
327
|
+
if (bVerifyOnly) { StartReadOnlyVerification(); return; }
|
|
328
|
+
auto& Bps = FModuleManager::LoadModuleChecked<IBuildPatchServicesModule>(TEXT("BuildPatchServices"));
|
|
329
|
+
using namespace BuildPatchServices;
|
|
330
|
+
FBuildInstallerConfiguration Config({FInstallerAction::MakeRepair(Manifest.ToSharedRef())});
|
|
331
|
+
Config.InstallDirectory = Output;
|
|
332
|
+
Config.StagingDirectory = Output / TEXT(".ue-mcp-fab/staging");
|
|
333
|
+
Config.CloudDirectories = {FPaths::GetPath(ManifestUrl.Left(ManifestUrl.Find(TEXT("?")) == INDEX_NONE ? ManifestUrl.Len() : ManifestUrl.Find(TEXT("?"))))};
|
|
334
|
+
Config.bRunRequiredPrereqs = false; Config.bSkipCustomUninstallAction = true; Config.bRejectSymlinks = true;
|
|
335
|
+
Config.bAllowConcurrentExecution = true; Config.VerifyMode = EVerifyMode::ShaVerifyAllFiles;
|
|
336
|
+
Config.ConstructorDisableResumeBelowMB = 0;
|
|
337
|
+
Cdn = MakeUnique<FCdnHandler>(ManifestUrl);
|
|
338
|
+
// BPS requires a bound completion delegate. Job state is observed by
|
|
339
|
+
// Refresh so callers and worker completion cannot race its lifetime.
|
|
340
|
+
Installer = Bps.CreateBuildInstaller(MoveTemp(Config), FBuildPatchInstallerDelegate::CreateLambda([](const IBuildInstallerRef&) {}));
|
|
341
|
+
// Only a signed CDN needs the handler. BPS answers its chunk-URI
|
|
342
|
+
// requests from its own ticker, so a loopback test server, which a
|
|
343
|
+
// test pumps without engine frames, takes the plain cloud path.
|
|
344
|
+
if (ManifestUrl.StartsWith(TEXT("https://"))) Installer->RegisterMessageHandler(Cdn.Get());
|
|
345
|
+
State = TEXT("downloading");
|
|
346
|
+
if (!Installer->StartInstallation()) Fail(TEXT("Native BuildPatch installer could not start."));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
void FetchManifest(const FString& Url)
|
|
350
|
+
{
|
|
351
|
+
if (!IsFetchableUrl(Url)) { Fail(TEXT("Fab returned a non-HTTPS manifest URL.")); return; }
|
|
352
|
+
Request = FHttpModule::Get().CreateRequest(); Request->SetVerb(TEXT("GET")); Request->SetURL(Url); Request->SetTimeout(60.0f);
|
|
353
|
+
Request->SetDelegateThreadPolicy(EHttpRequestDelegateThreadPolicy::CompleteOnGameThread);
|
|
354
|
+
const TWeakPtr<FJob> Weak = AsShared();
|
|
355
|
+
Request->OnProcessRequestComplete().BindLambda([Weak, Url](FHttpRequestPtr, FHttpResponsePtr Response, bool bOk)
|
|
356
|
+
{
|
|
357
|
+
auto Job = Weak.Pin(); if (!Job || Job->State != TEXT("resolving")) return; Job->Request.Reset();
|
|
358
|
+
if (!bOk || !Response || Response->GetResponseCode() != 200) { Job->Fail(TEXT("Fab manifest download failed. Retry download or resume_download.")); return; }
|
|
359
|
+
auto& Bps = FModuleManager::LoadModuleChecked<IBuildPatchServicesModule>(TEXT("BuildPatchServices"));
|
|
360
|
+
Job->Manifest = Bps.MakeManifestFromData(Response->GetContent());
|
|
361
|
+
if (!Job->Manifest) { Job->Fail(TEXT("Native BuildPatch could not parse the manifest.")); return; }
|
|
362
|
+
Job->StartInstaller(Url);
|
|
363
|
+
});
|
|
364
|
+
if (!Request->ProcessRequest()) Fail(TEXT("Manifest request could not start."));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
void Resolve()
|
|
368
|
+
{
|
|
369
|
+
#if WITH_DEV_AUTOMATION_TESTS
|
|
370
|
+
if (!FixtureCloud.IsEmpty()) { bPauseRequested = false; Error.Reset(); StartInstaller(FixtureCloud / TEXT("fixture.manifest")); return; }
|
|
371
|
+
#endif
|
|
372
|
+
FSession Session; FString Reason;
|
|
373
|
+
if (!ReadSession(Session, Reason) || Session.AccountId != Owner) { Fail(TEXT("Sign back into the account that owns this download, then retry.")); return; }
|
|
374
|
+
State = TEXT("resolving"); Error.Reset(); bPauseRequested = false;
|
|
375
|
+
Request = FHttpModule::Get().CreateRequest();
|
|
376
|
+
Request->SetURL(Session.BaseUrl / TEXT("e/artifacts") / Asset.ArtifactId / TEXT("manifest")); Request->SetVerb(TEXT("POST"));
|
|
377
|
+
Request->SetHeader(TEXT("Authorization"), TEXT("Bearer ") + Session.Token); Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
|
|
378
|
+
Request->SetHeader(TEXT("Accept"), TEXT("application/json")); Request->SetTimeout(30.0f);
|
|
379
|
+
auto Body = MakeShared<FJsonObject>(); Body->SetStringField(TEXT("item_id"), Asset.AssetId); Body->SetStringField(TEXT("namespace"), Asset.Namespace); Body->SetStringField(TEXT("platform"), Asset.Platform);
|
|
380
|
+
Request->SetContentAsString(EncodeJson(Body)); Request->SetDelegateThreadPolicy(EHttpRequestDelegateThreadPolicy::CompleteOnGameThread);
|
|
381
|
+
const TWeakPtr<FJob> Weak = AsShared();
|
|
382
|
+
Request->OnProcessRequestComplete().BindLambda([Weak](FHttpRequestPtr, FHttpResponsePtr Response, bool bOk)
|
|
383
|
+
{
|
|
384
|
+
auto Job = Weak.Pin(); if (!Job || Job->State != TEXT("resolving")) return; Job->Request.Reset();
|
|
385
|
+
const int32 Code = Response ? Response->GetResponseCode() : 0;
|
|
386
|
+
TSharedPtr<FJsonObject> Json; const TArray<TSharedPtr<FJsonValue>>* Infos = nullptr;
|
|
387
|
+
if (!bOk || !Response || Code < 200 || Code >= 300 || !Response->GetContentType().StartsWith(TEXT("application/json"))
|
|
388
|
+
|| !FJsonSerializer::Deserialize(TJsonReaderFactory<>::Create(Response->GetContentAsString()), Json) || !Json || !Json->TryGetArrayField(TEXT("downloadInfo"), Infos))
|
|
389
|
+
{ Job->Fail(FString::Printf(TEXT("Fab distribution resolution failed (HTTP %d). No response body or credentials are exposed."), Code)); return; }
|
|
390
|
+
for (const auto& Info : *Infos)
|
|
391
|
+
{
|
|
392
|
+
if (!Info || Info->Type != EJson::Object) continue; auto Object = Info->AsObject(); FString Artifact;
|
|
393
|
+
const TArray<TSharedPtr<FJsonValue>>* Points = nullptr;
|
|
394
|
+
if (!Object->TryGetStringField(TEXT("artifactId"), Artifact) || Artifact != Job->Asset.ArtifactId || !Object->TryGetArrayField(TEXT("distributionPoints"), Points)) continue;
|
|
395
|
+
for (const auto& Point : *Points)
|
|
396
|
+
{
|
|
397
|
+
if (!Point || Point->Type != EJson::Object) continue; FString Url, Expiry;
|
|
398
|
+
if (!Point->AsObject()->TryGetStringField(TEXT("manifestUrl"), Url)) continue;
|
|
399
|
+
FDateTime Expiration;
|
|
400
|
+
if (Point->AsObject()->TryGetStringField(TEXT("signatureExpiration"), Expiry) && FDateTime::ParseIso8601(*Expiry, Expiration) && Expiration <= FDateTime::UtcNow()) continue;
|
|
401
|
+
Job->FetchManifest(Url); return;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
Job->Fail(TEXT("Fab returned no current distribution for the selected artifact."));
|
|
405
|
+
});
|
|
406
|
+
if (!Request->ProcessRequest()) Fail(TEXT("Distribution request could not start."));
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
TMap<FString, TSharedPtr<FJob>> Jobs;
|
|
411
|
+
|
|
412
|
+
TSharedPtr<FJob> FindJob(const TSharedPtr<FJsonObject>& Params, FString& Error)
|
|
413
|
+
{
|
|
414
|
+
const FString Id = OptionalString(Params, TEXT("jobId"));
|
|
415
|
+
if (const auto* Found = Jobs.Find(Id)) { (*Found)->Refresh(); return *Found; }
|
|
416
|
+
Error = TEXT("Unknown jobId. After restarting the editor, repeat download with the same listing/version/outputDirectory to reuse its verified files and staging data."); return nullptr;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
TSharedPtr<FJsonValue> MCPFabJobResult(const TSharedPtr<FJob>& Job, bool bUnchanged = true, const FString& Inverse = FString())
|
|
420
|
+
{
|
|
421
|
+
Job->Refresh();
|
|
422
|
+
auto Result = MCPSuccess(); Result->SetObjectField(TEXT("job"), Job->Describe());
|
|
423
|
+
Result->SetBoolField(TEXT("unchanged"), bUnchanged);
|
|
424
|
+
if (!bUnchanged && !Inverse.IsEmpty())
|
|
425
|
+
{
|
|
426
|
+
auto Payload = MakeShared<FJsonObject>(); Payload->SetStringField(TEXT("jobId"), Job->Id);
|
|
427
|
+
MCPSetRollback(Result, Inverse, Payload);
|
|
428
|
+
Result->SetBoolField(TEXT("rollbackLossy"), true);
|
|
429
|
+
Result->SetStringField(TEXT("rollbackNote"), TEXT("Controls the job; transferred bytes and verified staging files remain cached. Wait for terminal or paused state before invoking the inverse."));
|
|
430
|
+
}
|
|
431
|
+
else MCPSetNoRollback(Result, TEXT("This call did not change the job."));
|
|
432
|
+
return MCPResult(Result);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
bool ResolveVersion(const TArray<TSharedPtr<FJsonValue>>& Items, const FString& ListingId, const FString& EngineVersion, const FString& Platform, FAssetVersion& Out, FString& Error)
|
|
437
|
+
{
|
|
438
|
+
FGuid Guid;
|
|
439
|
+
if (!FGuid::ParseExact(ListingId, EGuidFormats::DigitsWithHyphens, Guid)) { Error = TEXT("listingId must be a Fab listing UUID."); return false; }
|
|
440
|
+
const FString Engine = EngineVersion.StartsWith(TEXT("UE_")) ? EngineVersion : TEXT("UE_") + EngineVersion;
|
|
441
|
+
for (const auto& Value : Items)
|
|
442
|
+
{
|
|
443
|
+
if (!Value || Value->Type != EJson::Object || !DownloadPrivate::IsListing(Value->AsObject(), ListingId)) continue;
|
|
444
|
+
const auto Item = Value->AsObject(); const TArray<TSharedPtr<FJsonValue>>* Versions = nullptr;
|
|
445
|
+
if (!Item->TryGetArrayField(TEXT("projectVersions"), Versions)) break;
|
|
446
|
+
TArray<TSharedPtr<FJsonObject>> Matches;
|
|
447
|
+
for (const auto& Version : *Versions) if (Version && Version->Type == EJson::Object
|
|
448
|
+
&& DownloadPrivate::ContainsString(Version->AsObject(), TEXT("engineVersions"), Engine)
|
|
449
|
+
&& DownloadPrivate::ContainsString(Version->AsObject(), TEXT("targetPlatforms"), Platform)) Matches.Add(Version->AsObject());
|
|
450
|
+
if (Matches.Num() != 1)
|
|
451
|
+
{
|
|
452
|
+
Error = FString::Printf(TEXT("%s owned artifact matches %s/%s. This listing offers: %s. Pass engineVersion and platform from that list."),
|
|
453
|
+
Matches.IsEmpty() ? TEXT("No") : TEXT("More than one"), *Engine, *Platform, *DownloadPrivate::DescribeVersions(Item));
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
Out.ListingId = ListingId; Out.EngineVersion = Engine; Out.Platform = Platform;
|
|
457
|
+
if (!Item->TryGetStringField(TEXT("title"), Out.Title) || !Item->TryGetStringField(TEXT("assetId"), Out.AssetId)
|
|
458
|
+
|| !Item->TryGetStringField(TEXT("assetNamespace"), Out.Namespace) || !Matches[0]->TryGetStringField(TEXT("artifactId"), Out.ArtifactId) || Out.ArtifactId.IsEmpty())
|
|
459
|
+
{ Error = TEXT("Owned artifact metadata is incomplete."); return false; }
|
|
460
|
+
for (TCHAR C : Out.ArtifactId) if (!(FChar::IsAlnum(C) || C == '_' || C == '-')) { Error = TEXT("Invalid artifact identifier."); return false; }
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
Error = TEXT("Listing not present in the owned library. Complete sync_library first."); return false;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
bool SafePackPath(const FString& Relative)
|
|
467
|
+
{
|
|
468
|
+
if (Relative.IsEmpty() || Relative.Contains(TEXT("\\")) || Relative.Contains(TEXT(":")) || !FPaths::IsRelative(Relative)) return false;
|
|
469
|
+
TArray<FString> Parts; Relative.ParseIntoArray(Parts, TEXT("/"), false);
|
|
470
|
+
for (const auto& Part : Parts) if (Part.IsEmpty() || Part == TEXT(".") || Part == TEXT("..")) return false;
|
|
471
|
+
return Parts.Num() >= 2 && (Parts[0] == TEXT("Content") || Parts[0] == TEXT("Config"));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
bool ValidatePackManifest(const IBuildManifestRef& Manifest, FString& Error)
|
|
475
|
+
{
|
|
476
|
+
const auto Files = Manifest->GetBuildFileList();
|
|
477
|
+
if (Files.IsEmpty()) { Error = TEXT("Asset pack manifest is empty."); return false; }
|
|
478
|
+
TSet<FString> Seen;
|
|
479
|
+
for (const FString& File : Files)
|
|
480
|
+
{
|
|
481
|
+
const FString Ext = FPaths::GetExtension(File).ToLower();
|
|
482
|
+
if (!SafePackPath(File) || Ext == TEXT("uplugin") || Ext == TEXT("uproject") || Ext == TEXT("dylib") || Ext == TEXT("dll")
|
|
483
|
+
|| Ext == TEXT("exe") || Ext == TEXT("sh") || Ext == TEXT("command") || Seen.Contains(File.ToLower()))
|
|
484
|
+
{ Error = TEXT("Only non-executable Content/Config asset packs with safe, unique relative paths are supported. Plugins and full projects are excluded."); return false; }
|
|
485
|
+
Seen.Add(File.ToLower());
|
|
486
|
+
}
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
FString ChunkUrl(const FString& ManifestUrl, const FString& Subdirectory, const FString& ChunkPath)
|
|
491
|
+
{
|
|
492
|
+
// The chunk path is supplied by BPS, never by an MCP caller.
|
|
493
|
+
if (ChunkPath.IsEmpty() || ChunkPath.Contains(TEXT("..")) || Subdirectory.Contains(TEXT(".."))) return {};
|
|
494
|
+
FString Base, Query;
|
|
495
|
+
if (!ManifestUrl.Split(TEXT("?"), &Base, &Query)) Base = ManifestUrl;
|
|
496
|
+
FString Result = FPaths::GetPath(Base);
|
|
497
|
+
if (!Subdirectory.IsEmpty()) Result /= Subdirectory;
|
|
498
|
+
Result /= ChunkPath;
|
|
499
|
+
if (!Query.IsEmpty()) Result += TEXT("?") + Query;
|
|
500
|
+
return Result;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
} // namespace MCPFab
|
|
504
|
+
|
|
505
|
+
TSharedPtr<FJsonValue> FFabHandlers::ListOwned(const TSharedPtr<FJsonObject>& Params)
|
|
506
|
+
{
|
|
507
|
+
const FString Query = OptionalString(Params, TEXT("query"));
|
|
508
|
+
const int32 Offset = OptionalInt(Params, TEXT("offset"), 0), Limit = OptionalInt(Params, TEXT("limit"), 50);
|
|
509
|
+
if (Offset < 0 || Limit < 1 || Limit > 200) return MCPError(TEXT("offset must be nonnegative and limit between 1 and 200."));
|
|
510
|
+
if (!IsFabLoaded()) return UnavailableError();
|
|
511
|
+
MCPFab::FSession Session; TSharedPtr<FJsonValue> Refusal;
|
|
512
|
+
if (!MCPFab::DownloadPrivate::RequireSyncedSession(Session, Refusal)) return Refusal;
|
|
513
|
+
TArray<TSharedPtr<FJsonValue>> Matches;
|
|
514
|
+
for (const auto& Item : MCPFab::Library().Items) if (Query.IsEmpty() || Item->AsObject()->GetStringField(TEXT("title")).Contains(Query)) Matches.Add(Item);
|
|
515
|
+
// Each row is the library item as Fab sent it, plus listingId (what download
|
|
516
|
+
// takes) and whether this editor's engine and platform are among its versions.
|
|
517
|
+
const FString Engine = MCPFab::DownloadPrivate::RunningEngine(), Platform = MCPFab::DownloadPrivate::RunningPlatform();
|
|
518
|
+
TArray<TSharedPtr<FJsonValue>> Page;
|
|
519
|
+
for (int32 I = Offset; I < Matches.Num() && Page.Num() < Limit; ++I)
|
|
520
|
+
{
|
|
521
|
+
const TSharedPtr<FJsonObject> Source = Matches[I]->AsObject();
|
|
522
|
+
TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>(*Source);
|
|
523
|
+
Row->SetStringField(TEXT("listingId"), MCPFab::DownloadPrivate::ListingIdOf(Source));
|
|
524
|
+
bool bCompatible = false;
|
|
525
|
+
const TArray<TSharedPtr<FJsonValue>>* Versions = nullptr;
|
|
526
|
+
if (Source->TryGetArrayField(TEXT("projectVersions"), Versions)) for (const auto& Version : *Versions)
|
|
527
|
+
{
|
|
528
|
+
if (Version && Version->Type == EJson::Object && MCPFab::DownloadPrivate::ContainsString(Version->AsObject(), TEXT("engineVersions"), Engine)
|
|
529
|
+
&& MCPFab::DownloadPrivate::ContainsString(Version->AsObject(), TEXT("targetPlatforms"), Platform)) bCompatible = true;
|
|
530
|
+
}
|
|
531
|
+
Row->SetBoolField(TEXT("availableForThisEditor"), bCompatible);
|
|
532
|
+
Page.Add(MakeShared<FJsonValueObject>(Row));
|
|
533
|
+
}
|
|
534
|
+
auto Result = MCPSuccess(); Result->SetArrayField(TEXT("items"), Page); Result->SetNumberField(TEXT("total"), Matches.Num());
|
|
535
|
+
Result->SetNumberField(TEXT("offset"), Offset); Result->SetStringField(TEXT("engineVersion"), Engine); Result->SetStringField(TEXT("platform"), Platform);
|
|
536
|
+
Result->SetObjectField(TEXT("librarySync"), MCPFab::Library().Describe()); return MCPResult(Result);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
TSharedPtr<FJsonValue> FFabHandlers::Download(const TSharedPtr<FJsonObject>& Params)
|
|
540
|
+
{
|
|
541
|
+
FString Listing;
|
|
542
|
+
if (auto Err = RequireString(Params, TEXT("listingId"), Listing)) return Err;
|
|
543
|
+
// Default to this editor's engine and platform: the pack install_pack copies
|
|
544
|
+
// in has to be one this editor can load.
|
|
545
|
+
const FString Engine = OptionalString(Params, TEXT("engineVersion"), MCPFab::DownloadPrivate::RunningEngine());
|
|
546
|
+
const FString Platform = OptionalString(Params, TEXT("platform"), MCPFab::DownloadPrivate::RunningPlatform());
|
|
547
|
+
const bool bVerify = OptionalBool(Params, TEXT("verifyOnly"), false);
|
|
548
|
+
FString Output = OptionalString(Params, TEXT("outputDirectory"));
|
|
549
|
+
if (!IsFabLoaded()) return UnavailableError();
|
|
550
|
+
MCPFab::FSession Session; TSharedPtr<FJsonValue> Refusal; FString Error;
|
|
551
|
+
if (!MCPFab::DownloadPrivate::RequireSyncedSession(Session, Refusal)) return Refusal;
|
|
552
|
+
auto Job = MakeShared<MCPFab::DownloadPrivate::FJob>();
|
|
553
|
+
if (!MCPFab::ResolveVersion(MCPFab::Library().Items, Listing, Engine, Platform, Job->Asset, Error)) return MCPError(Error);
|
|
554
|
+
if (Output.IsEmpty())
|
|
555
|
+
{
|
|
556
|
+
#if WITH_FAB_PLUGIN
|
|
557
|
+
Output = FFabAssetsCache::GetCacheLocation() / TEXT("UE-MCP") / Listing / Job->Asset.ArtifactId;
|
|
558
|
+
#else
|
|
559
|
+
return MCPError(TEXT("Fab native cache is unavailable; supply outputDirectory."));
|
|
560
|
+
#endif
|
|
561
|
+
}
|
|
562
|
+
if (FPaths::IsRelative(Output)) return MCPError(TEXT("outputDirectory must be absolute."));
|
|
563
|
+
Job->Output = FPaths::ConvertRelativePathToFull(Output); FPaths::NormalizeDirectoryName(Job->Output);
|
|
564
|
+
if (!MCPFab::DownloadPrivate::NoSymlinkParents(Job->Output)) return MCPError(TEXT("Output path contains a symlink."));
|
|
565
|
+
for (const auto& Pair : MCPFab::DownloadPrivate::Jobs) if (Pair.Value->Active()
|
|
566
|
+
&& (FPaths::IsUnderDirectory(Job->Output, Pair.Value->Output) || FPaths::IsUnderDirectory(Pair.Value->Output, Job->Output) || FPaths::IsSamePath(Job->Output, Pair.Value->Output)))
|
|
567
|
+
return MCPError(TEXT("Another job owns an overlapping output directory."));
|
|
568
|
+
Job->Owner = Session.AccountId; Job->bVerifyOnly = bVerify;
|
|
569
|
+
MCPFab::DownloadPrivate::Jobs.Add(Job->Id, Job); Job->Resolve(); return MCPFab::DownloadPrivate::MCPFabJobResult(Job, false, TEXT("fab_cancel_download"));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
TSharedPtr<FJsonValue> FFabHandlers::DownloadStatus(const TSharedPtr<FJsonObject>& Params)
|
|
573
|
+
{
|
|
574
|
+
const FString Id = OptionalString(Params, TEXT("jobId"));
|
|
575
|
+
if (!Id.IsEmpty()) { FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); return Job ? MCPFab::DownloadPrivate::MCPFabJobResult(Job) : MCPError(Error); }
|
|
576
|
+
auto Result = MCPSuccess(); TArray<TSharedPtr<FJsonValue>> Rows;
|
|
577
|
+
for (const auto& Pair : MCPFab::DownloadPrivate::Jobs) { Pair.Value->Refresh(); Rows.Add(MakeShared<FJsonValueObject>(Pair.Value->Describe())); }
|
|
578
|
+
Result->SetArrayField(TEXT("jobs"), Rows); return MCPResult(Result);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
TSharedPtr<FJsonValue> FFabHandlers::PauseDownload(const TSharedPtr<FJsonObject>& Params)
|
|
582
|
+
{
|
|
583
|
+
FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); if (!Job) return MCPError(Error);
|
|
584
|
+
const bool bUnchanged = Job->State == TEXT("paused") || Job->State == TEXT("pausing");
|
|
585
|
+
if (Job->State == TEXT("resolving")) { Job->StopRequest(); Job->State = TEXT("paused"); }
|
|
586
|
+
else if (Job->State == TEXT("downloading")) { Job->bPauseRequested = true; Job->State = TEXT("pausing"); if (Job->Verify) Job->Verify->Cancel.Store(true); else Job->Installer->CancelInstall(); }
|
|
587
|
+
else if (Job->State != TEXT("paused") && Job->State != TEXT("pausing")) return MCPError(TEXT("Only an active download can be paused."));
|
|
588
|
+
return MCPFab::DownloadPrivate::MCPFabJobResult(Job, bUnchanged, TEXT("fab_resume_download"));
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
TSharedPtr<FJsonValue> FFabHandlers::ResumeDownload(const TSharedPtr<FJsonObject>& Params)
|
|
592
|
+
{
|
|
593
|
+
FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); if (!Job) return MCPError(Error);
|
|
594
|
+
if (Job->State != TEXT("paused") && Job->State != TEXT("failed") && Job->State != TEXT("cancelled")) return MCPError(TEXT("Wait for a paused, failed or cancelled state before resuming."));
|
|
595
|
+
for (const auto& Pair : MCPFab::DownloadPrivate::Jobs) if (Pair.Value != Job && Pair.Value->Active()
|
|
596
|
+
&& (FPaths::IsUnderDirectory(Job->Output, Pair.Value->Output) || FPaths::IsUnderDirectory(Pair.Value->Output, Job->Output) || FPaths::IsSamePath(Job->Output, Pair.Value->Output)))
|
|
597
|
+
return MCPError(TEXT("Another job owns an overlapping output directory."));
|
|
598
|
+
Job->Resolve(); return MCPFab::DownloadPrivate::MCPFabJobResult(Job, false, TEXT("fab_pause_download"));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
TSharedPtr<FJsonValue> FFabHandlers::CancelDownload(const TSharedPtr<FJsonObject>& Params)
|
|
602
|
+
{
|
|
603
|
+
FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); if (!Job) return MCPError(Error);
|
|
604
|
+
const bool bUnchanged = Job->State == TEXT("cancelled") || Job->State == TEXT("complete");
|
|
605
|
+
Job->StopRequest(); Job->bPauseRequested = false;
|
|
606
|
+
if (Job->Verify && !Job->Verify->Done.Load()) { Job->State = TEXT("cancelling"); Job->Verify->Cancel.Store(true); }
|
|
607
|
+
else if (Job->Installer && !Job->Installer->IsComplete()) { Job->State = TEXT("cancelling"); Job->Installer->CancelInstall(); }
|
|
608
|
+
else if (Job->State != TEXT("complete")) Job->State = TEXT("cancelled");
|
|
609
|
+
return MCPFab::DownloadPrivate::MCPFabJobResult(Job, bUnchanged, TEXT("fab_resume_download"));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
TSharedPtr<FJsonValue> FFabHandlers::InstallPack(const TSharedPtr<FJsonObject>& Params)
|
|
613
|
+
{
|
|
614
|
+
FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); if (!Job) return MCPError(Error);
|
|
615
|
+
if (Job->State != TEXT("complete") || !Job->Manifest) return MCPError(TEXT("The download must complete native SHA verification before installation."));
|
|
616
|
+
TArray<TPair<FString, FString>> Pending;
|
|
617
|
+
TMap<FString, FSHAHash> ExpectedHashes;
|
|
618
|
+
int32 Unchanged = 0;
|
|
619
|
+
// Check every source and collision before creating a single project file.
|
|
620
|
+
for (const FString& File : Job->Manifest->GetBuildFileList())
|
|
621
|
+
{
|
|
622
|
+
if (!File.StartsWith(TEXT("Content/"))) continue;
|
|
623
|
+
const FString Extension = FPaths::GetExtension(File).ToLower();
|
|
624
|
+
if (Extension != TEXT("uasset") && Extension != TEXT("umap") && Extension != TEXT("ubulk") && Extension != TEXT("uexp") && Extension != TEXT("uptnl"))
|
|
625
|
+
return MCPError(TEXT("Install supports native UE packages and their bulk companions only; import loose files using import_file."));
|
|
626
|
+
const FString Source = Job->Output / File;
|
|
627
|
+
const FString Destination = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir() / File.Mid(8));
|
|
628
|
+
if (!MCPFab::DownloadPrivate::NoSymlinkParents(Source) || !MCPFab::DownloadPrivate::NoSymlinkParents(Destination)) return MCPError(TEXT("Pack source or project destination contains a symlink."));
|
|
629
|
+
FSHAHash SourceHash; const FSHAHash* Expected = Job->Manifest->GetFileSHA1Hash(File);
|
|
630
|
+
if (!Expected || !MCPFab::DownloadPrivate::FileHash(Source, SourceHash) || SourceHash != *Expected) return MCPError(TEXT("A downloaded file changed since verification. Run download with verifyOnly before installing."));
|
|
631
|
+
if (IFileManager::Get().FileExists(*Destination))
|
|
632
|
+
{
|
|
633
|
+
FSHAHash Hash;
|
|
634
|
+
if (!MCPFab::DownloadPrivate::FileHash(Destination, Hash) || Hash != *Expected) return MCPError(TEXT("A different project file occupies a pack path. Nothing was copied; choose an isolated reference project."));
|
|
635
|
+
++Unchanged;
|
|
636
|
+
}
|
|
637
|
+
else { Pending.Emplace(Source, Destination); ExpectedHashes.Add(Destination, *Expected); }
|
|
638
|
+
}
|
|
639
|
+
if (Pending.IsEmpty() && Unchanged == 0) return MCPError(TEXT("No Content files in this asset pack."));
|
|
640
|
+
TArray<FString> Created;
|
|
641
|
+
for (const auto& File : Pending)
|
|
642
|
+
{
|
|
643
|
+
IFileManager::Get().MakeDirectory(*FPaths::GetPath(File.Value), true);
|
|
644
|
+
if (IFileManager::Get().Copy(*File.Value, *File.Key, false, false) != COPY_OK)
|
|
645
|
+
{
|
|
646
|
+
for (const FString& Path : Created) { IFileManager::Get().Delete(*Path); Job->CreatedFiles.Remove(Path); }
|
|
647
|
+
return MCPError(TEXT("Copy failed; files created by this call were removed. Existing project files were retained."));
|
|
648
|
+
}
|
|
649
|
+
Created.Add(File.Value);
|
|
650
|
+
FSHAHash Hash;
|
|
651
|
+
if (!MCPFab::DownloadPrivate::FileHash(File.Value, Hash) || Hash != ExpectedHashes[File.Value])
|
|
652
|
+
{
|
|
653
|
+
for (const FString& Path : Created) { IFileManager::Get().Delete(*Path); Job->CreatedFiles.Remove(Path); }
|
|
654
|
+
return MCPError(TEXT("Copied file failed SHA verification; files created by this call were removed."));
|
|
655
|
+
}
|
|
656
|
+
Job->CreatedFiles.Add(File.Value, Hash);
|
|
657
|
+
}
|
|
658
|
+
auto& Registry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
|
|
659
|
+
TArray<FString> Packages;
|
|
660
|
+
for (const FString& Path : Created) if (Path.EndsWith(TEXT(".uasset")) || Path.EndsWith(TEXT(".umap"))) Packages.Add(Path);
|
|
661
|
+
Registry.ScanFilesSynchronous(Packages, true);
|
|
662
|
+
auto Result = MCPSuccess(); Result->SetNumberField(TEXT("copiedFiles"), Created.Num()); Result->SetNumberField(TEXT("unchangedFiles"), Unchanged);
|
|
663
|
+
Result->SetBoolField(TEXT("unchanged"), Created.IsEmpty());
|
|
664
|
+
if (!Created.IsEmpty())
|
|
665
|
+
{
|
|
666
|
+
auto Payload = MakeShared<FJsonObject>(); Payload->SetStringField(TEXT("jobId"), Job->Id);
|
|
667
|
+
MCPSetRollback(Result, TEXT("fab_remove_installation"), Payload);
|
|
668
|
+
}
|
|
669
|
+
else MCPSetNoRollback(Result, TEXT("All pack files already existed with identical content, so this call created nothing."));
|
|
670
|
+
Result->SetStringField(TEXT("note"), TEXT("Content paths preserved. Config, plugins and project settings were not installed."));
|
|
671
|
+
return MCPResult(Result);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
TSharedPtr<FJsonValue> FFabHandlers::RemoveInstallation(const TSharedPtr<FJsonObject>& Params)
|
|
675
|
+
{
|
|
676
|
+
FString Error; auto Job = MCPFab::DownloadPrivate::FindJob(Params, Error); if (!Job) return MCPError(Error);
|
|
677
|
+
TArray<FString> Existing;
|
|
678
|
+
TSet<FName> OwnedPackages;
|
|
679
|
+
for (const auto& Pair : Job->CreatedFiles)
|
|
680
|
+
{
|
|
681
|
+
FString Package;
|
|
682
|
+
if (FPackageName::TryConvertFilenameToLongPackageName(Pair.Key, Package)) OwnedPackages.Add(FName(Package));
|
|
683
|
+
}
|
|
684
|
+
auto& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
|
|
685
|
+
for (const auto& Pair : Job->CreatedFiles)
|
|
686
|
+
{
|
|
687
|
+
if (!IFileManager::Get().FileExists(*Pair.Key)) continue;
|
|
688
|
+
FSHAHash Hash;
|
|
689
|
+
if (!MCPFab::DownloadPrivate::NoSymlinkParents(Pair.Key) || !MCPFab::DownloadPrivate::FileHash(Pair.Key, Hash) || Hash != Pair.Value)
|
|
690
|
+
return MCPError(TEXT("A file created by this installation changed. No files were removed."));
|
|
691
|
+
FString Package;
|
|
692
|
+
if (FPackageName::TryConvertFilenameToLongPackageName(Pair.Key, Package) && FindPackage(nullptr, *Package))
|
|
693
|
+
return MCPError(TEXT("A package from this installation is loaded. Close its editor or level before removing it."));
|
|
694
|
+
TArray<FName> Referencers;
|
|
695
|
+
if (!Package.IsEmpty()) AssetRegistry.GetReferencers(FName(Package), Referencers);
|
|
696
|
+
for (FName Referencer : Referencers) if (!OwnedPackages.Contains(Referencer)) return MCPError(TEXT("A project asset outside this installation references a pack package. No files were removed."));
|
|
697
|
+
Existing.Add(Pair.Key);
|
|
698
|
+
}
|
|
699
|
+
for (const FString& Path : Existing) if (!IFileManager::Get().Delete(*Path)) return MCPError(TEXT("Could not remove an installation file. Re-run install_pack to restore verified content."));
|
|
700
|
+
TArray<FString> Packages;
|
|
701
|
+
for (const FString& Path : Existing) if (Path.EndsWith(TEXT(".uasset")) || Path.EndsWith(TEXT(".umap"))) Packages.Add(Path);
|
|
702
|
+
AssetRegistry.ScanModifiedAssetFiles(Packages);
|
|
703
|
+
Job->CreatedFiles.Reset();
|
|
704
|
+
auto Result = MCPSuccess(); Result->SetNumberField(TEXT("removedFiles"), Existing.Num()); Result->SetBoolField(TEXT("unchanged"), Existing.IsEmpty());
|
|
705
|
+
if (!Existing.IsEmpty()) { auto Payload = MakeShared<FJsonObject>(); Payload->SetStringField(TEXT("jobId"), Job->Id); MCPSetRollback(Result, TEXT("fab_install_pack"), Payload); }
|
|
706
|
+
else MCPSetNoRollback(Result, TEXT("No files created by this job remained on disk."));
|
|
707
|
+
return MCPResult(Result);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
namespace MCPFab
|
|
711
|
+
{
|
|
712
|
+
bool HasActiveDownloads()
|
|
713
|
+
{
|
|
714
|
+
for (const auto& Pair : DownloadPrivate::Jobs) if (Pair.Value->Active()) return true;
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
void ShutdownDownloads()
|
|
719
|
+
{
|
|
720
|
+
for (const auto& Pair : DownloadPrivate::Jobs)
|
|
721
|
+
{
|
|
722
|
+
Pair.Value->StopRequest();
|
|
723
|
+
if (Pair.Value->Verify) Pair.Value->Verify->Cancel.Store(true);
|
|
724
|
+
if (Pair.Value->Verification.IsValid()) Pair.Value->Verification.Wait();
|
|
725
|
+
if (Pair.Value->Installer)
|
|
726
|
+
{
|
|
727
|
+
Pair.Value->Installer->UnregisterMessageHandler(Pair.Value->Cdn.Get());
|
|
728
|
+
Pair.Value->Installer->CancelInstall();
|
|
729
|
+
// Bounded: a chunk-URI request still queued for BPS's message pump
|
|
730
|
+
// is answered only from the core ticker, which does not run while
|
|
731
|
+
// the module shuts down, and an unbounded wait hung the editor's exit.
|
|
732
|
+
const double GiveUpAt = FPlatformTime::Seconds() + 5.0;
|
|
733
|
+
while (!Pair.Value->Installer->IsComplete() && FPlatformTime::Seconds() < GiveUpAt) FPlatformProcess::Sleep(0.01f);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
// Only this category's jobs are cancelled; native Fab downloads remain owned by Fab.
|
|
737
|
+
DownloadPrivate::Jobs.Reset();
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
#if WITH_DEV_AUTOMATION_TESTS
|
|
741
|
+
FString StartFixtureDownload(const IBuildManifestRef& Manifest, const FString& Cloud, const FString& Output, bool bVerifyOnly)
|
|
742
|
+
{
|
|
743
|
+
auto Job = MakeShared<DownloadPrivate::FJob>(); Job->Manifest = Manifest; Job->Output = Output; Job->Asset.ArtifactId = TEXT("fixture"); Job->FixtureCloud = Cloud; Job->bVerifyOnly = bVerifyOnly;
|
|
744
|
+
DownloadPrivate::Jobs.Add(Job->Id, Job); Job->StartInstaller(Cloud / TEXT("fixture.manifest")); return Job->Id;
|
|
745
|
+
}
|
|
746
|
+
#endif
|
|
747
|
+
#else
|
|
748
|
+
} // namespace MCPFab
|
|
749
|
+
TSharedPtr<FJsonValue> FFabHandlers::ListOwned(const TSharedPtr<FJsonObject>&)
|
|
750
|
+
{
|
|
751
|
+
return MCPUnsupportedEngineError(TEXT("Owned Fab content (list_owned, download and the job actions)"), TEXT("5.8"),
|
|
752
|
+
TEXT("They read the Fab Content Browser table and drive BuildPatchServices through APIs that first exist in 5.8"));
|
|
753
|
+
}
|
|
754
|
+
TSharedPtr<FJsonValue> FFabHandlers::Download(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
755
|
+
TSharedPtr<FJsonValue> FFabHandlers::DownloadStatus(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
756
|
+
TSharedPtr<FJsonValue> FFabHandlers::PauseDownload(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
757
|
+
TSharedPtr<FJsonValue> FFabHandlers::ResumeDownload(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
758
|
+
TSharedPtr<FJsonValue> FFabHandlers::CancelDownload(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
759
|
+
TSharedPtr<FJsonValue> FFabHandlers::InstallPack(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
760
|
+
TSharedPtr<FJsonValue> FFabHandlers::RemoveInstallation(const TSharedPtr<FJsonObject>& Params) { return ListOwned(Params); }
|
|
761
|
+
namespace MCPFab
|
|
762
|
+
{
|
|
763
|
+
bool HasActiveDownloads() { return false; }
|
|
764
|
+
void ShutdownDownloads() {}
|
|
765
|
+
#endif
|
|
766
|
+
}
|