@ -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 ( 1 0 0 ) ;
await fillChildNode ( itemsNode , item . Replace ( curDirTextBox . Text , "" ) ) ;
List < string > fileLines = new List < string > ( ) ;
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 < string > getFileContents ( string fileUrl )
{
List < string > lines = new List < string > ( ) ;
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 < string > 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 ;