Repository navigation
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
executable file
·270 lines (253 loc) · 9.38 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
executable file
·270 lines (253 loc) · 9.38 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using Metro.Controls;
using Plugin;
using RemoteControl;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Resources;
using Wifi;
namespace RemoteControlServer
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private WiFiCreator wc;
private IPMulticastServer ipmserver = new IPMulticastServer();
private ControlServer server;
List<Plugin.PluginBase> l = new List<Plugin.PluginBase>();
private System.Windows.Forms.NotifyIcon notifyIcon = null;
private System.Windows.Forms.ContextMenuStrip contextMenu = new System.Windows.Forms.ContextMenuStrip();
private System.Windows.Forms.ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem();
public MainWindow()
{
InitializeComponent();
SetStartPosition();
CreatAppDataFolder();
StartServer();
Loaded += MainWindow_Loaded;
string dirPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
l = Plugin.PluginLoader.Load<PluginBase>(dirPath+"\\Plugins");
lv.ItemsSource = l;
foreach (var item in l)
{
item.IExecutorUsedChangedEvent += (ie, x) =>
{
if (x && !server.Executors.Contains(ie))
{
server.Executors.Add(ie);
}
else
{
server.Executors.Remove(ie);
}
};
}
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//隐藏任务栏图标
this.ShowInTaskbar = false;
//设置托盘的各个属性
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Text = "NetShuttle";
StreamResourceInfo mini_ico = Application.GetResourceStream(new Uri("mini.ico", UriKind.Relative));
notifyIcon.Icon = new System.Drawing.Icon(mini_ico.Stream);
notifyIcon.Visible = true;
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
item.Text = "退出";
contextMenu.Items.Add(item);
this.notifyIcon.ContextMenuStrip = contextMenu;
item.Click += item_Click;
}
private void item_Click(object sender, EventArgs e)
{
notifyIcon.Dispose();
System.Windows.Application.Current.Shutdown();
}
private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
//如果鼠标左键单击
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.Visibility = Visibility.Visible;
this.ShowInTaskbar = true;
this.Activate();
}
}
public void StartServer()
{
if(server!=null)
{
server.Dispose();
}
int port = 0;
if(!int.TryParse(tbPort.Text,out port)||port>65536||port<1024)
{
port=9999;
tbPort.Text = "9999";
}
server = new ControlServer(IPAddress.Any, port);
if(cbKey.IsChecked==true&&tbKey.Text.Length<=12&&tbKey.Text.Length>=2)
{
ipmserver.AuthenticationString = tbKey.Text;
server.Executors.Add(new AuthenticateExecutor(tbKey.Text));
}
else
{
tbKey.Text = "";
ipmserver.AuthenticationString = null;
server.Executors.Add(new AuthenticateExecutor());
}
if(cbAllowMouse.IsChecked==true)
{
server.Executors.Add(new CommandExecutor());
}
if(cbAllowFileList.IsChecked==true)
{
server.Executors.Add(new FileListTransmissionExecutor());
}
if(cbAllowFileTrans.IsChecked==true)
{
server.Executors.Add(new FileTransmissionExecutor());
}
if(ipmserver.ServerStatus==ServerStatus.Stop)
{
ipmserver.Start();
}
server.Executors.Add(new DesktopTransportExecutor());
server.Listen();
}
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(wc!=null)
{
wc.Dispose();
}
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Hide();
}
private void SetStartPosition()
{
this.Left = SystemParameters.WorkArea.Width - this.Width;
this.Top = SystemParameters.WorkArea.Height - this.Height;
}
private void btnOpenWifi_Click(object sender, RoutedEventArgs e)
{
if(tbName.Text.Length<2||tbName.Text.Length>20)
{
tbSSIDJG.Visibility = Visibility.Visible;
return;
}
else
{
tbSSIDJG.Visibility = Visibility.Hidden;
}
if (pbPwd.Password.Length < 8 || pbPwd.Password.Length > 20)
{
tbPwdJG.Visibility = Visibility.Visible;
return;
}
else
{
tbPwdJG.Visibility = Visibility.Hidden;
}
if (btnOpenWifi.Content.ToString() == "开启热点")
{
wc = new WiFiCreator(tbName.Text, pbPwd.Password);
btnOpenWifi.Content = "正在开启...";
btnOpenWifi.IsEnabled = false;
Thread thread=new Thread(new ThreadStart(()=>{
wc.IP = "192.168.137.1";
wc.Creat();
if (wc.StartAp())
{
this.Dispatcher.BeginInvoke(new ThreadStart(() =>
{
btnOpenWifi.Content = "关闭热点";
icoWifi.Source = new BitmapImage(new Uri("Images/wifi-white.png", UriKind.Relative));
btnOpenWifi.IsEnabled = true;
}));
}
}));
thread.IsBackground = true;
thread.Start();
}
else if (btnOpenWifi.Content.ToString() == "关闭热点")
{
if(wc!=null&&wc.WiFiStatus==WiFiStatus.Running)
{
if (wc.StopAp())
{
btnOpenWifi.Content = "开启热点";
icoWifi.Source = new BitmapImage(new Uri("Images/wifi-black.png", UriKind.Relative));
}
}
}
else
{
}
}
private void btnUse_Click(object sender, RoutedEventArgs e)
{
StartServer();
}
private void cbKey_Click(object sender, RoutedEventArgs e)
{
if(cbKey.IsChecked==true)
{
tbKey.IsEnabled = true;
}
else
{
tbKey.IsEnabled = false;
}
}
private void CreatAppDataFolder()
{
string path =Path.Combine(System.Environment.GetEnvironmentVariable("appdata"),"PocketDesktop");
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
private void PluginSetting_Click(object sender, RoutedEventArgs e)
{
int index = lv.SelectedIndex;
if(index>=0)
{
MetroWindow w = new MetroWindow();
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
w.Background = new SolidColorBrush(Color.FromRgb(138,184,200));
//w.RectangleColor = new SolidColorBrush(Color.FromRgb(76,119,128));
w.RectangleColor = new SolidColorBrush(Colors.Transparent);
Grid g = new Grid();
//g.Background = new SolidColorBrush(Color.FromRgb(120,120,120));
g.Background = new SolidColorBrush(Color.FromRgb(239, 238, 233));
w.Title = l[index].Name + "-设置";
w.Content = g;
UserControl uc = l[index].GetControl();
w.Height = uc.Height+20;
w.Width = uc.Width+20;
g.Children.Add(uc);
w.ShowDialog();
}
}
}
}