-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
164 lines (142 loc) · 4.92 KB
/
MainWindow.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Linq;
namespace SimpleFileSearch
{
public partial class MainWindow : Form
{
public MainWindow()
{
InitializeComponent();
LoadData();
this.Text += " - " + Application.ProductVersion;
}
private void SaveData()
{
const int tammax = 50;
if (!Settings.Current.FileNameHistory.Contains(cmbFileName.Text))
{
Settings.Current.FileNameHistory.Insert(0, cmbFileName.Text);
cmbFileName.Items.Insert(0, cmbFileName.Text);
if (Settings.Current.FileNameHistory.Count > tammax)
{
Settings.Current.FileNameHistory.RemoveAt(tammax - 1);
}
}
if (!Settings.Current.SearchInsideFiles.Contains(cmbInFile.Text))
{
Settings.Current.SearchInsideFiles.Insert(0, cmbInFile.Text);
cmbInFile.Items.Insert(0, cmbInFile.Text);
if (Settings.Current.SearchInsideFiles.Count > tammax)
{
Settings.Current.SearchInsideFiles.RemoveAt(tammax - 1);
}
}
if (!Settings.Current.PathHistory.Contains(cmbPath.Text))
{
Settings.Current.PathHistory.Insert(0, cmbPath.Text);
cmbPath.Items.Insert(0, cmbPath.Text);
if (Settings.Current.PathHistory.Count > tammax)
{
Settings.Current.PathHistory.RemoveAt(tammax - 1);
}
}
Settings.Save();
}
private void LoadData()
{
foreach (string s in Settings.Current.FileNameHistory)
{
cmbFileName.Items.Add(s);
}
foreach (string s in Settings.Current.SearchInsideFiles)
{
cmbInFile.Items.Add(s);
}
foreach (string s in Settings.Current.PathHistory)
{
if (string.IsNullOrEmpty(s))
continue;
cmbPath.Items.Add(s);
}
cmbPath.Text = Settings.Current.CurrentDirectory;
}
private void btnSearch_Click(object sender, EventArgs e)
{
PrintStatus("Saving data...");
SaveData();
lstFiles.Items.Clear();
PrintStatus("Searching files...");
FileSearcher fs = new FileSearcher();
fs.estado += new Estado(fs_estado);
List<FileInfo> files = fs.SearchFiles(cmbPath.Text, cmbFileName.Text, cmbInFile.Text, chkCaseSens.Checked);
PrintStatus("Listing files...");
int limit = 2000;
foreach (FileInfo f in files)
{
lstFiles.Items.Add(f);
limit--;
if (limit < 0)
break;
}
PrintStatus("Ready.");
}
void fs_estado(string value)
{
PrintStatus(value);
}
private void lstFiles_DoubleClick(object sender, EventArgs e)
{
if (lstFiles.SelectedItem != null)
{
FileInfo f = (FileInfo)lstFiles.SelectedItem;
Process.Start(Environment.GetEnvironmentVariable("Windir") + "\\" + "explorer.exe", f.Directory.FullName);
}
}
private void PrintStatus(string status)
{
lblEstado.Text = status;
Application.DoEvents();
lblEstado.Refresh();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lblStatus_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start("https://github.com/GustavoHennig/FileSearch");
}
catch (Exception)
{
}
}
private void btnSearchFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new FolderBrowserDialog();
f.SelectedPath = cmbPath.Text;
if (f.ShowDialog() == DialogResult.OK)
{
cmbPath.Text = f.SelectedPath;
}
}
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
//Settings.Default.Save();
}
private void label2_Click(object sender, EventArgs e)
{
MainWindowMF mainWindowMF = new MainWindowMF();
mainWindowMF.Show();
}
}
}