-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUnityArchiveParser.cs
99 lines (79 loc) · 3.18 KB
/
UnityArchiveParser.cs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using AssetRipper.Primitives;
using n1685.Utilities.Extensions;
namespace UDGB
{
internal class UnityArchiveParser
{
private const string URL = "https://unity.com/releases/editor/archive";
private const string URL_WHATS_NEW = "https://unity.com/releases/editor/whats-new/";
private const string URL_DOWNLOAD = "https://download.unity3d.com/download_unity/";
internal static UnityVersion[]? GetVersions()
{
string? pageSource = Program.webClient.TryGetString(URL);
if (string.IsNullOrEmpty(pageSource))
return null;
string target = "unityHubDeepLink\\\":\\\"unityhub://";
HashSet<UnityVersion> returnVal = new();
int next;
while ((next = pageSource.IndexOf(target)) != -1)
{
pageSource = pageSource.Substring(next + target.Length);
int end = pageSource.IndexOf("\\\"");
if (end == -1)
continue;
string url = pageSource.Substring(0, end);
string[] parts = url.Split('/');
string foundVersion = parts[0];
//string hash = parts[1];
UnityVersion version = UnityVersion.Parse(foundVersion);
if (returnVal.Contains(version))
continue;
returnVal.Add(version);
}
return returnVal.ToArray();
}
internal enum ePlatform
{
ALL,
WINDOWS,
MACOS,
LINUX
}
internal static string[]? GetDownloads(UnityVersion version,
ePlatform platform = ePlatform.ALL)
{
string? pageSource = Program.webClient.TryGetString($"{URL_WHATS_NEW}{version}#installs");
if (string.IsNullOrEmpty(pageSource))
pageSource = Program.webClient.TryGetString($"{URL_WHATS_NEW}{version.ToStringWithoutType()}#installs");
if (string.IsNullOrEmpty(pageSource))
return null;
HashSet<string> returnVal = new();
string target = $"\"{URL_DOWNLOAD}";
int next;
while ((next = pageSource.IndexOf(target)) != -1)
{
pageSource = pageSource.Substring(next + target.Length);
int end = pageSource.IndexOf("\"");
if (end == -1)
continue;
string url = $"{URL_DOWNLOAD}{pageSource.Substring(0, end)}";
if (url.EndsWith("\\"))
url = url.Substring(0, url.Length - 1);
if (platform != ePlatform.ALL)
{
if (platform == ePlatform.WINDOWS
&& !url.EndsWith(".exe"))
continue;
if (platform == ePlatform.MACOS
&& !url.EndsWith(".pkg"))
continue;
if (platform == ePlatform.LINUX
&& !url.EndsWith(".tar.gz"))
continue;
}
returnVal.Add(url);
}
return returnVal.ToArray();
}
}
}