public void on_new_screenshot(object sender, FileSystemEventArgs e) { Task.Factory.StartNew(() => { Task.Factory.StartNew(() => { upload_image(e.FullPath); }); string map_path, tempest_path; string map_format_path, tempest_format_path; Dispatcher.BeginInvoke(new Action(() => { lbl_report.Content = "New screenshot read..."; btn_report.IsEnabled = false; found_mt = null; })); Bitmap img = new Bitmap(e.FullPath); var img_width = img.Width; var img_height = img.Height; var crop_data = new OCR.CropData { map_from = new Tuple <int, int>((int)(img_width * 0.85), 0), map_to = new Tuple <int, int>(img_width, (int)(img_height * 0.15)), tempest_from = new Tuple <int, int>((int)(img_width * 0.85), (int)(img_height * 0.10)), tempest_to = new Tuple <int, int>(img_width, (int)(img_height * 0.45)), }; foreach (var cd in OCR.CropData.resolutions) { if (img_width == cd.Key.Item1 && img_height == cd.Key.Item2) { crop_data = cd.Value; break; } } try { map_path = Path.Combine(exe_dir, "map.png"); tempest_path = Path.Combine(exe_dir, "tempest.png"); map_format_path = Path.Combine(exe_dir, "map-{0}.png"); tempest_format_path = Path.Combine(exe_dir, "tempest-{0}.png"); } catch (Exception ex) { Console.WriteLine("Something went wrong while combining paths. {0}", ex.Message); return; } update_label_d(lbl_report, "Cropping images"); OCR.Image.crop(e.FullPath, map_path, crop_data.map_from, crop_data.map_to); OCR.Image.crop(e.FullPath, tempest_path, crop_data.tempest_from, crop_data.tempest_to); update_label_d(lbl_report, "Applying filters to images"); var map_images = OCR.Image.apply_filters(map_path, map_format_path); var tempest_images = OCR.Image.apply_filters(tempest_path, tempest_format_path); MapTempest mt = get_map_tempest(map_images, tempest_images); Console.WriteLine(String.Format("Map name: {0}", mt.map)); Console.WriteLine(String.Format("Tempest name: {0}", mt.tempest.name)); bool do_vote = false; if (do_vote && mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) { update_label_d(lbl_report, "Reporting {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix); bool res = vote(mt.map, mt.tempest.prefix, mt.tempest.suffix).Result; if (res) { Console.WriteLine("Successfully sent tempest data!"); update_label_d(lbl_report, "Reported {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix); update_tempests(); } else { Dispatcher.BeginInvoke(new Action(() => { lbl_report.Content = "Error reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix; })); } } else { update_label_d(lbl_report, "NOT reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix); found_mt = mt; if (mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) { found_mt = null; } Dispatcher.BeginInvoke(new Action(() => { if (found_mt != null) { btn_report.IsEnabled = false; } else { btn_report.IsEnabled = true; } })); } }); }
public void on_new_screenshot(object sender, FileSystemEventArgs e) { Task.Factory.StartNew(() => { Task.Factory.StartNew(() => { upload_image(e.FullPath); }); string map_path, tempest_path; string map_format_path, tempest_format_path; Dispatcher.BeginInvoke(new Action(() => { lbl_report.Content = "New screenshot read..."; btn_report.IsEnabled = false; found_mt = null; })); Bitmap img = new Bitmap(e.FullPath); var img_width = img.Width; var img_height = img.Height; var crop_data = new OCR.CropData { map_from = new Tuple<int, int>((int)(img_width * 0.85), 0), map_to = new Tuple<int, int>(img_width, (int)(img_height * 0.15)), tempest_from = new Tuple<int, int>((int)(img_width * 0.85), (int)(img_height * 0.10)), tempest_to = new Tuple<int, int>(img_width, (int)(img_height * 0.45)), }; foreach (var cd in OCR.CropData.resolutions) { if (img_width == cd.Key.Item1 && img_height == cd.Key.Item2) { crop_data = cd.Value; break; } } try { map_path = Path.Combine(exe_dir, "map.png"); tempest_path = Path.Combine(exe_dir, "tempest.png"); map_format_path = Path.Combine(exe_dir, "map-{0}.png"); tempest_format_path = Path.Combine(exe_dir, "tempest-{0}.png"); } catch (Exception ex) { Console.WriteLine("Something went wrong while combining paths. {0}", ex.Message); return; } update_label_d(lbl_report, "Cropping images"); OCR.Image.crop(e.FullPath, map_path, crop_data.map_from, crop_data.map_to); OCR.Image.crop(e.FullPath, tempest_path, crop_data.tempest_from, crop_data.tempest_to); update_label_d(lbl_report, "Applying filters to images"); var map_images = OCR.Image.apply_filters(map_path, map_format_path); var tempest_images = OCR.Image.apply_filters(tempest_path, tempest_format_path); MapTempest mt = get_map_tempest(map_images, tempest_images); Console.WriteLine(String.Format("Map name: {0}", mt.map)); Console.WriteLine(String.Format("Tempest name: {0}", mt.tempest.name)); bool do_vote = false; if (do_vote && mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) { update_label_d(lbl_report, "Reporting {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix); bool res = vote(mt.map, mt.tempest.prefix, mt.tempest.suffix).Result; if (res) { Console.WriteLine("Successfully sent tempest data!"); update_label_d(lbl_report, "Reported {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix); update_tempests(); } else { Dispatcher.BeginInvoke(new Action(() => { lbl_report.Content = "Error reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix; })); } } else { update_label_d(lbl_report, "NOT reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix); found_mt = mt; if (mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) { found_mt = null; } Dispatcher.BeginInvoke(new Action(() => { if (found_mt != null) { btn_report.IsEnabled = false; } else { btn_report.IsEnabled = true; } })); } }); }