private static string CopyFile(string gameid, string image_id, string name) { string searchPattern = $"{image_id}.*"; var imagedir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "OCTGN", "ImageDatabase", gameid, "Sets"); var search = Directory.GetFiles("Export", searchPattern, SearchOption.AllDirectories); string found = search.SingleOrDefault(); if (found != null) { return($"Images/{Path.GetFileName(found)}"); } search = Directory.GetFiles(imagedir, searchPattern, SearchOption.AllDirectories); try { found = search.SingleOrDefault(); } catch (InvalidOperationException) { Console.WriteLine($"Collision on {image_id}: {name}"); found = CollisionForm.Resolve(search, name, image_id); } if (found != null) { string finalname = $"{image_id}" + Path.GetExtension(found); string destFileName = Path.Combine("Export", "Images", finalname); using (var bitmap = Image.FromFile(found)) { if (bitmap.Width > bitmap.Height) { bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); bitmap.Save(destFileName); return($"Images/{finalname}"); } } File.Copy(found, destFileName); return($"Images/{finalname}"); } Console.WriteLine($"Couldn't find {image_id}!"); return(""); }
internal static string Resolve(string[] search, string name, string image_id) { // There's a mess with some of the old Image Packs, due to Jarret using sequential uuids, rather than naturally generating them. // While the issues have been cleaned up in the XML, some of the old uuids still show up in old imagepacks. // These "bad images" can be safely deleted, as nothing refers to them anymore. switch (image_id) { case "09291d3f-1889-4c27-9822-e4fe01076164": case "09291d3f-1889-4c27-9822-e4fe01076076": case "09291d3f-1889-4c27-9822-e4fe01076062": var bad = search.Single(p => p.Contains("e8d510f7-4ad1-4ed8-a85d-3b7c21ce083b")); File.Delete(bad); return(search.Single(p => p.Contains("32b3926d-0563-4b05-b8e7-9f2848b500d3"))); default: // TLDR: If there's an issue, it's probably in e8d510f7-4ad1-4ed8-a85d-3b7c21ce083b. break; } using (var form = new CollisionForm()) { form.Text = $"Which of these looks like '{name}'?"; foreach (var item in search) { PictureBox image = new PictureBox() { ImageLocation = item, SizeMode = PictureBoxSizeMode.AutoSize }; image.Click += form.Image_Click; form.flowLayoutPanel1.Controls.Add(image); } form.WindowState = FormWindowState.Maximized; form.ShowDialog(); return(form.chosen); } }