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.

56 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)\."
  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:
  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 "".join(result)
  24. #return "<!--Start Dependencies-->\n <ItemGroup>\n" + "".join(result) + " </ItemGroup>\n<!--End Dependencies-->"
  25. if __name__ == "__main__":
  26. parser = argparse.ArgumentParser(description="Generate GamecraftModdingAPI.csproj")
  27. # TODO (maybe?): add params for custom csproj read and write locations
  28. args = parser.parse_args()
  29. print("Building Assembly references")
  30. asmXml = buildReferencesXml("../ref/Gamecraft_Data/Managed")
  31. print(asmXml)
  32. with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "r") as xmlFile:
  33. print("Parsing GamecraftModdingAPI.csproj")
  34. fileStr = xmlFile.read()
  35. print(fileStr)
  36. depsStart = re.search(r"\<!--\s*Start\s+Dependencies\s*--\>", fileStr)
  37. depsEnd = re.search(r"\<!--\s*End\s+Dependencies\s*--\>", fileStr)
  38. if depsStart is None or depsEnd is None:
  39. print("Unable to find dependency XML comments, aborting!")
  40. exit(1)
  41. newFileStr = fileStr[:depsStart.end()] + "\n" + asmXml + "\n" + fileStr[depsEnd.start():]
  42. with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "w") as xmlFile:
  43. print("Writing Assembly references (not)")
  44. #xmlFile.seek(0)
  45. xmlFile.write(newFileStr)
  46. print(newFileStr)