Example #1
0
        private void BtnLocalizar_Click(object sender, EventArgs e)
        {
            string pattern = txtTermo.Text;
            FileInfo f = null;
            if (pattern == String.Empty || txtDir.Text == String.Empty)
            {
                MessageBox.Show("É necessário selecionar o diretório e termo procurado.", "Aviso");
                return;
            }
            if (!Directory.Exists(txtDir.Text))
            {
                MessageBox.Show("Este é um diretório inválido.", "Aviso");
                return;
            }
            if (cbxSearchWholeWord.Checked)
                txtTermo.Text = Search.RemoveRegExSpecialChars(txtTermo.Text);

            string path = txtDir.Text;
            File.WriteAllText("Localiza.cfg", txtDir.Text);
            dg.RowCount = 1;
            for(int i=0; i<dg.ColumnCount; ++i)
                dg[i, 0].Value = "";
            Cursor = Cursors.WaitCursor;
            s = new Search(pattern, path, cbxCaseSensitive.Checked,cbxSearchBinaryFiles.Checked, cbxSearchWholeWord.Checked,
                           cbxUseRegularExpressions.Checked, cbxAlsoSearchInFilenames.Checked, cbxOnlySearchInFileNames.Checked, cbxDecodeHtml.Checked);
            statusStrip.Items[0].Text = "Favor aguardar...";
            Application.DoEvents();
            s.StartSearch();

            for (int y = 0; y < s.ResultLst.Count; ++y)
            {
                f = new FileInfo(s.ResultLst[y].Filename);
                dg[0, y].Value = Fcn.FileName(s.ResultLst[y].Filename);
                dg[1, y].Value = Fcn.FileName(s.ResultLst[y].Results);
                dg[2, y].Value = s.ResultLst[y].Filename;
                dg[3, y].Value = Fcn.Extension(s.ResultLst[y].Filename);
                dg[4, y].Value = File.GetLastWriteTime(s.ResultLst[y].Filename);
                dg[5, y].Value = f.Length.ToString();
                if (s.ResultLst[y].Encoding != null)
                    dg[6, y].Value = s.ResultLst[y].Encoding.EncodingName;
                else
                    dg[6, y].Value = "<Desconhecida>";
                dg.RowCount++;
            }
            dg.RowCount--;
            Cursor = Cursors.Default;
            statusStrip.Items[0].Text = "Padrão presente em " + s.ResultLst.Count + " arquivo(s), de um total de " + s.FileLst.Count + " arquivos. Tempo decorrido ";
            if (s.ElapsedSpan.Seconds < 1)
                statusStrip.Items[0].Text += s.ElapsedSpan.Milliseconds + " milissegundos.";
            else
                if (s.ElapsedSpan.Minutes < 1)
                    statusStrip.Items[0].Text += s.ElapsedSpan.Seconds + " segundo(s) e " + s.ElapsedSpan.Milliseconds + " milissegundos.";
                else
                    statusStrip.Items[0].Text += (s.ElapsedSpan.Seconds / 60) + " minutos(s) e " + (s.ElapsedSpan.Seconds%60) + " segundo(s).";
            MessageBox.Show("Terminado");
        }
Example #2
0
        private void BtnLocalizar_Click(object sender, EventArgs e)
        {
            string pattern = txtTermo.Text;
            if (pattern == String.Empty || txtDir.Text == String.Empty)
            {
                MessageBox.Show("É necessário selecionar o diretório e termo procurado.", "Aviso");
                return;
            }
            if (!Directory.Exists(txtDir.Text))
            {
                MessageBox.Show("Este é um diretório inválido.", "Aviso");
                return;
            }

            string path = txtDir.Text;
            File.WriteAllText("Localiza.cfg", txtDir.Text);
            dg.RowCount = 1;
            for(int i=0; i<dg.ColumnCount; ++i)
                dg[i, 0].Value = "";
            Cursor = Cursors.WaitCursor;
            s = new Search(pattern, path, cbxCaseSensitive.Checked, false, cbxSearchWholeWord.Checked);
            statusStrip.Items[0].Text = "Favor aguardar...";
            Application.DoEvents();
            s.StartSearch();

            for (int y = 0; y < s.ResultLst.Count; ++y)
            {
                dg[0, y].Value = Fcn.FileName(s.ResultLst[y].Filename);
                dg[1, y].Value = s.ResultLst[y].Filename;
                dg[2, y].Value = Fcn.Extension(s.ResultLst[y].Filename);
                dg[3, y].Value = File.GetLastWriteTime(s.ResultLst[y].Filename);
                dg.RowCount++;
            }
            dg.RowCount--;
            //statusStrip.Items["lblElapsedTime"].Text = s.ElapsedTime.ToString();
            Cursor = Cursors.Default;
            statusStrip.Items[0].Text = "Padrão presente em " + s.ResultLst.Count + " arquivo(s), tempo decorrido ";
            if (s.ElapsedSpan.Seconds < 1)
                statusStrip.Items[0].Text += s.ElapsedSpan.Milliseconds + " milissegundos.";
            else
                if (s.ElapsedSpan.Minutes < 1)
                    //statusStrip.Items[0].Text += s.ElapsedSpan.Seconds + " segundo(s).";
                    statusStrip.Items[0].Text += s.ElapsedSpan.Seconds + " segundo(s) e " + s.ElapsedSpan.Milliseconds + " milissegundos.";
                else
                    statusStrip.Items[0].Text += s.ElapsedSpan.Minutes + " minutos(s) e " + (s.ElapsedSpan.Seconds%60) + " segundo(s).";
            s = null;
            GC.Collect();
            MessageBox.Show("Terminado");
        }