-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainForm.cs
More file actions
164 lines (148 loc) · 6.11 KB
/
MainForm.cs
File metadata and controls
164 lines (148 loc) · 6.11 KB
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.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace FileMonitor
{
public partial class MainForm : Form
{
private readonly Regex PathRegex = new Regex(@"^[A-Z]:\\(.+?\\)*.*$");
public MainForm()
{
InitializeComponent();
Icon = notifyIcon1.Icon = Resource.icon;
notifyIcon1.Visible = true;
Program.FormsContainer.Add(this);
}
private void Form1_Load(object sender, EventArgs e)
{
if (MainProcess.Config.WindowPos.ContainsKey(Name))
{
Top = MainProcess.Config.WindowPos[Name].Top < 0 ? 100 : MainProcess.Config.WindowPos[Name].Top;
Left = MainProcess.Config.WindowPos[Name].Left < 0 ? 100 : MainProcess.Config.WindowPos[Name].Left;
Height = MainProcess.Config.WindowPos[Name].Height;
Width = MainProcess.Config.WindowPos[Name].Width;
}
checkBox1.Checked = MainProcess.Config.AutoRun;
if (MainProcess.Config.AutoRun)
{
WindowState = FormWindowState.Minimized;
notifyIcon1.ShowBalloonTip(5000, "存档监控", "已经在监控游戏存档了", ToolTipIcon.Info);
}
MainProcess.InitWatchers();
dataGridView1.DataSource = MainProcess.Config.FilePaths;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
//if (checkBox1.Checked)
//{
// string StartupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup);
// //获得文件的当前路径
// string dir = Directory.GetCurrentDirectory();
// //获取可执行文件的全部路径
// //string exeDir = dir + @"\FileMonitor.exe.lnk";
// string exeDir = dir + @"\FileMonitor.exe.lnk";
// File.Copy(exeDir, StartupPath + @"\FileMonitor.exe.lnk", true);
//}
//else
//{
// string StartupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup);
// File.Delete(StartupPath + @"\FileMonitor.exe.lnk");
//}
MainProcess.Config.AutoRun = checkBox1.Checked;
}
private void MainForm_SizeChanged(object sender, EventArgs e)
{
ShowInTaskbar = false;
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
Activate();
ShowInTaskbar = true;
}
else if (e.Button == MouseButtons.Right)
{
contextMenuStrip2.Show(MousePosition.X, MousePosition.Y);
}
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)//显示右键菜单
{
dataGridView1.ClearSelection();
dataGridView1.Rows[e.RowIndex].Selected = true;
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
}
else if (e.Button == MouseButtons.Left)
{
if (e.ColumnIndex != 0)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
if (e.ColumnIndex == 1)
{
var datas = (List<PathItem>)dataGridView1.DataSource;
if (datas.Exists(t => datas.IndexOf(t) != e.RowIndex && t.OriginPath == folderBrowserDialog1.SelectedPath))
{
MessageBox.Show("不能对同一路径进行重复监控");
return;
}
}
dataGridView1[e.ColumnIndex, e.RowIndex].Value = folderBrowserDialog1.SelectedPath;
MainProcess.Config.FilePaths = (List<PathItem>)dataGridView1.DataSource;
RefreshGridView();
}
}
}
}
private void RefreshGridView()
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = MainProcess.Config.FilePaths;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
var item = MainProcess.Config.FilePaths[e.RowIndex];
if (item.Started)
{
MainProcess.Dispose(e.RowIndex);
}
else
{
if (PathRegex.IsMatch(item.OriginPath ?? "") && PathRegex.IsMatch(item.BackupPath ?? ""))
{
MainProcess.InitWatcher(e.RowIndex);
}
else
{
MessageBox.Show("请选择正确的原路径和备份路径");
return;
}
}
RefreshGridView();
}
}
private void Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void DeleteItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
var selectIndex = dataGridView1.SelectedRows[0].Index;
MainProcess.Config.FilePaths.RemoveAt(selectIndex);
RefreshGridView();
}
}
}
}