hctgettaef.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import urllib.request
  2. import os
  3. import ssl
  4. import zipfile
  5. url = "https://github.com/Microsoft/WinObjC/raw/develop/deps/prebuilt/nuget/taef.redist.wlk.1.0.170206001-nativetargets.nupkg"
  6. zipfile_name = os.path.join(os.environ['TEMP'], "taef.redist.wlk.1.0.170206001-nativetargets.nupkg.zip")
  7. src_dir = os.environ['HLSL_SRC_DIR']
  8. taef_dir = os.path.join(src_dir, "external", "taef")
  9. if not os.path.isdir(taef_dir):
  10. os.makedirs(taef_dir)
  11. try:
  12. ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
  13. response = urllib.request.urlopen(url, context=ctx)
  14. f = open(zipfile_name, 'wb')
  15. f.write(response.read())
  16. f.close()
  17. except:
  18. print("Unable to read file with urllib, trying via powershell...")
  19. from subprocess import check_call
  20. cmd = ""
  21. cmd += "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;"
  22. cmd += "(new-object System.Net.WebClient).DownloadFile('" + url + "', '" + zipfile_name + "')"
  23. check_call(['powershell.exe', '-Command', cmd])
  24. z = zipfile.ZipFile(zipfile_name)
  25. z.extractall(taef_dir)
  26. z.close()