205 lines
9.3 KiB
C#
205 lines
9.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using System.Net;
|
|
using static System.Windows.Forms.LinkLabel;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace A69WD {
|
|
|
|
public partial class frmDownloader : Form {
|
|
|
|
|
|
public frmDownloader() {
|
|
InitializeComponent();
|
|
this.Text = String.Format("A69WD - Dowloader Testi Vrs {0}", cTools.AssemblyVersion);
|
|
engine = new cA69Engine(this.wb1);
|
|
engine.Updating += Engine_Updating;
|
|
engine2 = new cA69Engine2();
|
|
engine2.Updating += Engine_Updating;
|
|
engine3 = new cA69Engine3();
|
|
engine3.Updating += Engine_Updating;
|
|
}
|
|
|
|
cA69Engine engine = null;
|
|
cA69Engine2 engine2 = null;
|
|
cA69Engine3 engine3 = null;
|
|
|
|
|
|
/// <summary>
|
|
/// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già
|
|
/// </summary>
|
|
private void btnImportLinks_Click(object sender, EventArgs e) {
|
|
// Chiedo il file di testo da caricare
|
|
lblST.Text = " ";
|
|
this.openFileDialog1.InitialDirectory = Cfg.Settings.PathApplicationRoot;
|
|
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
|
|
lblST.Text = string.Format("Importati {0} link", engine.ImportLinkFromFile(openFileDialog1.FileNames[0]));
|
|
}
|
|
}
|
|
|
|
private void btnDownloadAll_Click(object sender, EventArgs e) {
|
|
engine.Start(true);
|
|
}
|
|
|
|
private void btnShowLog_Click(object sender, EventArgs e) {
|
|
cTools.ShowOnNotepad(Cfg.Settings.PathFileLogs);
|
|
}
|
|
|
|
private void btnHide_Click(object sender, EventArgs e) {
|
|
if (MessageBox.Show("Metodo ancora da terminare, la finestra non sarà più visibile, killare il processo", "ATTENZIONE", MessageBoxButtons.OKCancel) == DialogResult.OK){
|
|
this.Hide();
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e) { if (engine.Stop()) this.Close(); }
|
|
|
|
#region Gestione eventi dal engine
|
|
|
|
private void Engine_Updating(object sender, EngineEventArgs e) { EngineUpdatingStatus(e.Message, e.NTot, e.NtoDown, e.NDown); }
|
|
|
|
delegate void EngineUpdatingStatusCallback(string Message, int NTot, int NtoDown, int NDown);
|
|
private void EngineUpdatingStatus(string Message, int NTot, int NtoDown, int NDown) {
|
|
try {
|
|
// InvokeRequired required compares the thread ID of the
|
|
// calling thread to the thread ID of the creating thread.
|
|
// If these threads are different, it returns true.
|
|
if (lblST.InvokeRequired) {
|
|
EngineUpdatingStatusCallback callBack = new EngineUpdatingStatusCallback(EngineUpdatingStatus);
|
|
this.Invoke(callBack, new object[] { Message, NTot, NtoDown, NDown });
|
|
} else {
|
|
lblST.Text = string.Format("{4} - {3} | {2} | {1} - {0}", Message, NTot, NtoDown, NDown, DateTime.Now.ToString("HH:mm:ss"));
|
|
Logger.Information(lblST.Text);
|
|
}
|
|
} catch (Exception ex) {
|
|
Logger.Log(new object[] { "Error Code: ER05553", "Errore in EngineUpdatingStatus():", ex });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
private void btnDownloadAll2_Click(object sender, EventArgs e) { engine.Start(false); }
|
|
|
|
|
|
|
|
|
|
#region Test WEBCLIENT
|
|
|
|
private void btnTest_Click(object sender, EventArgs e) {
|
|
////Run download file with multiple thread
|
|
//string url = "https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=103";
|
|
//if (!string.IsNullOrEmpty(url)) {
|
|
// Thread thread = new Thread(() =>
|
|
// {
|
|
// Uri uri = new Uri(url);
|
|
// //string fileName = System.IO.Path.GetFileName(uri.AbsolutePath);
|
|
// string fileName = System.IO.Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"));
|
|
// client.DownloadFileAsync(uri, @"C:\VMS\Prj\C#\A69WD\Test\Txt\Src\_A69_genere_altro_103.html");
|
|
// });
|
|
// thread.Start();
|
|
//}
|
|
|
|
string url = "https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=98";
|
|
string fileName = @"C:\VMS\Prj\C#\A69WD\Test\Logs\_A69_genere_altro_98.html";
|
|
|
|
//// Test 1: Questo dà errore:
|
|
//WebClient client;
|
|
//client = new WebClient();
|
|
//client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
|
//client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
|
////client.DownloadFile(url, fileName);
|
|
//StringBuilder sb = new StringBuilder(client.DownloadString(url));
|
|
//cTools.WriteTextFile(fileName, sb);
|
|
//// Test 1
|
|
|
|
// // Test 2: OK
|
|
// WebClient client = new WebClient();
|
|
// //client.Headers["User-Agent"] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
|
|
// client.Encoding = Encoding.ASCII;
|
|
// client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
|
// client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
|
// //client.Headers.Add("Accept-Encoding", "gzip, deflate, br");
|
|
// //client.Headers.Add("Connection", "keep-alive");
|
|
// client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
|
// client.Headers.Add("DNT", "1");
|
|
// client.Headers.Add("TE", "Trailers");
|
|
// client.DownloadFile(new Uri(url), fileName);
|
|
// // Test 2: OK
|
|
|
|
// Test 3: OK
|
|
using (WebClient client = new WebClient()) {
|
|
for (int i = 90; i < 110; i++) {
|
|
url = "https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=" + i.ToString();
|
|
fileName = @"C:\VMS\Prj\C#\A69WD\Test\Logs\_A69_genere_altro_" + i.ToString() + ".html";
|
|
client.Encoding = Encoding.ASCII;
|
|
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
|
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
|
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
|
client.Headers.Add("DNT", "1");
|
|
client.Headers.Add("TE", "Trailers");
|
|
client.DownloadFile(new Uri(url), fileName);
|
|
}
|
|
}
|
|
// Test 3: OK
|
|
|
|
|
|
}
|
|
|
|
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) {
|
|
MessageBox.Show("Download complete !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) {
|
|
////Update progress bar & label
|
|
//Invoke(new MethodInvoker(delegate () {
|
|
// progressBar.Minimum = 0;
|
|
// double receive = double.Parse(e.BytesReceived.ToString());
|
|
// double total = double.Parse(e.TotalBytesToReceive.ToString());
|
|
// double percentage = receive / total * 100;
|
|
// lblStatus.Text = $"Downloaded {string.Format("{0:0.##}", percentage)}%";
|
|
// progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
|
|
//}));
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Test ENGINE2
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
|
|
engine2.Start(true);
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
private void button2_Click(object sender, EventArgs e) {
|
|
engine3.Start(true);
|
|
}
|
|
|
|
|
|
|
|
}//class frmDownloader
|
|
}//namespace A69WD
|