From bec7bfe0a612413e825c13f0796e7918ffeb4b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Tue, 2 Oct 2018 03:04:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=D1=8B=20getFileContents,=20isFileContainQuer?= =?UTF-8?q?y=20-=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D0=BE=D0=BB=D1=8F=D1=8E=D1=82=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B8=D1=82=D1=8C=20=D1=81=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=B8=D0=BC=D0=BE=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=8D=D1=82=D0=BE=20=D1=81=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=B8=D0=BC=D0=BE=D0=B5=20=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B5=20=D0=B8=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BE=D0=B9=20=D1=84=D1=80=D0=B0=D0=B7=D1=8B.=20buildRes?= =?UTF-8?q?ultTree=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= =?UTF-8?q?,=20=D1=83=D0=B4=D0=BE=D0=B2=D0=BB=D0=B5=D1=82=D0=B2=D0=BE?= =?UTF-8?q?=D1=80=D1=8F=D1=8E=D1=89=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=D0=BC?= =?UTF-8?q?=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F=D0=BC=20=D1=81?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fileFinder/MainForm.cs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/fileFinder/MainForm.cs b/fileFinder/MainForm.cs index 2059a63..e40ac46 100644 --- a/fileFinder/MainForm.cs +++ b/fileFinder/MainForm.cs @@ -68,8 +68,7 @@ namespace fileFinder } catch (Exception ex) { - var dialog = new ThreadExceptionDialog(ex); - dialog.ShowDialog(); + MessageBox.Show(ex.Message, "Поиск не удался!"); } int counter = 0; @@ -77,15 +76,51 @@ namespace fileFinder { while (controller.isPaused) Thread.Sleep(100); - await fillChildNode(itemsNode, item.Replace(curDirTextBox.Text, "")); + List fileLines = new List(); + try + { + fileLines = getFileContents(item); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка поиска внутри файла!"); + } + _report.progress = counter; _report.currentFileUrl = item; report.Report(_report); + + if ((fileLines.Count > 0) && (isFileContainQuery(fileLines, innerQueryTextBox.Text))) + await fillChildNode(itemsNode, item.Replace(curDirTextBox.Text, "")); } controller.stopTask(); return itemsNode; } + private List getFileContents (string fileUrl) + { + List lines = new List(); + FileStream fStream = new FileStream(fileUrl, FileMode.Open, FileAccess.Read); + using (StreamReader sReader = new StreamReader(fStream, Encoding.UTF8)) + { + string line; + while ((line = sReader.ReadLine()) != null) + lines.Add(line); + } + return lines; + } + + private bool isFileContainQuery (List fileLines, string query) + { + foreach (string line in fileLines) + { + if (line.IndexOf(query) != -1) + return true; + else break; + } + return false; + } + private void reportProgress(object sender, ProgressReportModel report) { infoLabel.Text = report.currentFileUrl;