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.

54 lines
2.2KB

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