Browse Source

Получение списка файлов вынесено в отдельный метод getFileList

release
Никита 6 years ago
parent
commit
bbc6c5520f
  1. 29
      fileFinder/MainForm.cs

29
fileFinder/MainForm.cs

@ -65,17 +65,8 @@ namespace fileFinder
private async Task<TreeNode> buildResultTree(TaskController controller, IProgress<ProgressReportModel> report) private async Task<TreeNode> buildResultTree(TaskController controller, IProgress<ProgressReportModel> report)
{ {
TreeNode itemsNode = new TreeNode(); TreeNode itemsNode = new TreeNode();
List<String> foundFiles = new List<String>();
ProgressReportModel _report = new ProgressReportModel(); ProgressReportModel _report = new ProgressReportModel();
List<String> foundFiles = getFileList(curDirTextBox.Text, queryTextBox.Text);
try
{
foundFiles = Directory.GetFiles(curDirTextBox.Text, queryTextBox.Text, SearchOption.AllDirectories).ToList<String>();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Поиск не удался!");
}
int counter = 0; int counter = 0;
foreach (String item in foundFiles) foreach (String item in foundFiles)
@ -83,9 +74,9 @@ namespace fileFinder
while (controller.isPaused) while (controller.isPaused)
{ {
Thread.Sleep(100); Thread.Sleep(100);
if (!mainController.isFormUpdatedAfterPause) if (!controller.isFormUpdatedAfterPause)
{ {
mainController.isFormUpdatedAfterPause = true; controller.isFormUpdatedAfterPause = true;
_report.progress = counter; _report.progress = counter;
_report.currentFileUrl = item; _report.currentFileUrl = item;
_report.currentTreeNode = (TreeNode) itemsNode.Clone(); _report.currentTreeNode = (TreeNode) itemsNode.Clone();
@ -108,6 +99,20 @@ namespace fileFinder
return itemsNode; return itemsNode;
} }
private List<string> getFileList (string directory, string nameQuery)
{
List<String> fileList = new List<String>();
try
{
fileList = Directory.GetFiles(directory, nameQuery, SearchOption.AllDirectories).ToList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Не удалось получить доступ к файлу/папке");
}
return fileList;
}
private string[] getFileContents (string fileUrl) private string[] getFileContents (string fileUrl)
{ {
try try

Loading…
Cancel
Save