2020-05-03 19:14:13 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path, PurePath
|
|
|
|
import re
|
|
|
|
|
2020-05-09 00:09:41 +00:00
|
|
|
DLL_EXCLUSIONS_REGEX = r"(System|Microsoft|Mono|IronPython|DiscordRPC)\."
|
2020-05-03 19:14:13 +00:00
|
|
|
|
|
|
|
def getAssemblyReferences(path):
|
|
|
|
asmDir = Path(path)
|
|
|
|
result = list()
|
|
|
|
for child in asmDir.iterdir():
|
2020-05-03 19:21:40 +00:00
|
|
|
if child.is_file() and re.search(DLL_EXCLUSIONS_REGEX, str(child), re.I) is None and str(child).lower().endswith(".dll"):
|
2020-05-03 19:14:13 +00:00
|
|
|
result.append(str(child).replace("\\", "/"))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def buildReferencesXml(path):
|
|
|
|
assemblyPathes = getAssemblyReferences(path)
|
|
|
|
result = list()
|
|
|
|
for asm in assemblyPathes:
|
|
|
|
asmPath = str(asm)
|
|
|
|
xml = " <Reference Include=\"" + asmPath[asmPath.rfind("/") + 1:].replace(".dll", "") + "\">\n" \
|
|
|
|
+ " <HintPath>" + asmPath.replace("/", "\\") + "</HintPath>\n" \
|
|
|
|
+ " <HintPath>..\\" + asmPath.replace("/", "\\") + "</HintPath>\n" \
|
|
|
|
+ " </Reference>\n"
|
|
|
|
result.append(xml)
|
2020-05-03 19:21:40 +00:00
|
|
|
return "<!--Start Dependencies-->\n <ItemGroup>\n" + "".join(result) + " </ItemGroup>\n<!--End Dependencies-->"
|
2020-05-03 19:14:13 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-05-11 20:56:36 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Generate TechbloxModdingAPI.csproj")
|
2020-05-03 19:14:13 +00:00
|
|
|
# TODO (maybe?): add params for custom csproj read and write locations
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
print("Building Assembly references")
|
2021-04-10 00:02:47 +00:00
|
|
|
asmXml = buildReferencesXml("../ref/TechbloxPreview_Data/Managed")
|
2020-05-03 19:21:40 +00:00
|
|
|
# print(asmXml)
|
2020-05-03 19:14:13 +00:00
|
|
|
|
2021-05-11 20:56:36 +00:00
|
|
|
with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "r") as xmlFile:
|
|
|
|
print("Parsing TechbloxModdingAPI.csproj")
|
2020-05-03 19:14:13 +00:00
|
|
|
fileStr = xmlFile.read()
|
2020-05-03 19:21:40 +00:00
|
|
|
# print(fileStr)
|
2020-05-03 19:14:13 +00:00
|
|
|
depsStart = re.search(r"\<!--\s*Start\s+Dependencies\s*--\>", fileStr)
|
|
|
|
depsEnd = re.search(r"\<!--\s*End\s+Dependencies\s*--\>", fileStr)
|
|
|
|
if depsStart is None or depsEnd is None:
|
|
|
|
print("Unable to find dependency XML comments, aborting!")
|
|
|
|
exit(1)
|
2020-05-03 19:21:40 +00:00
|
|
|
newFileStr = fileStr[:depsStart.start()] + "\n" + asmXml + "\n" + fileStr[depsEnd.end() + 1:]
|
2021-05-11 20:56:36 +00:00
|
|
|
with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "w") as xmlFile:
|
2020-05-15 03:08:37 +00:00
|
|
|
print("Writing Assembly references")
|
2020-05-03 19:14:13 +00:00
|
|
|
xmlFile.write(newFileStr)
|
2020-05-03 19:21:40 +00:00
|
|
|
# print(newFileStr)
|
2020-05-03 19:14:13 +00:00
|
|
|
|
|
|
|
|