public Form1() { InitializeComponent(); txtPath.Text = Settings.Default["startPath"].ToString(); txtFileName.Text = Settings.Default["fileNameMask"].ToString(); GUIController.SetForm(this); }
public void Start(TreeView _tView, string rootDir, string _mask) { End(); stopwatch = new System.Diagnostics.Stopwatch(); DirectoryInfo dir = new DirectoryInfo(rootDir); TreeNode node = new TreeNode(dir.Name, 0, 0); if (dir.Exists) { Continue(); numOfAll = 0; GUIController.UpdateTotalFilesLabel(numOfAll); numOfFound = 0; GUIController.UpdateFoundFilesLabel(numOfFound); fileNameMask = _mask; tView = _tView; tView.Nodes.Clear(); tView.Nodes.Add(node); thread = new Thread(() => Work(dir, node)); thread.Start(); } else { MessageBox.Show("Проверьте парвильность введённых данных", "Ошибка"); } }
private void btnSearch_Click(object sender, EventArgs e) { GUIController.UpdateStopConButtonEnabled(true); GUIController.UpdateStopConButtonText("Pause"); threadJob.Start(treeView, txtPath.Text, txtFileName.Text); timerSearch.Start(); SaveSettings(); }
private void timerSearch_Tick(object sender, EventArgs e) { threadJob.ThreadTimeWork(); if (threadJob.ThreadCurrentState() == System.Threading.ThreadState.Stopped) { timerSearch.Stop(); GUIController.UpdateStopConButtonEnabled(false); MessageBox.Show("Поиск завершен"); } }
private void Work(DirectoryInfo rootDir, TreeNode rootNode) { try { while (stopRunning) { } // Контроль остановки поиска TreeNode node; Regex regex = new Regex(fileNameMask); DirectoryInfo[] subDirs = rootDir.GetDirectories(); GUIController.UpdateCurrentFolderLabel(rootDir.Name); // Проход всех подпапок в главной папке foreach (DirectoryInfo dir in subDirs) { node = new TreeNode(dir.Name, 0, 0) { Tag = rootDir }; if (subDirs.Length != 0) { Work(dir, node); } ControlHelper.InvokeEx(tView, new Action(() => rootNode.Nodes.Add(node))); } // Проход по всем полученным файлам и применение к ним регекса foreach (FileInfo file in rootDir.GetFiles()) { if (regex.Match(file.Name).Success) { numOfFound++; node = new TreeNode(file.Name, 1, 1); ControlHelper.InvokeEx(tView, new Action(() => rootNode.Nodes.Add(node))); GUIController.UpdateFoundFilesLabel(numOfFound); } numOfAll++; GUIController.UpdateTotalFilesLabel(numOfAll); } } catch (Exception ex) { if (ex is UnauthorizedAccessException) { return; } } }
private void btnStopCon_Click(object sender, EventArgs e) { if (threadJob.ThreadWork()) { threadJob.Continue(); GUIController.UpdateStopConButtonText("Pause"); timerSearch.Start(); } else { threadJob.Stop(); GUIController.UpdateStopConButtonText("Continue"); timerSearch.Stop(); } }
public void ThreadTimeWork() { GUIController.UpdateTimeSearchLabel((int)stopwatch.Elapsed.TotalMilliseconds); }