private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); DirectoryInfo dirInfo = new DirectoryInfo(textBox1.Text); allFoundFiles = Filef.GetFilesByExtensions(dirInfo, ".exe", ".lnk").ToList(); for (int i = 0; i < allFoundFiles.Count; i++) { if (allFoundFiles[i].Extension == ".lnk") { allFoundFiles[i] = new FileInfo(Filef.lnk(allFoundFiles[i])); bool find = false; int index = 0; for (int j = 0; j < pro.Count; j++) { if (pro[j].path == allFoundFiles[i].FullName) { find = true; index = j; } } if (find) { listBox1.Items.Add(allFoundFiles[i].Name + " Запусков программы: " + pro[index].count); } else { listBox1.Items.Add(allFoundFiles[i].Name); } } else { listBox1.Items.Add(allFoundFiles[i].Name); } } }
private void button2_Click(object sender, EventArgs e) { try { FileInfo file = allFoundFiles[listBox1.SelectedIndex]; Process iStartProcess = new Process(); iStartProcess.StartInfo.FileName = file.ToString(); iStartProcess.Start(); bool find = false; for (int i = 0; i < pro.Count; i++) { if (pro[i].path == file.FullName) { pro[i].count++; find = true; } } if (!find) { pro.Add(new Program(allFoundFiles[listBox1.SelectedIndex])); } listBox1.Items.Clear(); DirectoryInfo dirInfo = new DirectoryInfo(textBox1.Text); allFoundFiles = Filef.GetFilesByExtensions(dirInfo, ".exe", ".lnk").ToList(); for (int i = 0; i < allFoundFiles.Count; i++) { if (allFoundFiles[i].Extension == ".lnk") { allFoundFiles[i] = new FileInfo(Filef.lnk(allFoundFiles[i])); find = false; int index = 0; for (int j = 0; j < pro.Count; j++) { if (pro[j].path == allFoundFiles[i].FullName) { find = true; index = j; } } if (find) { listBox1.Items.Add(allFoundFiles[i].Name + " Запусков программы: " + pro[index].count); } else { listBox1.Items.Add(allFoundFiles[i].Name); } } else { listBox1.Items.Add(allFoundFiles[i].Name); } } } catch { MessageBox.Show("Ошибка при запуске программы"); } }