-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
197 lines (167 loc) · 7.99 KB
/
Form1.cs
File metadata and controls
197 lines (167 loc) · 7.99 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using HtmlAgilityPack;
using Newtonsoft.Json;
namespace Updates
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/*private void UpdatePHP()
{
string phpBaseUrl = "https://windows.php.net";
string phpReleasesUrl = phpBaseUrl + "/downloads/releases/";
string apacheBaseUrl = "https://www.apachelounge.com";
string apacheUrl = apacheBaseUrl + "/download/";
string jsonFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "download.json");
var downloads = new List<DownloadEntry>();
// ======================= PHP =======================
var phpWeb = new HtmlWeb();
var phpDoc = phpWeb.Load(phpReleasesUrl);
var phpLinkNode = phpDoc.DocumentNode.SelectNodes("//a[@href]")
?.FirstOrDefault(node =>
{
var href = node.Attributes["href"].Value;
return href.EndsWith("-nts-Win32-vs17-x64.zip") &&
!href.Contains("debug", StringComparison.OrdinalIgnoreCase) &&
!href.Contains("devel", StringComparison.OrdinalIgnoreCase);
});
if (phpLinkNode != null)
{
string phpHref = phpLinkNode.Attributes["href"].Value;
string phpUrl = phpBaseUrl + phpHref;
string phpFilename = Path.GetFileName(phpHref);
downloads.Add(new DownloadEntry { Filename = phpFilename, Url = phpUrl });
}
// ======================= Apache =======================
var apacheWeb = new HtmlWeb();
var apacheDoc = apacheWeb.Load(apacheUrl);
var apacheLinkNode = apacheDoc.DocumentNode.SelectNodes("//a[@href]")
?.FirstOrDefault(node =>
{
var href = node.Attributes["href"].Value;
return href.EndsWith(".zip") && href.StartsWith("/download/VS17/binaries/httpd-");
});
if (apacheLinkNode != null)
{
string apacheHref = apacheLinkNode.Attributes["href"].Value;
string apacheFullUrl = apacheBaseUrl + apacheHref;
string apacheFilename = Path.GetFileName(apacheHref);
downloads.Add(new DownloadEntry { Filename = apacheFilename, Url = apacheFullUrl });
}
// ======================= Atualizar JSON =======================
List<DownloadEntry> existing = new();
if (File.Exists(jsonFilePath))
{
string json = File.ReadAllText(jsonFilePath);
existing = JsonSerializer.Deserialize<List<DownloadEntry>>(json) ?? new List<DownloadEntry>();
}
// Atualiza ou adiciona
foreach (var d in downloads)
{
var found = existing.FirstOrDefault(e => e.Filename.StartsWith("php") && d.Filename.StartsWith("php") ||
e.Filename.StartsWith("httpd") && d.Filename.StartsWith("httpd"));
if (found != null)
{
found.Filename = d.Filename;
found.Url = d.Url;
}
else
{
existing.Add(d);
}
}
// Salva o JSON atualizado
string finalJson = JsonSerializer.Serialize(existing, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(jsonFilePath, finalJson);
MessageBox.Show("JSON atualizado com PHP e Apache!");
}*/
private void AddFilesToJson()
{
string phpUrl = @"https://windows.php.net/downloads/releases/";
string apacheUrl = @"https://www.apachelounge.com/download/";
string nginxUrl = @"https://nginx.org/en/download.html"; // Página principal de download do Nginx
// Criando uma lista para armazenar as entradas de download
List<DownloadEntry> downloadEntries = new List<DownloadEntry>();
// PHP - Atualizar a versão PHP
var phpWeb = new HtmlWeb();
var phpDoc = phpWeb.Load(phpUrl);
var phpLinks = phpDoc.DocumentNode.SelectNodes("//a[@href]")
?.Where(node => node.Attributes["href"].Value.EndsWith("-nts-Win32-vs17-x64.zip") &&
!node.Attributes["href"].Value.Contains("debug") &&
!node.Attributes["href"].Value.Contains("devel"))
.ToList();
if (phpLinks != null && phpLinks.Count > 0)
{
foreach (var link in phpLinks)
{
string href = link.Attributes["href"].Value;
string version = href.Split('-')[1]; // ex: "8.4.6"
string fullLink = "https://windows.php.net" + href;
downloadEntries.Add(new DownloadEntry
{
Filename = "php-" + version + "-nts-Win32-vs17-x64.zip",
Url = fullLink
});
}
}
// Apache - Atualizar a versão Apache (Filtrar apenas "httpd" e evitar outros arquivos como módulos)
var apacheWeb = new HtmlWeb();
var apacheDoc = apacheWeb.Load(apacheUrl);
var apacheLinks = apacheDoc.DocumentNode.SelectNodes("//a[@href]")
?.Where(node => node.Attributes["href"].Value.Contains("httpd-") &&
node.Attributes["href"].Value.EndsWith("-win64-VS17.zip"))
.ToList();
if (apacheLinks != null && apacheLinks.Count > 0)
{
foreach (var link in apacheLinks)
{
string href = link.Attributes["href"].Value;
string filename = href.Split('/').Last();
string fullLink = "https://www.apachelounge.com" + href;
downloadEntries.Add(new DownloadEntry
{
Filename = filename,
Url = fullLink
});
}
}
var nginxWeb = new HtmlWeb();
var nginxDoc = nginxWeb.Load(nginxUrl);
// Encontra o primeiro link que contém '/download/nginx-', termina com '.zip' e
// o nó de texto pai contém 'Windows'
var latestNginxLinkNode = nginxDoc.DocumentNode.SelectNodes("//a[@href]")
?.Where(node => node.Attributes["href"].Value.Contains("/download/nginx-") &&
node.Attributes["href"].Value.EndsWith(".zip") &&
node.InnerText.Contains("Windows"))
.FirstOrDefault(); // Pegamos apenas o primeiro link encontrado
if (latestNginxLinkNode != null)
{
string href = latestNginxLinkNode.Attributes["href"].Value;
string fullLink = new Uri(new Uri(nginxUrl), href).AbsoluteUri; // Retorna a URL completa
downloadEntries.Add(new DownloadEntry
{
Filename = Path.GetFileName(href), // Nome do arquivo
Url = fullLink // URL completa
});
}
// Salvar o JSON com as versões mais recentes
string jsonPath = Path.Combine(Directory.GetCurrentDirectory(), "download.json");
string json = JsonConvert.SerializeObject(downloadEntries, Formatting.Indented);
File.WriteAllText(jsonPath, json);
//textBox1.Text = jsonPath;
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
public class DownloadEntry
{
public string? Filename { get; set; }
public string? Url { get; set; }
}
}