diff --git a/App.config b/App.config index 881791c..2d4d451 100644 --- a/App.config +++ b/App.config @@ -1,21 +1,23 @@ - + - + - - + + - + + - - + + + diff --git a/App.xaml.cs b/App.xaml.cs index 42e0140..323a35b 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,8 @@ -using System.Windows; +using Microsoft.Win32; +using System; +using System.IO; +using System.Windows; +using System.Windows.Threading; namespace GeekDesk { @@ -7,5 +11,138 @@ namespace GeekDesk /// public partial class App : Application { + System.Threading.Mutex mutex; + private void App_Startup(object sender, StartupEventArgs e) + { + bool ret; + mutex = new System.Threading.Mutex(true, "GeekDesk", out ret); + + if (!ret) + { + MessageBox.Show("已有一个客户端正在运行,请先结束原来客户端!"); + Environment.Exit(0); + } + #region 设置程序开机自动运行(+注册表项) + try + { + //SetSelfStarting(true, "GeekDesk.exe"); + } + catch (Exception ex) + { + } + + #endregion + } + + + + #region 注册表开机自启动 + + + /// + /// 开机自动启动 + /// + /// 设置开机启动,或取消开机启动 + /// 注册表中的名称 + /// 开启或停用是否成功 + public bool SetSelfStarting(bool started, string exeName) + { + RegistryKey key = null; + try + { + string exeDir = System.Windows.Forms.Application.ExecutablePath; + //RegistryKey HKLM = Registry.CurrentUser; + //key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项 + key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项 + + if (key == null)//如果该项不存在的话,则创建该子项 + { + key = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); + } + if (started) + { + try + { + object ob = key.GetValue(exeName, -1); + + if (!ob.ToString().Equals(exeDir)) + { + if (!ob.ToString().Equals("-1")) + { + key.DeleteValue(exeName);//取消开机启动 + } + key.SetValue(exeName, exeDir);//设置为开机启动 + } + key.Close(); + + } + catch (Exception ex) + { + return false; + } + } + else + { + try + { + key.DeleteValue(exeName);//取消开机启动 + key.Close(); + } + catch (Exception ex) + { + return false; + } + } + return true; + } + catch (Exception ex) + { + if (key != null) + { + key.Close(); + } + return false; + } + } + + #endregion } + // private void WriteLog(object exception) + // { + // Exception ex = exception as Exception; + + // using (FileStream fs = File.Open(".//ErrorLog.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)) + // { + // fs.Seek(0, SeekOrigin.End); + // byte[] buffer = Encoding.Default.GetBytes("-------------------------------------------------------\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // buffer = Encoding.Default.GetBytes(DateTime.Now.ToString() + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // if (ex != null) + // { + // buffer = Encoding.Default.GetBytes("成员名: " + ex.TargetSite + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // buffer = Encoding.Default.GetBytes("引发异常的类: " + ex.TargetSite.DeclaringType + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // buffer = Encoding.Default.GetBytes("异常信息: " + ex.Message + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // buffer = Encoding.Default.GetBytes("引发异常的程序集或对象: " + ex.Source + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + + // buffer = Encoding.Default.GetBytes("栈:" + ex.StackTrace + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + // } + // else + // { + // buffer = Encoding.Default.GetBytes("应用程序错误: " + exception.ToString() + "\r\n"); + // fs.Write(buffer, 0, buffer.Length); + // } + // } + + //} } diff --git a/Control/UserControls/Config/MotionControl.xaml.cs b/Control/UserControls/Config/MotionControl.xaml.cs index 2666be3..12fca53 100644 --- a/Control/UserControls/Config/MotionControl.xaml.cs +++ b/Control/UserControls/Config/MotionControl.xaml.cs @@ -1,7 +1,6 @@ using GeekDesk.Control.Windows; using GeekDesk.Util; using GeekDesk.ViewModel; -using GlobalHotKey; using HandyControl.Data; using Microsoft.Win32; using System; diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml.cs b/Control/UserControls/PannelCard/RightCardControl.xaml.cs index 1d9892f..3513d31 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml.cs +++ b/Control/UserControls/PannelCard/RightCardControl.xaml.cs @@ -173,7 +173,7 @@ namespace GeekDesk.Control.UserControls.PannelCard { string path = (string)obj; - string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg); + //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg); IconInfo iconInfo = new IconInfo { diff --git a/Control/Windows/ConfigWindow.xaml.cs b/Control/Windows/ConfigWindow.xaml.cs index cbf4a88..2e63ac8 100644 --- a/Control/Windows/ConfigWindow.xaml.cs +++ b/Control/Windows/ConfigWindow.xaml.cs @@ -1,5 +1,4 @@  -using GalaSoft.MvvmLight.Command; using GeekDesk.Control.UserControls; using GeekDesk.Control.UserControls.Config; using GeekDesk.ViewModel; diff --git a/Control/Windows/UpdateWindow.xaml b/Control/Windows/UpdateWindow.xaml index 48fe6b7..975f8f2 100644 --- a/Control/Windows/UpdateWindow.xaml +++ b/Control/Windows/UpdateWindow.xaml @@ -4,13 +4,41 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:GeekDesk.Control.Windows" + xmlns:hc="https://handyorg.github.io/handycontrol" mc:Ignorable="d" - Title="UpdateWindow" Height="450" Width="800" + Title="UpdateWindow" Height="300" Width="450" WindowStyle="None" AllowsTransparency="True" Background="Transparent" ShowInTaskbar="False"> - - + + + + + + + + + + + + + + + + + + + + + +