예제 #1
0
        void AnalysisFile(string file, CancellationToken ct, ManualResetEvent pauseEvent, IProgress <ScanProgress> progress, int num, int tcount, bool onlyImage)
        {
            log.Info("Scan: " + file);
            Exception classifyException;

            PornDatabase.PornItemType itype = PornDatabase.PornItemType.Undefined;
            if (onlyImage || ActiveFileMonitor.IsFileExtWith(file, ActiveFileMonitor.ImageExts))
            {
                if (PornClassifier.Instance.Classify(file, out classifyException) == PornClassifier.ImageType.P**n)
                {
                    itype = PornDatabase.PornItemType.LocalImage;
                }
            }
            else if (ActiveFileMonitor.IsFileExtWith(file, ActiveFileMonitor.VideoExts))
            {
                if (PornClassifier.Instance.ClassifyVideoFile(file, out classifyException))
                {
                    itype = PornDatabase.PornItemType.LocalVideo;
                }
            }
            if (progress != null)
            {
                ScanProgress npro = new ScanProgress();
                npro.Percentage     = PercentageOffset + PercentageRatio * num / tcount;
                npro.TargetFilePath = file;
                npro.Description    = "正在扫描:" + npro.TargetFilePath;
                npro.ItemType       = itype;
                progress.Report(npro);
            }
            pauseEvent.WaitOne();
            if (ct.IsCancellationRequested)
            {
                ct.ThrowIfCancellationRequested();
            }
        }
예제 #2
0
        public MainForm(string[] args)
        {
            Instance = this;
            Text     = Properties.Resources.ProductionName;
            //ForceToQuit = false;
            Icon = Properties.Resources.icon_main_icon;

            //必须在UI内部初始化,保证progress对象是由UI线程初始化的
            PornDatabase.Init();

            TargetProcessedProgress = new Progress <PornDatabase.PornItemType>();

            const bool bUseIPv6 = false;

            Server = new TcpServer(Properties.Settings.Default.bindPort, bUseIPv6);
            Server.Start(GreenProxy.CreateProxy);
            Server.InitListenFinished.WaitOne();
            if (Server.InitListenException != null)
            {
                throw Server.InitListenException;
            }

            _activeFileMonitor = new ActiveFileMonitor();

            m_aeroEnabled   = false;
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //InitializeComponent();
            Size                         = new System.Drawing.Size(MainFormWidth, MainFormHeight);
            mainPanelControl             = new MainPanelControl();
            scanPanelControl             = new ScanPanelControl();
            _protectionPanelControl      = new ProtectionPanelControl();
            mainPanelControl.Size        = Size;
            scanPanelControl.Size        = Size;
            _protectionPanelControl.Size = Size;
            Controls.Add(_protectionPanelControl);
            Controls.Add(scanPanelControl);
            Controls.Add(mainPanelControl);

            _mainContextMenuTrip = new System.Windows.Forms.ContextMenuStrip();
            ToolStripItem openMainPanel  = _mainContextMenuTrip.Items.Add("打开主界面");
            ToolStripItem openProtection = _mainContextMenuTrip.Items.Add("防护中心");
            ToolStripItem quitItem       = _mainContextMenuTrip.Items.Add("退出");

            openMainPanel.Click  += openMainPanelOnClick;
            quitItem.Click       += quitItemOnClick;
            openProtection.Click += openProtectionOnClick;

            _mainNotifyIcon = new NotifyIcon();
            _mainNotifyIcon.ContextMenuStrip = _mainContextMenuTrip;
            _mainNotifyIcon.Icon             = Properties.Resources.icon_main_icon;
            _mainNotifyIcon.Visible          = true;
            _mainNotifyIcon.DoubleClick     += _mainNotifyIconOnDoubleClick;

            //最小化的方法会导致防护窗口中日志目录的表格尺寸有问题
            if (args.Contains("-notvisible"))
            {
                ShowInTaskbar = false;
                _needToBeHide = true;
                Shown        += MainFormOnShown;
                StartPosition = FormStartPosition.Manual;
                Location      = new Point(-10000, -10000);
                ////Hide();
                ////WindowState = FormWindowState.Minimized;
            }
            //mainPanelControl.ScanEvent += mainPanelOnScanEvent;
            Load        += MainFormOnLoad;
            FormClosed  += MainFormOnFormClosed;
            FormClosing += MainFormOnFormClosing;
            Disposed    += MainFormOnDisposed;

            //set hotkey as ctrl+alt+backspace
            //Boolean success = FormMain.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), MOD_CTRL | MOD_ALT, 0x08);//Set hotkey as 'b'
            //set the owner to avoid the main form in atl-table window
            //Form form1 = new Form();
            //form1.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            //form1.ShowInTaskbar = false;
            //Owner = form1;
        }