-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_embedded.py
35 lines (29 loc) · 1.34 KB
/
generate_embedded.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
import glob
from pathlib import Path
# PowerShellConfig calls typeof(PSObject).Assembly.Location in its constructor,
# which returns an empty string on memory-loaded assemblies and breaks subsequent path operations.
BLACKLISTED_DEPENDENCIES = "System.Management.Automation.dll"
dependencies = {}
paths_to_check = ["SharpShell/bin/Release/net6.0/publish/win-x64/*.dll"]
for check_path in paths_to_check:
for file in glob.glob(check_path):
path = Path(file)
if path.name not in BLACKLISTED_DEPENDENCIES:
print(f"embedding dependency {path.name}")
data = open(file, "rb").read()
dependencies[path.name[:-4]] = data
dependencies_source = ""
dependencies_source += "// <auto-generated />\n"
dependencies_source += "namespace AutoGenerated\n"
dependencies_source += "{\n"
dependencies_source += "\tinternal static class Dependencies\n"
dependencies_source += "\t{\n"
dependencies_source += "\t\tpublic static Dictionary<string, byte[]> Files = new()\n"
dependencies_source += "\t\t{\n"
for name, data in dependencies.items():
dependencies_source += f'\t\t\t["{name.lower()}"] = [{", ".join([str(x) for x in data])}],\n'
dependencies_source += "\t\t};\n"
dependencies_source += "\t}\n"
dependencies_source += "}\n"
with open("SharpShell.Loader/Dependencies.g.cs", "w") as f:
f.write(dependencies_source)