@ -68,8 +68,7 @@ namespace fileFinder
}
}
catch ( Exception ex )
catch ( Exception ex )
{
{
var dialog = new ThreadExceptionDialog ( ex ) ;
MessageBox . Show ( ex . Message , "Поиск не удался!" ) ;
dialog . ShowDialog ( ) ;
}
}
int counter = 0 ;
int counter = 0 ;
@ -77,15 +76,51 @@ namespace fileFinder
{
{
while ( controller . isPaused )
while ( controller . isPaused )
Thread . Sleep ( 1 0 0 ) ;
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 . progress = counter ;
_ report . currentFileUrl = item ;
_ report . currentFileUrl = item ;
report . Report ( _ report ) ;
report . Report ( _ report ) ;
if ( ( fileLines . Count > 0 ) & & ( isFileContainQuery ( fileLines , innerQueryTextBox . Text ) ) )
await fillChildNode ( itemsNode , item . Replace ( curDirTextBox . Text , "" ) ) ;
}
}
controller . stopTask ( ) ;
controller . stopTask ( ) ;
return itemsNode ;
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 )
private void reportProgress ( object sender , ProgressReportModel report )
{
{
infoLabel . Text = report . currentFileUrl ;
infoLabel . Text = report . currentFileUrl ;