forked from unitycoder/UnityLauncherPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetUnityUpdates.cs
More file actions
83 lines (73 loc) · 2.81 KB
/
GetUnityUpdates.cs
File metadata and controls
83 lines (73 loc) · 2.81 KB
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
namespace UnityLauncherPro
{
public static class GetUnityUpdates
{
static bool isDownloadingUnityList = false;
static readonly string unityVersionsURL = @"http://symbolserver.unity3d.com/000Admin/history.txt";
public static async Task<string> Scan()
{
if (isDownloadingUnityList == true)
{
Console.WriteLine("We are already downloading ...");
return null;
}
isDownloadingUnityList = true;
//SetStatus("Downloading list of Unity versions ...");
string result = null;
// download list of Unity versions
using (WebClient webClient = new WebClient())
{
Task<string> downloadStringTask = webClient.DownloadStringTaskAsync(new Uri(unityVersionsURL));
try
{
result = await downloadStringTask;
}
catch (WebException)
{
Console.WriteLine("It's a web exception");
}
catch (Exception)
{
Console.WriteLine("It's not a web exception");
}
isDownloadingUnityList = false;
}
return result;
}
public static Updates[] Parse(string items)
{
isDownloadingUnityList = false;
//SetStatus("Downloading list of Unity versions ... done");
var receivedList = items.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
if (receivedList == null && receivedList.Length < 1) return null;
Array.Reverse(receivedList);
var releases = new Dictionary<string, Updates>();
// parse into data
string prevVersion = null;
for (int i = 0, len = receivedList.Length; i < len; i++)
{
var row = receivedList[i].Split(',');
var versionTemp = row[6].Trim('"');
if (versionTemp.Length < 1) continue;
if (prevVersion == versionTemp) continue;
if (releases.ContainsKey(versionTemp) == false)
{
var u = new Updates();
u.ReleaseDate = DateTime.ParseExact(row[3], "MM/dd/yyyy", CultureInfo.InvariantCulture);
u.Version = versionTemp;
releases.Add(versionTemp, u);
}
prevVersion = versionTemp;
}
// convert to array
var results = new Updates[releases.Count];
releases.Values.CopyTo(results, 0);
return results;
}
}
}