-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModDatabaseUpdate.cs
More file actions
76 lines (65 loc) · 2.22 KB
/
ModDatabaseUpdate.cs
File metadata and controls
76 lines (65 loc) · 2.22 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
struct ModDatabaseUpdate
{
public DateTime Time;
public string Repo;
public int DownloadCount;
public int DownloadCountChange;
public ModDatabaseUpdate(string[] lines, DateTime time)
{
Time = time;
if (!lines.Any(x => x.StartsWith(" \"repo\":")))
{
if (lines.Any(x => x.StartsWith("+ \"repo\":")))
{
Repo = lines.First(x => x.StartsWith("+ \"repo\":"))[16..^2];
}
else if (lines.Any(x => x.StartsWith("- \"repo\":")))
{
Repo = lines.First(x => x.StartsWith("- \"repo\":"))[16..^2];
}
else if (lines.Any(x => x.StartsWith(" \"installerDownloadUrl\":")))
{
var installerDownloadUrl = lines.First(x => x.StartsWith(" \"installerDownloadUrl\":"))[30..^2];
var indexOf5thSlash = Core.GetNthIndex(installerDownloadUrl, '/', 5);
Repo = installerDownloadUrl[..indexOf5thSlash];
}
else
{
// what
Repo = "IGNORE_ENTRY";
DownloadCount = 0;
DownloadCountChange = 0;
return;
}
}
else
{
Repo = lines.First(x => x.StartsWith(" \"repo\":"))[16..^2];
}
DownloadCount = 0;
var removedCount = 0;
if (lines.Any(x => x.StartsWith("+ \"downloadCount\":")))
{
var downloadCount = lines.First(x => x.StartsWith("+ \"downloadCount\":"));
DownloadCount = downloadCount[^1] == ',' ? int.Parse(downloadCount[24..^1]) : int.Parse(downloadCount[24..]);
var removedCount_temp = lines.FirstOrDefault(x => x.StartsWith("- \"downloadCount\":"));
removedCount = removedCount_temp == null
? 0
: removedCount_temp[^1] == ','
? int.Parse(removedCount_temp[24..^1])
: int.Parse(removedCount_temp[24..]);
}
else if (lines.Any(x => x.StartsWith("+ \"downloadCount\":")))
{
var downloadCount = lines.First(x => x.StartsWith("+ \"downloadCount\":"));
DownloadCount = downloadCount[^1] == ',' ? int.Parse(downloadCount[22..^1]) : int.Parse(downloadCount[22..]);
var removedCount_temp = lines.FirstOrDefault(x => x.StartsWith("- \"downloadCount\":"));
removedCount = removedCount_temp == null
? 0
: removedCount_temp[^1] == ','
? int.Parse(removedCount_temp[22..^1])
: int.Parse(removedCount_temp[22..]);
}
DownloadCountChange = DownloadCount - removedCount;
}
}