-
Notifications
You must be signed in to change notification settings - Fork 63
/
InstallPlugin.py
361 lines (324 loc) · 13.2 KB
/
InstallPlugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import sys
import platform
import os
import tempfile
import shutil
import subprocess
import glob
import json
import collections
scriptPath = os.path.realpath(os.getcwd())
pluginFile = os.path.join(scriptPath, "NoesisGUI.uplugin")
if not os.path.isfile(pluginFile):
print("This script must be run from the NoesisGUI plugin directory. Exiting...")
exit(1)
if not os.path.isfile(os.path.join(scriptPath, "Source", "Noesis", "NoesisSDK", "Include", "NoesisPCH.h")):
print("You must install the NoesisGUI native SDK in Source/Noesis/NoesisSDK. Exiting...")
exit(1)
if platform.platform().startswith("Windows"):
hostPlatform = "Win64"
if platform.platform().startswith("Darwin"):
hostPlatform = "Mac"
allInstallations = collections.OrderedDict()
try:
import configparser
except:
print("Module configparser not installed. Exiting...")
exit(1)
if hostPlatform == "Win64":
try:
import win32api
import win32con
except:
print("Module pywin32 not installed. Exiting...")
exit(1)
import ctypes
from ctypes import wintypes, windll
from win32com.shell import shellcon, shell
def getProgramDataPath():
try:
return shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0)
except:
return ""
programDataPath = getProgramDataPath()
if programDataPath == "":
print("Can't find application support folder")
exit(1)
applicationSettingsPath = os.path.join(programDataPath, "Epic")
installedListFile = os.path.join(applicationSettingsPath, "UnrealEngineLauncher", "LauncherInstalled.dat")
if os.path.isfile(installedListFile):
launcherInstalled = json.load(open(installedListFile))
installationList = launcherInstalled["InstallationList"]
if installationList is not None:
for installation in installationList:
appName = installation["AppName"]
if appName.startswith("UE_"):
appName = appName[3:]
installLocation = installation["InstallLocation"]
allInstallations[appName] = installLocation
try:
reghandle = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"SOFTWARE\\Epic Games\\Unreal Engine\\Builds", 0, win32con.KEY_ALL_ACCESS)
index = 0
while True:
name, value, type = win32api.RegEnumValue(reghandle, index)
allInstallations[name] = value
index += 1
except:
pass
if hostPlatform == "Mac":
try:
import Cocoa
except:
print("Module pyobjc not installed. Exiting...")
exit(1)
applicationSupportPaths = Cocoa.NSSearchPathForDirectoriesInDomains(Cocoa.NSApplicationSupportDirectory, Cocoa.NSUserDomainMask, True)
if len(applicationSupportPaths) == 0:
print("Can't find application support folder")
exit(1)
applicationSettingsPath = applicationSupportPaths[0].stringByAppendingPathComponent_("Epic")
installedListFile = applicationSettingsPath.stringByAppendingPathComponent_("UnrealEngineLauncher").stringByAppendingPathComponent_("LauncherInstalled.dat")
if os.path.isfile(installedListFile):
launcherInstalled = json.load(open(installedListFile.cStringUsingEncoding_(Cocoa.NSUTF8StringEncoding)))
installationList = launcherInstalled["InstallationList"]
if installationList is not None:
for installation in installationList:
appName = installation["AppName"]
if appName.startswith("UE_"):
appName = appName[3:]
installLocation = installation["InstallLocation"]
allInstallations[appName] = installLocation
configFile = applicationSettingsPath.stringByAppendingPathComponent_("UnrealEngine").stringByAppendingPathComponent_("Install.ini")
if os.path.isfile(configFile):
config = configparser.ConfigParser()
config.read(configFile)
if "Installations" in config:
installations = config["Installations"]
if installations is not None:
allInstallations.update(installations)
print("Found the following engine installations:")
for id, path in allInstallations.items():
print(id + " = " + path)
engineInstall = False
installerEngineInstall = False
pluginEnginePath = None
for id, installation in allInstallations.items():
enginePath = os.path.realpath(installation)
if os.path.commonprefix([enginePath, scriptPath]) == enginePath:
engineInstall = True
if not id.startswith("{"):
installerEngineInstall = True
pluginEnginePath = enginePath
print("Found engine for plugin at " + pluginEnginePath)
break
if pluginEnginePath is None:
print("Plugin is not installed in any of the installed engines. Looking for projects...")
currentPath, currentDir = os.path.split(scriptPath)
while currentDir != "":
projectFiles = glob.glob(os.path.join(currentPath, "*.uproject"))
if projectFiles:
projectFile = projectFiles[0]
print("Found project for plugin at " + projectFile)
try:
project = json.load(open(projectFile), object_pairs_hook=collections.OrderedDict)
engineAssociation = project["EngineAssociation"]
if engineAssociation is not None:
if engineAssociation in allInstallations:
pluginEnginePath = os.path.realpath(allInstallations[engineAssociation])
print("Found associated engine at " + pluginEnginePath)
break
else:
print("Couldn't find an engine with id " + engineAssociation)
exit(1)
except:
print("Malformed project file. Exiting...")
exit(1)
currentPath, currentDir = os.path.split(currentPath)
if pluginEnginePath is None:
print("Couldn't find an engine for the plugin. Exiting...")
exit(1)
if not os.path.isdir(pluginEnginePath):
print(pluginEnginePath + " doesn't exist. Exiting...")
exit(1)
if engineInstall:
if installerEngineInstall:
packagePath = tempfile.mkdtemp()
packageCmdLine = ["-Package=" + packagePath]
pluginCmdLine = ["-Plugin=" + pluginFile]
else:
packagePath = tempfile.mkdtemp()
projectFile = os.path.join(packagePath, "NoesisGUI.uproject")
projectCmdLine = ["-project=" + projectFile]
project = { "FileVersion" : 3, "Plugins" : [ { "Name" : "NoesisGUI", "Enabled" : True } ] }
json.dump(project, open(projectFile, "w+"))
else:
projectCmdLine = ["-project=" + projectFile]
if "Plugins" in project:
foundPlugin = False
plugins = project["Plugins"]
for plugin in plugins:
if plugin["Name"] == "NoesisGUI":
foundPlugin = True
if not plugin["Enabled"]:
print("Project includes NoesisGUI plugin, but it's disabled. Enabling...")
plugin["Enabled"] = True
if not foundPlugin:
print("Project does not include NoesisGUI plugin. Including...")
plugins += [ collections.OrderedDict([("Name", "NoesisGUI"), ("Enabled", True)]) ]
else:
print("Project does not include NoesisGUI plugin. Including...")
project["Plugins"] = [ collections.OrderedDict([("Name", "NoesisGUI"), ("Enabled", True)]) ]
json.dump(project, open(projectFile, "w+"), indent=2, separators=(',', ': '))
arguments = sys.argv[1:]
if hostPlatform == "Win64":
ubtFile = os.path.join(pluginEnginePath, "Engine", "Binaries", "DotNET", "UnrealBuildTool.exe")
if not os.path.isfile(ubtFile):
print(pluginEnginePath + " doesn't appear to be a valid engine installation. Exiting...")
exit(1)
runUatFile = os.path.join(pluginEnginePath, "Engine", "Build", "BatchFiles", "RunUAT.bat")
if not os.path.isfile(runUatFile):
print(pluginEnginePath + " doesn't appear to be a valid engine installation. Exiting...")
exit(1)
def build(target, configurations, platforms):
modulesCmdLine = ["-module=NoesisRuntime"]
if target == "UE4Editor":
modulesCmdLine += ["-module=NoesisEditor"]
else:
modulesCmdLine += ["-ignorejunk"]
additionalCmdLine = []
if "-verbose" in arguments:
additionalCmdLine += ["-verbose"]
for platform in platforms:
for configuration in configurations:
print("Building " + target + " " + configuration + " " + platform)
buildCmdLine = [ubtFile, target, platform, configuration, "-WaitMutex", "-FromMsBuild"] + modulesCmdLine + projectCmdLine + additionalCmdLine
process = subprocess.Popen(buildCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
metadataFile = os.path.join(os.path.dirname(projectFile), "Intermediate", "Build", platform, target, configuration, "Metadata.dat");
inputCmdLine = ["-Input=" + metadataFile]
writeMetadataCmdLine = [ubtFile, "-Mode=WriteMetadata", "-Version=1"] + inputCmdLine
print(writeMetadataCmdLine)
process = subprocess.Popen(writeMetadataCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
def buildPlugin(platforms):
hostPlatformCmdLine = []
if hostPlatform not in platforms:
hostPlatformCmdLine += ["-NoHostPlatform"]
targetPlatformsCmdLine = ["-TargetPlatforms=" + '+'.join(platforms)]
buildCmdLine = [runUatFile, "BuildPlugin"] + pluginCmdLine + targetPlatformsCmdLine + packageCmdLine + hostPlatformCmdLine
process = subprocess.Popen(buildCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
if hostPlatform == "Mac":
monoFile = os.path.join(pluginEnginePath, "Engine", "Build", "BatchFiles", "Mac", "RunMono.sh")
if not os.path.isfile(monoFile):
print(pluginEnginePath + " doesn't appear to be a valid engine installation. Exiting...")
exit(1)
ubtFile = os.path.join(pluginEnginePath, "Engine", "Binaries", "DotNET", "UnrealBuildTool.exe")
if not os.path.isfile(ubtFile):
print(pluginEnginePath + " doesn't appear to be a valid engine installation. Exiting...")
exit(1)
runUatFile = os.path.join(pluginEnginePath, "Engine", "Build", "BatchFiles", "RunUAT.sh")
if not os.path.isfile(runUatFile):
print(pluginEnginePath + " doesn't appear to be a valid engine installation. Exiting...")
exit(1)
def build(target, configurations, platforms):
modulesCmdLine = ["-module=NoesisRuntime"]
if target == "UE4Editor":
modulesCmdLine += ["-module=NoesisEditor"]
else:
modulesCmdLine += ["-ignorejunk"]
additionalCmdLine = []
if "-verbose" in arguments:
additionalCmdLine += ["-verbose"]
for platform in platforms:
for configuration in configurations:
print("Building " + target + " " + configuration + " " + platform)
buildCmdLine = [monoFile, ubtFile, target, platform, configuration, "-WaitMutex", "-FromMsBuild"] + modulesCmdLine + projectCmdLine + additionalCmdLine
process = subprocess.Popen(buildCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
metadataFile = os.path.join(os.path.dirname(projectFile), "Intermediate", "Build", platform, target, configuration, "Metadata.dat");
inputCmdLine = ["-Input=" + metadataFile]
writeMetadataCmdLine = [monoFile, ubtFile, "-Mode=WriteMetadata", "-Version=1"] + inputCmdLine
print(writeMetadataCmdLine)
process = subprocess.Popen(writeMetadataCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
def buildPlugin(platforms):
hostPlatformCmdLine = []
if hostPlatform not in platforms:
hostPlatformCmdLine += ["-NoHostPlatform"]
targetPlatformsCmdLine = ["-TargetPlatforms=" + '+'.join(platforms)]
buildCmdLine = [runUatFile, "BuildPlugin"] + pluginCmdLine + targetPlatformsCmdLine + packageCmdLine + hostPlatformCmdLine
process = subprocess.Popen(buildCmdLine)
while process.poll() is None:
stdout, stderr = process.communicate()
if stdout is not None:
print(stdout)
allowedPlatforms = [ "Win64", "Mac", "IOS", "Android", "PS4", "XboxOne" ]
excludedPlatforms = []
buildPlatforms = [hostPlatform]
for buildPlatform in arguments:
if buildPlatform in allowedPlatforms:
if buildPlatform not in excludedPlatforms:
buildPlatforms += [buildPlatform]
if hostPlatform == "Win64":
pluginEngineBinariesPath = os.path.join(pluginEnginePath, "Engine", "Binaries", "Win64")
if os.path.isfile(pluginEngineBinariesPath):
print("Deleting " + pluginEngineBinariesPath)
os.remove(pluginEngineBinariesPath)
if not installerEngineInstall:
if not arguments:
build("UE4Editor", ["Development"], [hostPlatform])
else:
if buildPlatforms:
if hostPlatform in buildPlatforms:
build("UE4Editor", ["Development"], [hostPlatform])
else:
print("No valid platforms specified. Exiting...")
else:
print("Launcher engine installation detected. This configuration is no longer supported. Please install as a project plugin.")
exit(1)
if engineInstall:
if installerEngineInstall:
dst = os.path.join(scriptPath, "Binaries")
if not os.path.exists(dst):
os.mkdir(dst)
for root, dirs, files in os.walk(os.path.join(packagePath, "Binaries")):
for item in files:
src = os.path.join(root, item)
dst = os.path.join(scriptPath, src.replace(packagePath, "")[1:])
shutil.copy2(src, dst)
for item in dirs:
src = os.path.join(root, item)
dst = os.path.join(scriptPath, src.replace(packagePath, "")[1:])
if not os.path.exists(dst):
os.mkdir(dst)
dst = os.path.join(scriptPath, "Intermediate")
if not os.path.exists(dst):
os.mkdir(dst)
for root, dirs, files in os.walk(os.path.join(packagePath, "Intermediate")):
for item in files:
src = os.path.join(root, item)
dst = os.path.join(scriptPath, src.replace(packagePath, "")[1:])
shutil.copy2(src, dst)
for item in dirs:
src = os.path.join(root, item)
dst = os.path.join(scriptPath, src.replace(packagePath, "")[1:])
if not os.path.exists(dst):
os.mkdir(dst)
shutil.rmtree(packagePath)
else:
shutil.rmtree(packagePath)