download-gameinput-headers.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3
  2. import argparse
  3. import logging
  4. from pathlib import Path
  5. import urllib.request
  6. logger = logging.getLogger(__name__)
  7. def download_headers(tag: str, lowercase: bool, output: Path):
  8. base_url = f"https://raw.githubusercontent.com/microsoftconnect/GameInput/refs/tags/{tag}/"
  9. url_relpaths = (
  10. "include/GameInput.h",
  11. "include/v0/GameInput.h",
  12. "include/v1/GameInput.h",
  13. "include/v2/GameInput.h",
  14. )
  15. remove_prefix = "include/"
  16. for url_relpath in url_relpaths:
  17. url = base_url + url_relpath
  18. local_relpath = url_relpath.removeprefix(remove_prefix)
  19. if lowercase:
  20. local_relpath = local_relpath.lower()
  21. local_path = output / local_relpath
  22. local_dirpath = local_path.parent
  23. local_dirpath.mkdir(parents=False, exist_ok=True)
  24. logger.info("Downloading %s to %s...", url, local_path)
  25. urllib.request.urlretrieve(url, local_path)
  26. logger.info("... done")
  27. def main():
  28. logging.basicConfig(level=logging.INFO)
  29. parser = argparse.ArgumentParser(description="Download Microsoft.GameInput headers", allow_abbrev=False)
  30. parser.add_argument("--version", required=True, help="GameInput release tag (see https://github.com/microsoftconnect/GameInput/tags)")
  31. parser.add_argument("--no-lowercase", action="store_false", dest="lowercase", help="Don't lowercase downloaded headers")
  32. parser.add_argument("-o", "--output", type=Path, default=Path.cwd(), help="Headers will be stored here (subdirectories created as ")
  33. args = parser.parse_args()
  34. download_headers(tag=args.version, lowercase=args.lowercase, output=args.output)
  35. if __name__ == "__main__":
  36. raise SystemExit(main())