예제 #1
0
        static void Main()
        {
            Thread.CurrentThread.Name = "主线程";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Mutex mutex = new Mutex(true, Application.ProductName, out bool ret);

            if (ret)
            {
                Logger.Info(string.Format("正在启动 {0} v{1}, 版本: {2}, 64位: {3}.",
                                          Application.ProductName,
                                          Application.ProductVersion,
                                          System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                                          Util.Is64BitProcess
                                          ));
                Util.PromoteBackupPrivilege();
                Util.PromoteRestorePrivilege();
                App.GetHookManager().EnableHook();
                Icon icon = App.GetIcon();
                USBDevice.CheckDevice();
                Application.Run(icon);
                mutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("已有一个程序正在运行", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #2
0
        static void Main()
        {
            Thread.CurrentThread.Name = "主线程";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Mutex mutex = new Mutex(true, Application.ProductName, out bool ret);

            if (ret)
            {
                Util.PromoteBackupPrivilege();
                Util.PromoteRestorePrivilege();
                Logger      logger      = App.GetLogger();
                HookManager hookManager = App.GetHookManager();
                hookManager.EnableHook();
                Icon icon = App.GetIcon();
                USBDevice.CheckDevice();
                Application.Run(icon);
                mutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("已有一个程序正在运行", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #3
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == USBDevice.WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                    case USBDevice.WM_DEVICECHANGE:
                        break;

                    case USBDevice.DBT_DEVICEARRIVAL:    //U盘插入
                        Logger.Info(Util.MainThread, "检测到U盘已插入");
                        USBDevice.CheckDevice();
                        break;

                    case USBDevice.DBT_CONFIGCHANGECANCELED:
                        break;

                    case USBDevice.DBT_CONFIGCHANGED:
                        break;

                    case USBDevice.DBT_CUSTOMEVENT:
                        break;

                    case USBDevice.DBT_DEVICEQUERYREMOVE:
                        break;

                    case USBDevice.DBT_DEVICEQUERYREMOVEFAILED:
                        break;

                    case USBDevice.DBT_DEVICEREMOVECOMPLETE:     //U盘卸载
                        USBDevice.RemoveDevice();
                        Logger.Info(Util.MainThread, "检测到U盘已卸载");
                        break;

                    case USBDevice.DBT_DEVICEREMOVEPENDING:
                        break;

                    case USBDevice.DBT_DEVICETYPESPECIFIC:
                        break;

                    case USBDevice.DBT_DEVNODES_CHANGED:
                        break;

                    case USBDevice.DBT_QUERYCHANGECONFIG:
                        break;

                    case USBDevice.DBT_USERDEFINED:
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Warn(Util.MainThread, e);
            }
            base.WndProc(ref m);
        }