Example #1
0
        private void backgroundWorker_DoWork(CancellationToken ct)
        {
            try
            {
                String iecachepath = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
                log.Info("IE cache path: " + iecachepath);
                var totalfiles = SafeFileEnumerator.EnumerateFiles(iecachepath, "*.*", SearchOption.AllDirectories);
                //Directory.EnumerateFiles(iecachepath, "*.*", SearchOption.AllDirectories).Where<String>(s => (s.EndsWith(".jpg") || s.EndsWith(".png")));

                string roamingPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                var    dirs        = SafeFileEnumerator.EnumerateDirectories(roamingPath, "*Cache*", SearchOption.AllDirectories);

                string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                dirs = dirs.Concat(SafeFileEnumerator.EnumerateDirectories(localAppDataPath, "*Cache*", SearchOption.AllDirectories));

                foreach (var dir in dirs)
                {
                    totalfiles = totalfiles.Concat(SafeFileEnumerator.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories));
                }

                int tcount = totalfiles.Count();
                int num    = 0;
                foreach (var file in totalfiles)
                {
                    log.Info("Scan: " + file);
                    PornClassifier.ImageType t;
                    try
                    {
                        t = PornClassifier.Instance.Classify(file);
                    }
                    catch (Exception exception)
                    {
                        log.Error(exception.ToString());
                        t = PornClassifier.ImageType.Normal;
                    }
                    num++;
                    //backgroundWorker.ReportProgress(100 * num / tcount, new PornFile(file, t));
                    //progressBar.Invoke(backgroundWorker_ProgressChanged, (int)100*num/tcount, file, t);
                    int percentage = 100 * num / tcount;
                    if (percentage > 100)
                    {
                        percentage = 100;
                    }
                    progressBar.BeginInvoke(progressChanged, percentage, file, t);
                    if (ct.IsCancellationRequested)
                    {
                        ct.ThrowIfCancellationRequested();
                    }
                    //if (backgroundWorker.CancellationPending)
                    //    break;
                }
            }
            catch (Exception exception)
            {
                log.Error(exception.ToString());
            }
        }
Example #2
0
 void CustomLocalScan(string dir, CancellationToken ct, ManualResetEvent pauseEvent, IProgress <ScanProgress> progress)
 {
     try
     {
         //要忽略程序自身的缓存
         string localTempDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\masatek\\trollwiz";
         var    totalfiles   = SafeFileEnumerator.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories,
                                                                 d => !(d.Contains(localTempDir))
                                                                 ).Where <String>(FilesCanProcessed);
         int tcount = totalfiles.Count();
         int num    = 0;
         foreach (var file in totalfiles)
         {
             AnalysisFile(file, ct, pauseEvent, progress, num, tcount, false);
             num++;
         }
     }
     catch (Exception exception)
     {
         log.Error(exception.ToString());
     }
 }