-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoryBrowserForm.cs
96 lines (85 loc) · 2.78 KB
/
DirectoryBrowserForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GS_ReplayBrowser
{
public partial class DirectoryBrowserForm : Form
{
public DirectoryBrowserForm()
{
InitializeComponent();
}
private string[] _Files;
private Dictionary<string, ReplayInfo> _Result;
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var dir = folderBrowserDialog1.SelectedPath;
_Files = Directory.EnumerateFiles(dir, "*.rep", SearchOption.TopDirectoryOnly).ToArray();
textBox1.Text = dir;
progressBar1.Value = 0;
progressBar1.Visible = true;
backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
var number = _Files.Length;
_Result = new Dictionary<string, ReplayInfo>();
var finished = 0;
var toReport = 10;
foreach (var f in _Files)
{
++finished;
try
{
_Result.Add(f, new ReplayInfo(f));
}
catch
{
}
if (--toReport <= 0)
{
toReport = 10;
backgroundWorker1.ReportProgress((int)(100.0f * finished / number));
}
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBar1.Visible = false;
listView1.Items.Clear();
foreach (var entry in _Result)
{
var item = new ListViewItem(new string[] { Path.GetFileName(entry.Key), entry.Value.Description }, -1);
item.Tag = entry.Value;
listView1.Items.Add(item);
}
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0)
{
return;
}
var sel = (ReplayInfo)listView1.SelectedItems[0].Tag;
if (sel != null)
{
var dialog = new ReplayInfoForm(sel);
dialog.ShowDialog();
}
}
}
}