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); }
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()); }
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; } }
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; } }
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; } } }