A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.4KB

  1. #!/usr/bin/python3
  2. import argparse
  3. from pathlib import Path, PurePath
  4. import re
  5. import os
  6. DLL_EXCLUSIONS_REGEX = r"(System|Microsoft|Mono|IronPython|DiscordRPC)\."
  7. def getAssemblyReferences(path):
  8. asmDir = Path(path)
  9. result = list()
  10. addedPath = ""
  11. if not asmDir.exists():
  12. addedPath = "../"
  13. asmDir = Path(addedPath + path)
  14. for child in asmDir.iterdir():
  15. if child.is_file() and re.search(DLL_EXCLUSIONS_REGEX, str(child), re.I) is None and str(child).lower().endswith(".dll"):
  16. childstr = str(child)
  17. childstr = os.path.relpath(childstr, addedPath).replace("\\", "/")
  18. result.append(childstr)
  19. return result
  20. def buildReferencesXml(path):
  21. assemblyPathes = getAssemblyReferences(path)
  22. result = list()
  23. for asm in assemblyPathes:
  24. asmPath = str(asm)
  25. xml = " <Reference Include=\"" + asmPath[asmPath.rfind("/") + 1:].replace(".dll", "") + "\">\n" \
  26. + " <HintPath>" + asmPath.replace("/", "\\") + "</HintPath>\n" \
  27. + " <HintPath>..\\" + asmPath.replace("/", "\\") + "</HintPath>\n" \
  28. + " </Reference>\n"
  29. result.append(xml)
  30. return "<!--Start Dependencies-->\n <ItemGroup>\n" + "".join(result) + " </ItemGroup>\n<!--End Dependencies-->"
  31. if __name__ == "__main__":
  32. parser = argparse.ArgumentParser(description="Generate TechbloxModdingAPI.csproj")
  33. # TODO (maybe?): add params for custom csproj read and write locations
  34. args = parser.parse_args()
  35. print("Building Assembly references")
  36. asmXml = buildReferencesXml("../ref/Techblox_Data/Managed")
  37. # print(asmXml)
  38. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "r") as xmlFile:
  39. print("Parsing TechbloxModdingAPI.csproj")
  40. fileStr = xmlFile.read()
  41. # print(fileStr)
  42. depsStart = re.search(r"\<!--\s*Start\s+Dependencies\s*--\>", fileStr)
  43. depsEnd = re.search(r"\<!--\s*End\s+Dependencies\s*--\>", fileStr)
  44. if depsStart is None or depsEnd is None:
  45. print("Unable to find dependency XML comments, aborting!")
  46. exit(1)
  47. newFileStr = fileStr[:depsStart.start()] + "\n" + asmXml + "\n" + fileStr[depsEnd.end() + 1:]
  48. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "w") as xmlFile:
  49. print("Writing Assembly references")
  50. xmlFile.write(newFileStr)
  51. # print(newFileStr)