From 5acd3b393584ac864d26548c401d837b8acba103 Mon Sep 17 00:00:00 2001 From: CSiCoAlm Date: Wed, 27 Oct 2021 17:01:15 +0200 Subject: [PATCH] - Autocommit - 2021/10/27 17:01:14 --- Doc/A69WD.org | 14 +++++++- Src/A69WD/General/cTools.cs | 10 ++++-- Src/A69WD/Net/cA69Engine.cs | 47 +++++++++++++++++++++++++ Src/A69WD/Net/frmDownloader.Designer.cs | 31 +++++++++------- Src/A69WD/Net/frmDownloader.cs | 20 ++++++++--- Src/A69WD/Net/frmDownloader.resx | 3 ++ 6 files changed, 106 insertions(+), 19 deletions(-) diff --git a/Doc/A69WD.org b/Doc/A69WD.org index cac56ac..8e7008b 100644 --- a/Doc/A69WD.org +++ b/Doc/A69WD.org @@ -35,7 +35,19 @@ velocemente ai link fatti, e a quelli da fare - Update :: indica la data in cui eseguo l'ultimo update al record -* TODO Vrs 0.1.5.0 :DONE: +* TODO Vrs 0.1.5.2 :WORKING: +Modifica per: +- Inserire l'importazione di link (solo Idx o Rac di A69) da file di testo +- Correggere l'importazione ed esportazione degli elenchi dal DB + + +* Vrs 0.1.5.1 :DONE: +Breve modifica per: +- Corretto formato del numero di versione +- Razionalizzato il messaggio di update dell'engine. +- Inserito gli aggiornamenti dell'engine sul log degli eventi + +* Vrs 0.1.5.0 :DONE: Applicazione che serializza i dati su SQLite, ma continua ad usare liste internamente per recuperare il codice già fatto. diff --git a/Src/A69WD/General/cTools.cs b/Src/A69WD/General/cTools.cs index 880603a..ae4d08f 100644 --- a/Src/A69WD/General/cTools.cs +++ b/Src/A69WD/General/cTools.cs @@ -56,13 +56,19 @@ namespace A69WD { /// Nome completo del file da creare/sovrascrivere /// StringBuilder con il testo da riportare nel file public static void WriteTextFile(string FullFileName, StringBuilder Text) { - System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.UTF8); + //System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.UTF8); + //sw.Write(Text.ToString()); + //sw.Flush(); + //sw.Close(); + WriteTextFile(FullFileName, Text, Encoding.UTF8); + } + public static void WriteTextFile(string FullFileName, StringBuilder Text, Encoding code) { + System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, code); sw.Write(Text.ToString()); sw.Flush(); sw.Close(); } - /// /// Metodo che legge un testo da file (UTF8) /// diff --git a/Src/A69WD/Net/cA69Engine.cs b/Src/A69WD/Net/cA69Engine.cs index 6211330..0401c72 100644 --- a/Src/A69WD/Net/cA69Engine.cs +++ b/Src/A69WD/Net/cA69Engine.cs @@ -98,6 +98,50 @@ namespace A69WD { state = EngineStatusEnum.Stopping; } + public int ImportLinkFromFile(string SrcFilePath) { + int res = 0; + try { + if (File.Exists(SrcFilePath)) { + StreamReader sr = new StreamReader(SrcFilePath, Encoding.UTF8); + string row = sr.ReadLine().Trim(); + while (row != null) { + // verifico che non sia un commento: + if (!(row.StartsWith("#") || row.StartsWith("//"))) { + // Se link nuovo: + if (!allLinks.Contains(row)) { + // Link nuovo, mi comporto di conseguenza alla tipologia: + if (IsRacLink(row)) { + // Link ad un racconto + allLinks.Add(row); + if (downRac) { toDownload.Add(row); } + racLinks.Add(row); + res++; + } else { + if (IsIdxLink(row)) { + // Link ad un indice + allLinks.Add(row); + toDownload.Add(row); + res++; + } else { + // Link non riconosciuto, lo scarto + ; + } + } + } + } + //Read the next line + row = sr.ReadLine(); + } + } + + } catch (Exception ex) { + Logger.Log(new object[] { "Error Code: DB07403", "Errore in ImportLinkFromFile()", ex }); + if (res > 0) res = -1 * res; + } + return res; + } + + #endregion @@ -135,6 +179,7 @@ namespace A69WD { + private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { object obj = new Object(); lock (obj) { @@ -153,6 +198,8 @@ namespace A69WD { sb = new StringBuilder(); sb.Append(wb.DocumentText); string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(link)); + cTools.WriteTextFile(fn, sb, Encoding.GetEncoding(wb.Document.Encoding)); + fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, "UTF8_" +GetFileName(link)); cTools.WriteTextFile(fn, sb); } diff --git a/Src/A69WD/Net/frmDownloader.Designer.cs b/Src/A69WD/Net/frmDownloader.Designer.cs index 02a622d..e1f5ebe 100644 --- a/Src/A69WD/Net/frmDownloader.Designer.cs +++ b/Src/A69WD/Net/frmDownloader.Designer.cs @@ -28,7 +28,8 @@ this.btnDownloadAll = new System.Windows.Forms.Button(); this.lblST = new System.Windows.Forms.Label(); this.wb1 = new System.Windows.Forms.WebBrowser(); - this.btnDownloadLink = new System.Windows.Forms.Button(); + this.btnImportLinks = new System.Windows.Forms.Button(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.SuspendLayout(); // // btnClose @@ -53,7 +54,7 @@ // // btnDownloadAll // - this.btnDownloadAll.Location = new System.Drawing.Point(135, 12); + this.btnDownloadAll.Location = new System.Drawing.Point(12, 12); this.btnDownloadAll.Name = "btnDownloadAll"; this.btnDownloadAll.Size = new System.Drawing.Size(117, 33); this.btnDownloadAll.TabIndex = 11; @@ -84,25 +85,30 @@ this.wb1.TabStop = false; this.wb1.Visible = false; // - // btnDownloadLink + // btnImportLinks // - this.btnDownloadLink.Location = new System.Drawing.Point(12, 12); - this.btnDownloadLink.Name = "btnDownloadLink"; - this.btnDownloadLink.Size = new System.Drawing.Size(117, 33); - this.btnDownloadLink.TabIndex = 10; - this.btnDownloadLink.Text = "Download only Link"; - this.btnDownloadLink.UseVisualStyleBackColor = true; - this.btnDownloadLink.Click += new System.EventHandler(this.btnDownloadLink_Click); + this.btnImportLinks.Location = new System.Drawing.Point(135, 12); + this.btnImportLinks.Name = "btnImportLinks"; + this.btnImportLinks.Size = new System.Drawing.Size(117, 33); + this.btnImportLinks.TabIndex = 15; + this.btnImportLinks.Text = "Import Links"; + this.btnImportLinks.UseVisualStyleBackColor = true; + this.btnImportLinks.Click += new System.EventHandler(this.btnImportLinks_Click); + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.Filter = "File Testo|*.tes|Tutti i file|*.*"; // // frmDownloader // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(504, 74); + this.Controls.Add(this.btnImportLinks); this.Controls.Add(this.btnClose); this.Controls.Add(this.btnHide); this.Controls.Add(this.btnDownloadAll); - this.Controls.Add(this.btnDownloadLink); this.Controls.Add(this.lblST); this.Controls.Add(this.wb1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; @@ -118,6 +124,7 @@ private System.Windows.Forms.Button btnDownloadAll; private System.Windows.Forms.Label lblST; private System.Windows.Forms.WebBrowser wb1; - private System.Windows.Forms.Button btnDownloadLink; + private System.Windows.Forms.Button btnImportLinks; + private System.Windows.Forms.OpenFileDialog openFileDialog1; } } \ No newline at end of file diff --git a/Src/A69WD/Net/frmDownloader.cs b/Src/A69WD/Net/frmDownloader.cs index 3f158d0..96b437f 100644 --- a/Src/A69WD/Net/frmDownloader.cs +++ b/Src/A69WD/Net/frmDownloader.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -21,8 +22,16 @@ namespace A69WD { cA69Engine engine = null; - private void btnDownloadLink_Click(object sender, EventArgs e) { - engine.Start(false); + /// + /// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già + /// + 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) { @@ -30,7 +39,9 @@ namespace A69WD { } private void btnHide_Click(object sender, EventArgs e) { - this.Hide(); + 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) { @@ -63,9 +74,10 @@ namespace A69WD { } } - #endregion + #endregion + }//class frmDownloader }//namespace A69WD diff --git a/Src/A69WD/Net/frmDownloader.resx b/Src/A69WD/Net/frmDownloader.resx index 29dcb1b..3a7d671 100644 --- a/Src/A69WD/Net/frmDownloader.resx +++ b/Src/A69WD/Net/frmDownloader.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file