示例#1
0
文件: Program.cs 项目: Corv/D3Bit
 static void Main(string[] args)
 {
     var cmds = CommandLineToArgs(Environment.CommandLine);
     if (cmds.Length == 4)
     {
         Tesseract.language_code = cmds[3];
         Bitmap bitmap = Bitmap.FromFile(cmds[1]) as Bitmap;
         var res = Screenshot.GetToolTip(bitmap);
         Tooltip tooltip = new D3Bit.Tooltip(res);
         string name = tooltip.ParseItemName();
         string quality = "";
         string type = tooltip.ParseItemType(out quality);
         double dps = tooltip.ParseDPS();
         string socketBonuses = "";
         var affixes = tooltip.ParseAffixes(out socketBonuses);
         if (name.Length > 0 && quality.Length > 0 && type.Length > 0 && affixes.Keys.Count > 0)
         {
             Dictionary<string, string> itemDic = new Dictionary<string, string>();
             itemDic.Add("Name", name);
             itemDic.Add("Quality", quality);
             itemDic.Add("Type", type);
             itemDic.Add("DPS", dps + "");
             itemDic.Add("Stats", String.Join(", ", affixes.Select(kv => (kv.Value + " " + kv.Key).Trim())));
             var format = "JSON";
             Console.WriteLine(Path.GetExtension(cmds[2]));
             if (Path.GetExtension(cmds[2]).ToLower() == ".xml")
                 format = "XML";
             else if (Path.GetExtension(cmds[2]).ToLower() == ".csv")
                 format = "CSV";
             Export(itemDic, cmds[2], format);
         }
     }
 }
示例#2
0
 public void ParseMetaTestCase()
 {
     string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "..", "images", "05_d3_tooltip_rare.bmp");
     Bitmap bm = new Bitmap(file);
     Tooltip tooltip = new Tooltip(bm);
     string actual = tooltip.ParseMeta();
     string expected = "723-1289,1.32";
     Assert.AreEqual(expected, actual);
 }
示例#3
0
 public void ParseDPSTestCase()
 {
     string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "..", "images", "05_d3_tooltip_rare.bmp");
     Bitmap bm = new Bitmap(file);
     Tooltip tooltip = new Tooltip(bm);
     double actual = tooltip.ParseDPS();
     double expected = 1328.0;
     Assert.AreEqual(expected, actual);
 }
示例#4
0
 public void ParseAffixesTestCase()
 {
     string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "..", "images", "05_d3_tooltip_rare.bmp");
     Bitmap bm = new Bitmap(file);
     Tooltip tooltip = new Tooltip(bm);
     string actual_socket = "";
     Dictionary<string, string> actual_affixes = tooltip.ParseAffixes(out actual_socket);
     Assert.AreEqual("", actual_socket);
     Dictionary<string, string> expected_affixes = new Dictionary<string, string>();
     expected_affixes.Add("MinD", "299");
     expected_affixes.Add("MaxD", "398");
     expected_affixes.Add("Dmg%", "42");
     expected_affixes.Add("Dex", "54");
     expected_affixes.Add("LoH", "858");
     Assert.AreEqual(expected_affixes, actual_affixes);
 }
示例#5
0
文件: UCBatch.cs 项目: CreepGin/D3Bit
        void Process()
        {
            int numProcessed = 0;
            List<Dictionary<string, string>> data = new List<Dictionary<string, string>>();
            foreach (var filename in openFileDialog1.FileNames)
            {
                try
                {
                    Bitmap bitmap = Bitmap.FromFile(filename) as Bitmap;
                    var res = Screenshot.GetToolTip(bitmap);
                    Tooltip tooltip = new D3Bit.Tooltip(res);
                    string name = tooltip.ParseItemName();
                    string quality = "";
                    string type = tooltip.ParseItemType(out quality, Properties.Settings.Default.ReverseQuality);
                    double dps = tooltip.ParseDPS();
                    string meta = tooltip.ParseMeta();
                    string socketBonuses = "";
                    var affixes = tooltip.ParseAffixes(out socketBonuses);
                    if (name.Length > 0 && quality.Length > 0 && type.Length > 0 && affixes.Keys.Count > 0)
                    {
                        Dictionary<string, string> itemDic = new Dictionary<string, string>();
                        itemDic.Add("Name", name);
                        itemDic.Add("Quality", quality);
                        itemDic.Add("Type", type);
                        itemDic.Add("Meta", meta);
                        itemDic.Add("DPS", dps + "");
                        itemDic.Add("Stats", String.Join(", ", affixes.Select(kv => (kv.Value + " " + kv.Key).Trim())));
                        data.Add(itemDic);
                    }
                }
                catch (Exception ex)
                {

                }
                numProcessed++;
                this.UIThread(() => this.progressBar1.Value = (int)Math.Ceiling(numProcessed / (double)openFileDialog1.FileNames.Length * 100));
            }
            Exporter.Export(data, "export." + Properties.Settings.Default.ExportFormat.ToLower(), Properties.Settings.Default.ExportFormat);
            GUI.Log("Parsed {0} out of {1}. Saved to \"export.{2}\"", data.Count, openFileDialog1.FileNames.Length, Properties.Settings.Default.ExportFormat.ToLower());
        }
示例#6
0
文件: frmMain.cs 项目: ipatalas/D3Bit
        void HandleItem()
        {
            tabControl1.SelectTab(tabItem);
            panelDebugPictures.Controls.Clear();

            Trace.TraceInformation("Hello :)");

            var bmp = GetDiabloScreenshot();

            bmp.Save("last_screenshot.png", ImageFormat.Png);

            var result = Screenshot.GetTooltip(bmp);
            if (result == null)
            {
                tbItemSpecs.Text = "Tooltip not found";
                return;
            }
            result.Save("last.png", ImageFormat.Png);

            var sw = Stopwatch.StartNew();
            var tt = new D3Bit.Tooltip(result);
            var r = new Results(tt);
            sw.Stop();

            pbItem.Image = tt.Processed;

            //SaveForUnitTests(r, result, bmp.Size);

            //var sb = new StringBuilder();
            //sb.AppendLine("Name: {0}", r.Name);
            //sb.AppendLine("Type: {0} {1}", r.Quality, r.Type);
            //sb.AppendLine("DPS: {0}", r.DPS);
            //sb.AppendLine("Meta: {0}", r.Meta);
            //sb.AppendLine("Affixes:");
            //sb.Append(r.Affixes.Aggregate(new StringBuilder(), (o, v) => o.AppendLine("\t{0} = {1}", v.Key, v.Value)).ToString());
            //sb.AppendLine("Socket bonuses: {0}", r.SocketBonuses);
            //sb.AppendLine();
            //sb.AppendLine("{0}ms", sw.ElapsedMilliseconds);

            tbItemSpecs.Text = JsonConvert.SerializeObject(r, Formatting.Indented);

            #if DEBUG
            foreach (var item in tt.DebugBitmaps)
            {
                var pb = new PictureBox();
                pb.SizeMode = PictureBoxSizeMode.AutoSize;
                pb.Image = item;
                pb.ContextMenuStrip = cmPictures;

                panelDebugPictures.Controls.Add(pb);
            }
            #endif
        }
示例#7
0
文件: frmMain.cs 项目: ipatalas/D3Bit
        private void BatchSaveForUnitTests()
        {
            var path = @"d:\Programs\Benchmarks\Fraps\Screenshots";

            var pb = new ProgressBar();
            pb.Maximum = 18;
            pb.Dock = DockStyle.Bottom;
            Controls.Add(pb);
            pb.Show();

            foreach (var file in Directory.GetFiles(path, "*.png"))
            {
                var bmp = Bitmap.FromFile(file) as Bitmap;
                var result = Screenshot.GetTooltip(bmp, false);
                if (result == null)
                {
                    Debugger.Break();
                    return;
                }

                var tt = new D3Bit.Tooltip(result);
                var r = new Results(tt);

                pbItem.Image = tt.Processed;

                SaveForUnitTests(r, result, bmp.Size);
                pb.Increment(1);
                Trace.TraceInformation("Saved " + r.Name);
                bmp.Dispose();
            }
            pb.Hide();
            MessageBox.Show("Done!");
        }
示例#8
0
        void Process()
        {
            var sw = Stopwatch.StartNew();
            _tooltipBitmap = Screenshot.GetTooltip(_bitmap);
            sw.Stop();

            GUI.Debug("Tooltip extracted in {0}ms", sw.ElapsedMilliseconds);

            if (_tooltipBitmap == null)
            {
                this.UIThread(Abort);
                return;
            }
            try
            {
                TooltipPath = string.Format("tmp/{0}.png", DateTime.Now.Ticks);
                _tooltipBitmap.Save(TooltipPath, ImageFormat.Png);

                Tooltip tooltip = new Tooltip(_tooltipBitmap);
                _info["name"] = tooltip.ParseItemName();
                IncreaseProgress();
                string quality = "Unknown";
                _info["type"] = tooltip.ParseItemType(out quality);
                _info["quality"] = quality;
                IncreaseProgress();
                _info["dps"] = tooltip.ParseDPS().ToString(CultureInfo.InvariantCulture);
                IncreaseProgress();
                _info["meta"] = tooltip.ParseMeta();
                IncreaseProgress();
                string socketBonuses = "";
                _affixes = tooltip.ParseAffixes(out socketBonuses);
                if (socketBonuses != "")
                    _info["meta"] += _info["meta"] == "" ? socketBonuses : "," + socketBonuses;
                _info["stats"] = String.Join(", ", _affixes.Select(kv => (kv.Value + " " + kv.Key).Trim()));
                IncreaseProgress();

                tooltip.Processed.Save("s.png", ImageFormat.Png);
                this.UIThread(() => progressBar.Visible = false);

                Func<string, string> u = System.Uri.EscapeDataString;
                string url = String.Format("http://d3bit.com/c/?image={0}&battletag={1}&build={2}&secret={3}&{4}&test=1",
                                           u(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TooltipPath)),
                                           u(Properties.Settings.Default.Battletag), Properties.Settings.Default.D3UpDefaultBuildNumber,
                                           u(Properties.Settings.Default.Secret.Trim()), Util.FormGetString(_info));
                browser.Url = new Uri(url);
                //GUI.Log(url);

                GUI.SoundFeedback(true);
                this.UIThread(BringToFront);
            }
            catch (Exception ex)
            {
                GUI.Log(ex.Message);
                GUI.Log(ex.StackTrace);
                this.UIThread(Abort);
                return;
            }
        }
示例#9
0
        void Process()
        {
            _tooltipBitmap = Screenshot.GetToolTip(_bitmap);
            if (_tooltipBitmap == null)
            {
                this.UIThread(Abort);
                return;
            }
            try
            {
                TooltipPath = string.Format("tmp/{0}.png", DateTime.Now.Ticks);
                _tooltipBitmap.Save(TooltipPath, ImageFormat.Png);
                Tooltip tooltip = new Tooltip(_tooltipBitmap);
                _progressStep++;
                _info["name"] = tooltip.ParseItemName();
                _progressStep++;
                string quality = "Unknown";
                _info["type"] = tooltip.ParseItemType(out quality, Properties.Settings.Default.ReverseQuality);
                _info["quality"] = quality;
                _progressStep++;
                _info["meta"] = tooltip.ParseMeta();
                _progressStep++;
                _info["dps"] = tooltip.ParseDPS()+"";
                _progressStep++;
                string socketBonuses = "";
                _affixes = tooltip.ParseAffixes(out socketBonuses);
                if (socketBonuses != "")
                    _info["meta"] += _info["meta"] == "" ? socketBonuses : "," + socketBonuses;
                _info["stats"] = String.Join(", ", _affixes.Select(kv => (kv.Value + " " + kv.Key).Trim()));
                _progressStep++;
                tooltip.Processed.Save("s.png", ImageFormat.Png);
                this.UIThread(() => progressBar.Location = new Point(800, 800));

                Func<string, string> u = System.Uri.EscapeDataString;
                string url = String.Format("http://d3bit.com/c/?image={0}&battletag={1}&build={2}&auctionrName={3}&secret={4}&{5}&test=1",
                                           u(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TooltipPath)),
                                           u(Properties.Settings.Default.Battletag), Properties.Settings.Default.D3UpDefaultBuildNumber,
                                           u(Properties.Settings.Default.AuctionrName),
                                           u(Properties.Settings.Default.Secret.Trim()), Util.FormGetString(_info));
                browser.Url = new Uri(url);
                //GUI.Log(url);

                GUI.SoundFeedback(true);
                this.UIThread(BringToFront);
                //this.UIThread(() => TopMost = false);
            }
            catch (Exception ex)
            {
                GUI.Log(ex.Message);
                GUI.Log(ex.StackTrace);
                this.UIThread(Abort);
                return;
            }
        }
示例#10
0
文件: OverlayForm.cs 项目: Corv/D3Bit
        void Process()
        {
            tooltipBitmap = Screenshot.GetToolTip(_bitmap);
            if (tooltipBitmap == null)
            {
                Abort();
                return;
            }
            try
            {
                /*
                EncoderParameters myEncoderParameters = new EncoderParameters(1);
                myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 70L);
                tooltipBitmap.Save(TOOLTIP_FILEPATH, ImageCodecInfo.GetImageEncoders().Where(c => c.FormatID == ImageFormat.Jpeg.Guid).First(), myEncoderParameters);
                */
                tooltipBitmap.Save(TOOLTIP_FILEPATH, ImageFormat.Png);
                Tooltip tooltip = new Tooltip(tooltipBitmap);
                _progress++;
                name = tooltip.ParseItemName();
                _progress++;
                quality = "";
                type = tooltip.ParseItemType(out quality);
                _progress++;
                dps = tooltip.ParseDPS();
                _progress++;
                string socketBonuses = "";
                affixes = tooltip.ParseAffixes(out socketBonuses);
                stats = String.Join(", ", affixes.Select(kv => (kv.Value + " " + kv.Key).Trim()));
                _progress++;
                this.UIThread(() => panel2.Location = new Point(0, 400));
                this.UIThread(() => panel1.Location = new Point(2, 1));
                tooltip.Processed.Save("s.png", ImageFormat.Png);

                this.UIThread(() => tbName.Text = name);
                this.UIThread(() => cbQuality.Text = quality);
                this.UIThread(() => cbType.Text = type);
                this.UIThread(() => tbDps.Text = dps+"");
                this.UIThread(() => tbStats.Text = stats);

                //Max Stats
                ShowMaxStats(type, affixes);

                GUI.SoundFeedback(true);
                Loaded = true;
            }catch
            {
                Abort();
                return;
            }
        }
示例#11
0
partial         void openScreenshot(NSObject sender)
        {
            var openPanel = new NSOpenPanel();
            openPanel.ReleasedWhenClosed = true;
            openPanel.Prompt = "Select file";

            var result = openPanel.RunModal();
            if (result == 1)
            {
                Bitmap bm = new Bitmap(openPanel.Url.Path);
                var tooltipBmp = Screenshot.GetToolTip(bm);

                if (tooltipBmp != null) {
                    // FIXME: there has to be a better way to do this...
                    // System.IO.MemoryStream s = new System.IO.MemoryStream();
                    // tooltip.Save(s, ImageFormat.Bmp);
                    // var image = NSImage.FromStream(s);
                    // string locationDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    // tooltipBmp.Save(Path.Combine(locationDir, "tooltip.bmp"))
                    // var image = new NSImage(Path.Combine(locationDir, "tooltip.bmp"));
                    // tooltipImageCell.Image = image;

                    // parse D3 information from Bitmap using D3Bit.Tooltip
                    Tooltip tooltip = new Tooltip(tooltipBmp);
                    string name = tooltip.ParseItemName();                      // parse item name
                    string quality = "";
                    string itemType = tooltip.ParseItemType(out quality);       // parse item type (and quality);
                    string dpsArmor = String.Format("{0}", tooltip.ParseDPS()); // parse dps armor
                    string meta = tooltip.ParseMeta();                          // parse meta
                    string socketBonus = "";
                    var affixes = tooltip.ParseAffixes(out socketBonus);        // parse affixes
                    string stats = String.Join(", ", affixes.Select(kv => (kv.Value + " " + kv.Key).Trim()));

                    // TODO: look into how KVO works with MonoMac
                    item = new Item {
                        Name = name,
                        Quality = quality,
                        ItemType = itemType,
                        DpsArmor = dpsArmor,
                        Meta = meta,
                        SocketBonus = socketBonus,
                        Affixes = stats
                    };

                    // set the fields string value in the view
                    nameField.StringValue = item.Name;
                    typeField.StringValue = item.ItemType;
                    qualityField.StringValue = item.Quality;
                    dpsArmorField.StringValue = item.DpsArmor;
                    metaField.StringValue = item.Meta;
                    statsField.StringValue = item.Affixes;

                    // displays the processed tooltip image
                    string locationDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    Console.WriteLine (locationDir);
                    tooltip.Processed.Save(Path.Combine(locationDir, "tooltip.bmp"));
                    var image = new NSImage(Path.Combine(locationDir, "tooltip.bmp"));
                    tooltipImageCell.Image = image;
                }
            }
        }