Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 private void Item_Click(object sender, EventArgs e)
 {
     if (sender is ToolStripMenuItem)
     {
         string    s      = ((ToolStripMenuItem)sender).Text;
         USBDevice device = DeviceList.GetUSBDevice(s);
         if (device != null)
         {
             if (device.State == Status.Unchecked)
             {
                 device.RunSearch();
             }
             else
             {
                 System.Diagnostics.Process.Start(device.RootDir.FullName);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static void RemoveDevice()
        {
            var DriveList = from drive in DriveInfo.GetDrives()
                            select drive.Name;

            for (int i = DeviceList.Count - 1; i >= 0; i--)
            {
                USBDevice device = DeviceList[i];
                if (!DriveList.Contains(device.Name))
                {
                    if (device.State == Status.Checking)
                    {
                        device.USBKiller.Abort = true;
                    }
                    App.GetIcon().RemoveMenuItem(device.MenuItem);
                    DeviceList.Remove(device);
                }
            }
            GC.Collect();
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
        }