forked from TansuoTro/MineRealmsUupdateSystem-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileVersionForm.cs
194 lines (174 loc) · 7.12 KB
/
FileVersionForm.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MRUS.Core;
using System.IO;
namespace MRUS.Server
{
public partial class FileVersionForm : Form
{
private bool changed = false;
private UpdateConfiguration fileConfig;
public FileVersionForm(UpdateConfiguration _fileConfig)
{
InitializeComponent();
this.fileConfig = _fileConfig;
this.BindData();
}
private void BindData()
{
if (this.fileConfig.FileList.Count == 0)
{
List<string> files = ESBasic.Helpers.FileHelper.GetOffspringFiles(AppDomain.CurrentDomain.BaseDirectory + "FileFolder\\");
foreach (string fileRelativePath in files)
{
FileInfo info = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "FileFolder\\" + fileRelativePath);
this.fileConfig.FileList.Add(new FileUnit(fileRelativePath, 1 ,(int)info.Length ,info.LastWriteTime));
}
this.fileConfig.Save();
this.changed = true;
}
((List<FileUnit>)(this.fileConfig.FileList)).Sort();
this.dataGridView1.DataSource = null;
this.dataGridView1.DataSource = this.fileConfig.FileList;
this.label1.Text = "最后更新时间:" + DateTime.Now.ToString();
this.label_lastVersion.Text = "最后综合版本:" + this.fileConfig.ClientVersion;
}
private void button_add_Click(object sender, EventArgs e)
{
AddFileVersionForm addForm = new AddFileVersionForm(this.fileConfig, null);
addForm.addSuccessEvent += new ESBasic.CbGeneric(addForm_addSuccessEvent);
addForm.Show();
}
void addForm_addSuccessEvent()
{
this.BindData();
this.changed = true;
}
private void button_update_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要修改的文件");
return;
}
FileUnit fileObject = this.dataGridView1.SelectedRows[0].DataBoundItem as FileUnit;
AddFileVersionForm addForm = new AddFileVersionForm(this.fileConfig, fileObject);
addForm.addSuccessEvent += new ESBasic.CbGeneric(addForm_addSuccessEvent);
addForm.Show();
}
private void button_delete_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要删除的文件");
return;
}
FileUnit fileObject = this.dataGridView1.SelectedRows[0].DataBoundItem as FileUnit;
DialogResult result = MessageBox.Show(string.Format("确定要删除文件{0}?", fileObject.FileRelativePath), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == System.Windows.Forms.DialogResult.OK)
{
this.fileConfig.FileList.Remove(fileObject);
this.fileConfig.Save();
this.changed = true;
this.BindData();
}
}
private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button != System.Windows.Forms.MouseButtons.Left)
{
return;
}
DataGridView.HitTestInfo info = this.dataGridView1.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
FileUnit fileObject = this.dataGridView1.SelectedRows[0].DataBoundItem as FileUnit;
AddFileVersionForm addForm = new AddFileVersionForm(this.fileConfig, fileObject);
addForm.addSuccessEvent += new ESBasic.CbGeneric(addForm_addSuccessEvent);
addForm.Show();
}
}
private void FileVersionForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.changed)
{
++this.fileConfig.ClientVersion;
this.fileConfig.Save();
MessageBox.Show(string.Format("综合版本更新为:{0}" ,this.fileConfig.ClientVersion));
}
}
private void button1_Click(object sender, EventArgs e)
{
int changedCount = 0;
int addedCount = 0;
List<FileUnit> deleted = new List<FileUnit>();
List<string> files = ESBasic.Helpers.FileHelper.GetOffspringFiles(AppDomain.CurrentDomain.BaseDirectory + "FileFolder\\");
foreach (string fileRelativePath in files)
{
FileInfo info = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "FileFolder\\" + fileRelativePath);
FileUnit unit = this.GetFileUnit(fileRelativePath);
if (unit == null)
{
unit = new FileUnit(fileRelativePath, 1, (int)info.Length, info.LastWriteTime);
this.fileConfig.FileList.Add(unit);
++addedCount;
}
else
{
if (unit.FileSize != info.Length || unit.LastUpdateTime.ToString() != info.LastWriteTime.ToString())
{
unit.Version += 1;
unit.FileSize = (int)info.Length;
unit.LastUpdateTime = info.LastWriteTime;
++changedCount;
}
}
}
foreach (FileUnit unit in this.fileConfig.FileList)
{
bool found = false;
foreach (string fileRelativePath in files)
{
if (fileRelativePath == unit.FileRelativePath)
{
found = true;
break;
}
}
if (!found)
{
deleted.Add(unit);
}
}
foreach (FileUnit unit in deleted)
{
this.fileConfig.FileList.Remove(unit);
}
this.fileConfig.Save();
if (changedCount > 0 || addedCount > 0 || deleted.Count > 0)
{
this.changed = true;
this.dataGridView1.DataSource = null;
this.dataGridView1.DataSource = this.fileConfig.FileList;
string msg = string.Format("更新:{0},新增:{1},删除:{2}" ,changedCount, addedCount, deleted.Count);
MessageBox.Show(msg);
}
}
private FileUnit GetFileUnit(string fileRelativePath)
{
foreach (FileUnit unit in this.fileConfig.FileList)
{
if (unit.FileRelativePath == fileRelativePath)
{
return unit;
}
}
return null;
}
}
}