forked from space-wizards/SS14.Launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_net_runtime.py
executable file
·78 lines (57 loc) · 2.57 KB
/
download_net_runtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
import os
import sys
import urllib.request
import tarfile
import zipfile
import shutil
from typing import List, Optional
PLATFORM_WINDOWS = "windows"
PLATFORM_LINUX = "linux"
PLATFORM_MACOS = "mac"
DOTNET_RUNTIME_VERSION = "7.0.3"
DOTNET_RUNTIME_DOWNLOADS = {
PLATFORM_LINUX: "https://download.visualstudio.microsoft.com/download/pr/2431d5ac-f5db-4bb1-bcf0-4a2d9725d4e4/1b0747add72af919754509f83ad08660/dotnet-runtime-7.0.3-linux-x64.tar.gz",
PLATFORM_WINDOWS: "https://download.visualstudio.microsoft.com/download/pr/e30129ab-4e46-42af-90a9-a5b597b06746/3e9993907f00eaba9da4a8d9ed168657/dotnet-runtime-7.0.3-win-x64.zip",
PLATFORM_MACOS: "https://download.visualstudio.microsoft.com/download/pr/c8f49e77-4d55-4a33-aa87-ddc034be61a2/77a50b1726446bee5a3a4dc6573568e2/dotnet-runtime-7.0.3-osx-x64.tar.gz"
}
p = os.path.join
def main() -> None:
update_netcore_runtime(sys.argv[1:])
def update_netcore_runtime(platforms: List[str]) -> None:
runtime_cache = p("Dependencies/dotnet")
version_file_path = p(runtime_cache, "VERSION")
# Check if current version is fine.
current_version: Optional[str]
try:
with open(version_file_path, "r") as f:
current_version = f.read().strip()
except FileNotFoundError:
current_version = None
if current_version != DOTNET_RUNTIME_VERSION and os.path.exists(runtime_cache):
print("Cached Release .NET Core Runtime out of date/nonexistant, downloading new one..")
shutil.rmtree(runtime_cache)
os.makedirs(runtime_cache, exist_ok=True)
with open(version_file_path, "w") as f:
f.write(DOTNET_RUNTIME_VERSION)
# Download missing runtimes if necessary.
for platform in platforms:
platform_runtime_cache = p(runtime_cache, platform)
if not os.path.exists(platform_runtime_cache):
os.mkdir(platform_runtime_cache)
download_platform_runtime(platform_runtime_cache, platform)
def download_platform_runtime(dir: str, platform: str) -> None:
print(f"Downloading .NET Core Runtime for platform {platform}.")
download_file = p(dir, "download.tmp")
download_url = DOTNET_RUNTIME_DOWNLOADS[platform]
urllib.request.urlretrieve(download_url, download_file)
if download_url.endswith(".tar.gz"):
# this is a tar gz.
with tarfile.open(download_file, "r:gz") as tar:
tar.extractall(dir)
elif download_url.endswith(".zip"):
with zipfile.ZipFile(download_file) as zipF:
zipF.extractall(dir)
os.remove(download_file)
if __name__ == "__main__":
main()