Пример #1
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            DraftParser draftImageParser = new DraftParser();

            DraftParser.Result lastResult = null;
            string             setName    = null;
            string             subFolder  = null;

            this.Log("Starting");
            while (true)
            {
                System.Threading.Thread.Sleep(this.pauseTime);
                if (All.GetForegroundProcess().MainWindowTitle != string.Empty)
                {
                    continue;
                }

                Bitmap bmp = All.ScreenCaptureProcess(this.magicProgramName);
                if (bmp == null)
                {
                    continue;
                }

                FastAccessImage    fai    = new FastAccessImage(bmp);
                DraftParser.Result result = draftImageParser.Read(fai, setName);
                if (result.HasCards && (lastResult == null || result.Count != lastResult.Count))
                {
                    if (setName == null)
                    {
                        setName = result.Cards.First().SetName;
                        this.setNameCombo.BeginInvoke(new System.Action(() =>
                        {
                            this.setNameCombo.Text = setName;
                        }));
                    }

                    if (subFolder == null || result.Count == 0)
                    {
                        subFolder = this.rootDirectory + "\\" + DateTime.Now.ToFileTime().ToString();
                        System.IO.Directory.CreateDirectory(subFolder);
                        this.folderCombo.BeginInvoke(new System.Action(() =>
                        {
                            this.folderCombo.Text = subFolder;
                        }));
                    }

                    string file = subFolder + "\\" + DateTime.Now.ToFileTime() + ".png";
                    bmp.Save(file, ImageFormat.Png);
                    string logMessage = string.Format("{0} : wrote to {1}", DateTime.Now, file);
                    this.Log(logMessage);
                    lastResult = result;
                }
            }
        }
Пример #2
0
        public static void ReadDirectory()
        {
            DraftParser parser = new DraftParser();

            foreach (string file in Directory.GetFiles(DraftImageDirectory))
            {
                if (DraftImageExtensions.Contains(new FileInfo(file).Extension))
                {
                    DraftParser.Result result = parser.Read(FastAccessImage.FromPath(file));
                    Console.WriteLine(file + " = " + result);
                }
            }
        }