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.

63 lines
2.6KB

  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|IllusionInjector|IllusionPlugin|netstandard)\."
  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)) 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. result.sort(key=str.lower)
  20. result = [path + "/IllusionInjector.dll", path + "/IllusionPlugin.dll"] + result # Always put it on top
  21. return result
  22. def buildReferencesXml(path):
  23. assemblyPathes = getAssemblyReferences(path)
  24. result = list()
  25. for asm in assemblyPathes:
  26. asmPath = str(asm)
  27. xml = " <Reference Include=\"" + asmPath[asmPath.rfind("/") + 1:].replace(".dll", "") + "\">\n" \
  28. + " <HintPath>" + asmPath.replace("/", "\\") + "</HintPath>\n" \
  29. + " <HintPath>..\\" + asmPath.replace("/", "\\") + "</HintPath>\n" \
  30. + " </Reference>\n"
  31. result.append(xml)
  32. return "<!--Start Dependencies-->\n <ItemGroup>\n" + "".join(result) + " </ItemGroup>\n<!--End Dependencies-->"
  33. if __name__ == "__main__":
  34. parser = argparse.ArgumentParser(description="Generate TechbloxModdingAPI.csproj")
  35. # TODO (maybe?): add params for custom csproj read and write locations
  36. args = parser.parse_args()
  37. print("Building Assembly references")
  38. asmXml = buildReferencesXml("../ref/Techblox_Data/Managed")
  39. # print(asmXml)
  40. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "r") as xmlFile:
  41. print("Parsing TechbloxModdingAPI.csproj")
  42. fileStr = xmlFile.read()
  43. # print(fileStr)
  44. depsStart = re.search(r"\<!--\s*Start\s+Dependencies\s*--\>", fileStr)
  45. depsEnd = re.search(r"\<!--\s*End\s+Dependencies\s*--\>", fileStr)
  46. if depsStart is None or depsEnd is None:
  47. print("Unable to find dependency XML comments, aborting!")
  48. exit(1)
  49. newFileStr = fileStr[:depsStart.start() - 1] + "\n" + asmXml + "\n" + fileStr[depsEnd.end() + 1:]
  50. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "w") as xmlFile:
  51. print("Writing Assembly references")
  52. xmlFile.write(newFileStr)
  53. # print(newFileStr)