/// <summary> /// 快捷键注册按键 /// </summary> /// <param name="code"></param> public void ShortcutkeyHandRegister() { string temp = ClassStatic.GetConfigSoftware("copy"); ClassStatic.ShortcutKeys tempkey = GetShortcutKey(temp, ClassHotKey.KeyModifiers.Ctrl, Keys.C); if (tempkey.key1 != ClassHotKey.KeyModifiers.Ctrl || tempkey.key2 != Keys.C) { ClassHotKey.RegisterHotKey(Handle, ClassStatic.ShortcutKey.Copy, tempkey.key1, tempkey.key2); } temp = ClassStatic.GetConfigSoftware("paste"); tempkey = GetShortcutKey(temp, ClassHotKey.KeyModifiers.Ctrl, Keys.V); if (tempkey.key1 != ClassHotKey.KeyModifiers.Ctrl || tempkey.key2 != Keys.V) { ClassHotKey.RegisterHotKey(Handle, ClassStatic.ShortcutKey.Paste, tempkey.key1, tempkey.key2); } temp = ClassStatic.GetConfigSoftware("screenshot"); tempkey = GetShortcutKey(temp, ClassHotKey.KeyModifiers.Ctrl, Keys.P); ClassHotKey.RegisterHotKey(Handle, ClassStatic.ShortcutKey.Screenshot, tempkey.key1, tempkey.key2); temp = ClassStatic.GetConfigSoftware("color"); tempkey = GetShortcutKey(temp, ClassHotKey.KeyModifiers.Ctrl, Keys.L); ClassHotKey.RegisterHotKey(Handle, ClassStatic.ShortcutKey.Color, tempkey.key1, tempkey.key2); }
/// <summary> /// 修改缓存位置按钮被点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonChangePath_Click(object sender, EventArgs e) { if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { cachePath.Text = folderBrowserDialog.SelectedPath; ClassStatic.SetConfigSoftware("cachePath", cachePath.Text); } }
/// <summary> /// 解析连接开启 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Parsing_CheckedChanged(object sender, EventArgs e) { if (ClassStatic.GetConfigSoftware("parse") != Parsing.Checked.ToString()) { ClassStatic.SetConfigSoftware("parse", Parsing.Checked.ToString()); Action <bool, byte[]> action = new Action <bool, byte[]>(SettingChange_Callback); ClassStatic.ClientData clientData = new ClassStatic.ClientData("parse", Parsing.Checked.ToString()); ClassStatic.tcpClient.Send(220, ClassStatic.SetClientDataByte(clientData), action); } }
public static ClientData GetClientData(byte[] data) { ClientData temp; try { temp = JsonConvert.DeserializeObject <ClassStatic.ClientData>(ClassStatic.GetString(data)); } catch { temp = null; } return(temp); }
public static UserLoginSuccess GetLoginSuccessData(byte[] data) { UserLoginSuccess temp; try { temp = JsonConvert.DeserializeObject <ClassStatic.UserLoginSuccess>(ClassStatic.GetString(data)); } catch { temp = null; } return(temp); }
public static ListDrive GetListDrive(byte[] data) { ListDrive temp; try { temp = JsonConvert.DeserializeObject <ClassStatic.ListDrive>(ClassStatic.GetString(data)); } catch { temp = null; } return(temp); }
public static ListDriveData GetListDriveData(byte[] data) { ListDriveData temp; try { temp = JsonConvert.DeserializeObject <ClassStatic.ListDriveData>(ClassStatic.GetString(data)); } catch { temp = new ListDriveData("false", new List <ListDrive>()); } return(temp); }
/// <summary> /// 快捷键设置抬起 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextShortcutKey_KeyUp(object sender, KeyEventArgs e) { TextBox that = sender as TextBox; string type; if (that.Tag != null) { if (that == textCopy) { type = "copy"; } else if (that == textPaste) { type = "paste"; } else if (that == textScreenshot) { type = "screenshot"; } else if (that == textColor) { type = "color"; } else { type = ""; } if (that.Text != "" && that.Text != that.Tag.ToString()) { if (type != "") { Action <bool, byte[]> action = new Action <bool, byte[]>(SettingChange_Callback); ClassStatic.ClientData clientData = new ClassStatic.ClientData(type, that.Text); ClassStatic.tcpClient.Send(220, ClassStatic.SetClientDataByte(clientData), action); ClassStatic.SetConfigSoftware(type, that.Text); } } else { that.Text = that.Tag.ToString(); } that.Tag = null; if (shortcutkey) { shortcutkey = false; FormMain.formMain.ShortcutkeyHandRegister(); } } }
/// <summary> /// 有设备改变运行状态 /// </summary> /// <param name="state"></param> /// <param name="data"></param> public void OnDeviceChangeStateHandler(int state, byte[] data) { if (state == 203) { string token = ClassStatic.GetString(data); string stateDrive = token.Substring(token.Length - 2, 2); token = token.Substring(0, token.Length - 2); this.Invoke(new Action(() => { if (controlDeviceOnline.ContainsKey(token)) { ControlDevice temp = controlDeviceOnline[token]; temp.Status = (stateDrive == "在线" ? 0 : 1); } })); } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (Status == 0) { MessageBox.Show("无法删除一个在线的设备!"); } else { if (deviceId != "") { // 获取设备列表 Action <bool, byte[]> action = new Action <bool, byte[]>(DeleteDeviceList_Callback); ClassStatic.tcpClient.Send(238, ClassStatic.SetClientDataByte(new ClassStatic.ClientData(deviceId)), action); } } }
/// <summary> /// 确定按钮点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { // 更换头像事件 if (portrait.Portrait != (int)pictureSelect.Tag) { portrait.Portrait = (int)pictureSelect.Tag; ClassStatic.portraitPid = (int)pictureSelect.Tag; ClassStatic.SetConfig("portrait", pictureSelect.Tag.ToString()); // 已经登录更改头像事件 if (ClassStatic.account != "") { } } this.Close(); }
/// <summary> /// 将byte[]转为Result /// </summary> /// <param name="data"></param> /// <returns></returns> public static Result GetResult(byte[] data) { Result temp; try { temp = JsonConvert.DeserializeObject <ClassStatic.Result>(ClassStatic.GetString(data)); } catch { temp = new Result(); temp.ret = "false"; temp.msg = "与服务器链接失败"; } return(temp); }
/// <summary> /// 模式更改到勿扰 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemtoolStripMenuItemNoData_Click(object sender, EventArgs e) { if (ClassStatic.tcpClient.IsConnected && ClassStatic.onlineStatus != 1) { if (ClassStatic.isLogined) { this.Invoke(new Action(() => { ClassStatic.onlineStatus = 1; statusOnlineControl1.Status = 1; deviceList.controlDeviceMyself.Status = 1; notifyIcon1.Icon = Properties.Resources.RemoteClipboardRed; Action <bool, byte[]> action = new Action <bool, byte[]>(MenuItemChangeState_Callback); ClassStatic.tcpClient.Send(203, ClassStatic.GetBytes("勿扰"), action); })); } } }
/// <summary> /// 登录成功,加载数据 /// </summary> /// <param name="phone"></param> public void LoginSuccess(string phone) { this.Invoke(new Action(() => { timerControlLoading.Start(); if (!ClassStatic.IsPhone(phone)) { LabelTipShow("登录失败,登录账号格式有误", true); return; } ClassStatic.account = phone; string name = Dns.GetHostName(); string mac = ClassStatic.GetMacByNetworkInterface(); Action <bool, byte[]> action = new Action <bool, byte[]>(SendMyOnline_Callback); ClassStatic.ClientData clientData = new ClassStatic.ClientData(name, mac, ClassStatic.portraitPid.ToString()); ClassStatic.tcpClient.Send(201, ClassStatic.SetClientDataByte(clientData), action); })); }
/// <summary> /// 上线信息响应回调处理 /// </summary> /// <param name="state"></param> /// <param name="data"></param> private void SendMyOnline_Callback(bool state, byte[] data) { this.Invoke(new Action(() => { if (state) { ClassStatic.UserLoginSuccess resultData = ClassStatic.GetLoginSuccessData(data); if (resultData != null && resultData.ret == "true") { ClassStatic.isLogined = true; ClassStatic.bind = resultData.bind; if (ClassStatic.GetConfigSoftware("turnOn") == "") { ClassStatic.SetConfigSoftware("turnOn", "False"); } if (ClassStatic.GetConfigSoftware("parse") == "") { ClassStatic.SetConfigSoftware("parse", resultData.parse); } if (ClassStatic.GetConfigSoftware("copy") == "") { ClassStatic.SetConfigSoftware("copy", resultData.copy); } if (ClassStatic.GetConfigSoftware("paste") == "") { ClassStatic.SetConfigSoftware("paste", resultData.paste); } if (ClassStatic.GetConfigSoftware("screenshot") == "") { ClassStatic.SetConfigSoftware("screenshot", resultData.screenshot); } if (ClassStatic.GetConfigSoftware("color") == "") { ClassStatic.SetConfigSoftware("color", resultData.color); } FormLogin.formLogin.Close(); return; } } ClassStatic.account = ""; LabelTipShow("登录失败,请稍后再试", true); })); }
/// <summary> /// 刷新设备列表 /// </summary> public void InitializeDeviceList() { DeviceOnlineCount = 1; flowLayoutPanelList.Controls.Clear(); controlDeviceOnline.Clear(); controlDeviceOffline.Clear(); controlDeviceMyself.Title = System.Net.Dns.GetHostName(); controlDeviceMyself.Mac = ClassStatic.GetMacByNetworkInterface(); controlDeviceMyself.Status = ClassStatic.onlineStatus; controlDeviceMyself.Oneself = true; controlDeviceMyself.Portrait = ClassStatic.portraitPid; flowLayoutPanelList.Controls.Add(controlDeviceMyself); // 获取设备列表 Action <bool, byte[]> action = new Action <bool, byte[]>(GetDeviceList_Callback); ClassStatic.tcpClient.Send(200, ClassStatic.GetBytes("获取设备列表"), action); }
/// <summary> /// 获取设备列表回调函数 /// </summary> /// <param name="state"></param> /// <param name="data"></param> private void GetDeviceList_Callback(bool state, byte[] data) { if (state) { this.Invoke(new Action(() => { ClassStatic.ListDriveData listDriveData = ClassStatic.GetListDriveData(data); if (listDriveData != null) { DeviceOnlineCount = 1; foreach (ClassStatic.ListDrive drive in listDriveData.list) { ControlDevice temp = new ControlDevice(); temp.DeviceId = drive.mac; temp.Title = drive.name; temp.Mac = drive.mac; temp.Portrait = Convert.ToInt32(drive.pid); temp.Status = drive.state; if (drive.token != "" && drive.token != null) { DeviceOnlineCount++; controlDeviceOnline.Add(drive.token, temp); flowLayoutPanelList.Controls.Add(temp); } else { controlDeviceOffline.Add(temp.Mac, temp); } } foreach (ControlDevice temp in controlDeviceOffline.Values) { flowLayoutPanelList.Controls.Add(temp); } labelListNum.Text = "我的设备(" + DeviceOnlineCount + "/" + (listDriveData.list.Count + 1) + ")"; } })); } }
private void buttonFinish_Click(object sender, EventArgs e) { // 定义一个临时图层 Image temp = (Image)canvasImage.Clone(); Graphics graphics = Graphics.FromImage(temp); foreach (DrawShape drawShape in drawShapeList) { DrawShapeOnGraphics(graphics, drawShape); } graphics.Dispose(); int w = cropBoxRectangle.Width; int h = cropBoxRectangle.Height; Image temp2 = new Bitmap(w, h); graphics = Graphics.FromImage(temp2); graphics.DrawImage(temp, new Rectangle(0, 0, w, h), cropBoxRectangle, GraphicsUnit.Pixel); graphics.Dispose(); string path = ClassStatic.GetConfigSoftware("cachePath"); if (Directory.Exists(path) == false) { path = System.Environment.CurrentDirectory + "\\cache"; Directory.CreateDirectory(path); ClassStatic.SetConfigSoftware("cachePath", path); } path = path + "\\" + DateTime.Now.ToString("yyyy-MM-dd.HHmmss") + ".png"; temp2.Save(path); StringCollection file = new StringCollection(); file.Add(path); Clipboard.SetFileDropList(file); temp.Dispose(); temp2.Dispose(); this.Close(); }
public void InitializeControl() { if (ClassStatic.GetConfigSoftware("cachePath") == "") { ClassStatic.SetConfigSoftware("cachePath", System.Environment.CurrentDirectory + "\\cache"); } string path = ClassStatic.GetConfigSoftware("cachePath"); if (Directory.Exists(path) == false) { path = System.Environment.CurrentDirectory + "\\cache"; Directory.CreateDirectory(path); ClassStatic.SetConfigSoftware("cachePath", path); } cachePath.Text = path; if (ClassStatic.bind != "") { textBindNumber.Text = ClassStatic.bind; buttonBindQQ.Text = "解除绑定"; } else { textBindNumber.Text = "等待绑定"; buttonBindQQ.Text = "绑定QQ"; } turnOn.Checked = (ClassStatic.GetConfigSoftware("turnOn") == "True"); Parsing.Checked = (ClassStatic.GetConfigSoftware("parse") == "True"); textCopy.Text = ClassStatic.GetConfigSoftware("copy"); textPaste.Text = ClassStatic.GetConfigSoftware("paste"); textScreenshot.Text = ClassStatic.GetConfigSoftware("screenshot"); textColor.Text = ClassStatic.GetConfigSoftware("color"); }
/// <summary> /// 剪贴板内容改变事件 /// </summary> private void DisplayClipboardData() { if (ClassStatic.isLogined) { if (ClassStatic.isRemoteClipboardData < 1) { if (Clipboard.ContainsImage()) { Action <bool, byte[]> action = new Action <bool, byte[]>(ClipboardData_Callback); ClassStatic.tcpClient.Send(222, ClassStatic.GetByteImage(Clipboard.GetImage()), action); } if (Clipboard.ContainsText()) { if (ClassStatic.GetConfigSoftware("parse") == "True") { string url = Clipboard.GetText(); string path = ClassStatic.GetConfigSoftware("cachePath"); MatchCollection mc = Regex.Matches(url, @"^http://(.*?)\.\w+$"); if (mc.Count > 0) { string filename = ""; try { Uri uri = new Uri(url); filename = System.Web.HttpUtility.UrlDecode(uri.Segments.Last()); } catch {} if (filename != "") { path += "\\" + filename; FormDownload temp = new FormDownload(url, path); temp.Show(); } } } Action <bool, byte[]> action = new Action <bool, byte[]>(ClipboardData_Callback); ClassStatic.tcpClient.Send(221, ClassStatic.GetBytes(Clipboard.GetText()), action); } if (Clipboard.ContainsFileDropList()) { if (Clipboard.GetFileDropList().Count == 1) { string file = Clipboard.GetFileDropList()[0]; if (File.Exists(file) == true) { byte[] buffur = { }; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { try { buffur = new byte[fs.Length]; fs.Read(buffur, 0, (int)fs.Length); } catch (Exception ex) { throw ex; } } string fileName = Path.GetFileName(file); Action <bool, byte[]> action = new Action <bool, byte[]>(ClipboardData_Callback); List <byte> byteSource = new List <byte>(); byte[] fileNameByte = ClassStatic.GetBytes(fileName); byte[] fileNameByteLenth = ClassStatic.GetBytes(fileNameByte.Length.ToString()); byteSource.AddRange(new byte[] { Convert.ToByte(fileNameByteLenth.Length) }); byteSource.AddRange(fileNameByteLenth); byteSource.AddRange(fileNameByte); byteSource.AddRange(buffur); ClassStatic.tcpClient.Send(223, byteSource.ToArray(), action); } } } } else { ClassStatic.isRemoteClipboardData--; } } }
private void turnOn_CheckedChanged(object sender, EventArgs e) { ClassStatic.SetConfigSoftware("turnOn", turnOn.Checked.ToString()); }
private void SettingChange_Callback(bool state, byte[] data) { System.Diagnostics.Debug.WriteLine(ClassStatic.GetString(data)); }
/// <summary> /// 远程发送剪贴板中含有文字 /// </summary> /// <param name="state"></param> /// <param name="data"></param> public void OnOtherDriveClipboardDataTextHandler(int state, byte[] data) { if (state == 221) { this.Invoke(new Action(() => { ClassStatic.isRemoteClipboardData = 2; Clipboard.SetText(ClassStatic.GetString(data)); })); } if (state == 222) { this.Invoke(new Action(() => { Bitmap bmp = new Bitmap(Clipboard.GetImage()); string path = ClassStatic.GetConfigSoftware("cachePath"); if (Directory.Exists(path) == false) { path = System.Environment.CurrentDirectory + "\\cache"; Directory.CreateDirectory(path); ClassStatic.SetConfigSoftware("cachePath", path); } path += "\\img"; if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } path += "\\" + DateTime.Now.ToString("yyyy-MM-dd.HHmmss") + ".png"; bmp.Save(path, Clipboard.GetImage().RawFormat); StringCollection file = new StringCollection(); file.Add(path); ClassStatic.isRemoteClipboardData = 2; Clipboard.SetFileDropList(file); bmp.Dispose(); })); } if (state == 223) { string fileName = ""; try { int lenth = Convert.ToInt32(ClassStatic.GetString(data.Skip(1).Take(data[0]).ToArray())); data = data.Skip(data[0] + 1).ToArray(); fileName = ClassStatic.GetString(data.Take(lenth).ToArray()); data = data.Skip(lenth).ToArray(); } catch { } if (fileName != "") { this.Invoke(new Action(() => { string path = ClassStatic.GetConfigSoftware("cachePath"); if (Directory.Exists(path) == false) { path = System.Environment.CurrentDirectory + "\\cache"; Directory.CreateDirectory(path); ClassStatic.SetConfigSoftware("cachePath", path); } path += "\\" + fileName; System.Diagnostics.Debug.WriteLine(path); FileStream fs = new FileStream(path, FileMode.Create); System.Diagnostics.Debug.WriteLine(data.Length); fs.Write(data, 0, data.Length); fs.Close(); StringCollection file = new StringCollection(); file.Add(path); ClassStatic.isRemoteClipboardData = 2; Clipboard.SetFileDropList(file); System.Diagnostics.Debug.WriteLine(Clipboard.GetFileDropList().Count); })); } } if (state == 238) { this.Invoke(new Action(() => { FormMain.formMain.deviceList.InitializeDeviceList(); })); } }
/// <summary> /// 接收服务端信息 /// </summary> private void SocketReceive() { while (socketConnect && socketClient != null && socketClient.Connected) { try { byte[] temp = new byte[1024]; byte[] data = new byte[1024]; List <byte> byteSource = new List <byte>(); int length = socketClient.Receive(data, data.Length, 0); byteSource.AddRange(data.Take(length)); while (socketClient.Available > 0) { Thread.Sleep(100); int len = socketClient.Receive(temp, temp.Length, 0); if (len > 0) { byteSource.AddRange(temp.Take(len)); } } data = byteSource.ToArray(); length = data.Length; if (length > 3) { // 获取标识码 int state; if (Int32.TryParse(Encoding.UTF8.GetString(data.Take(3).ToArray()), out state)) { // 是否使用回调函数 uint isCallback = data[3]; // 截取数据 data = data.Skip(4).ToArray(); if (isCallback == 1) { string token = ClassStatic.GetString(data.Take(32).ToArray()); if (sendCallbackList.ContainsKey(token)) { data = data.Skip(32).ToArray(); sendCallbackList[token].action(true, data); sendCallbackList.Remove(token); } // 丢弃错误回调ID的数据包 } else { // 执行客户端信息响应事件 OnServerReceiveHandler?.Invoke(state, data); } } // 丢弃协议不合法的数据包 } // 丢弃长度不合法的数据包 } catch (SocketException ex) { // 断开连接 socketConnect = false; // 断开与服务器的连接 OnServerCloseHandler?.Invoke(); return; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); // 其他错误 } } }