private bool ParseSave() { if (Monitor.TryEnter(_parse_lock)) { try { foreach (PictureBox slot in slots) { // Stop existing animations AnimatedSprite sprite = (slot.Tag is AnimatedSprite) ? (AnimatedSprite)slot.Tag : null; if (sprite == null) { continue; } else { sprite.StopAnimation(); slot.Invalidate(); } } PokeSave save = new PokeSave(txtSavPath.Text + @"\Pokemon Yellow.sav"); try { List <Pokemon> pokes = save.Team; try { foreach (Pokemon p in pokes) { if (p.DexNumber == 0) { continue; } Console.WriteLine("Found Pkmn #" + p.DexNumber + "!"); //string sprite_name = p.DexNumber.ToString().PadLeft(3, '0') + ".png"; string local_resource = @"poke_sprites/" + _pokemon[p.DexNumber - 1].ToLower() + ".gif"; if (!Directory.Exists(@"poke_sprites")) { Console.WriteLine("PokemonParty sprites directory does not exist. Creating one..."); Directory.CreateDirectory(@"poke_sprites"); } if (!File.Exists(local_resource)) { /*using (WebClient Client = new WebClient()) * { * Client.DownloadFile(@"http://www.serebii.net/pokedex-xy/icon/" + sprite_name, sprite_file); * }*/ string remote_url = @"http://www.pkparaiso.com/imagenes/xy/sprites/animados/"; using (HeadClient Client = new HeadClient()) { string remote_resource_name = _pokemon[p.DexNumber - 1].ToLower() + ".gif"; Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name); } using (HeadClient Client = new HeadClient()) { for (int i = 2; i <= 5; i++) { string remote_resource_name = _pokemon[p.DexNumber - 1].ToLower() + "-" + i.ToString() + ".gif"; Client.HeadOnly = true; try { Client.DownloadData(remote_url + remote_resource_name); Client.HeadOnly = false; Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name); } catch { Console.WriteLine("Couldn't find remote resource: " + remote_resource_name); break; } } } Console.WriteLine("Done downloading available sprites."); } } } catch { Console.WriteLine("Unable to download pkmn team sprites"); } try { for (int i = 0; i < pokes.Count; i++) { //string sprite_name = pokes[i].DexNumber.ToString().PadLeft(3, '0') + ".png"; string sprite_name = _pokemon[pokes[i].DexNumber - 1].ToLower() + ".gif"; string sprite_file = @"poke_sprites/" + sprite_name; //slots[i].ImageLocation = sprite_file; if (!File.Exists(sprite_file)) { Console.WriteLine("Sprite file does not exist: " + sprite_file); continue; } Image image = null; try { image = Image.FromFile(sprite_file); } catch (Exception e) { Program.ExitWithError(e, "Error loading sprite image."); } _images[i].Clear(); _images[i].Add(image); for (int alt = 2; alt <= 5; alt++) { string local_resource_name = @"poke_sprites/" + _pokemon[pokes[i].DexNumber - 1].ToLower() + "-" + alt.ToString() + ".gif"; if (File.Exists(local_resource_name)) { _images[i].Add(Image.FromFile(local_resource_name)); } else { break; } } //if (_images[i].Width == 192 && _images[i].Height == 192) { { // Let Paint draw it. slots[i].Image = null; try { slots[i].Tag = new AnimatedSprite(slots[i], _images[i]); } catch { slots[i].Tag = null; Console.WriteLine("Unable to create AnimatedSprite."); }; }/* else { * slots[i].Image = _images[i]; * }*/ } } catch { Console.WriteLine("Unable to set pkmn team sprites"); } } catch { Console.WriteLine("Unable to extract team."); } Thread.Sleep(1000 * 5); // Hold so duplicate calls fall through. return(true); } catch { Console.WriteLine("PokemonParty: Save file does not exist."); } finally { Monitor.Exit(_parse_lock); } } else { Console.WriteLine("Couldn't get parse file lock"); } return(false); }
private bool ParseSave() { if (Monitor.TryEnter(_parse_lock)) { try { foreach (PictureBox slot in slots) { // Stop existing animations AnimatedSprite sprite = (slot.Tag is AnimatedSprite) ? (AnimatedSprite)slot.Tag : null; if (sprite == null) continue; else { sprite.StopAnimation(); slot.Invalidate(); } } PokeSave save = new PokeSave(txtSavPath.Text + @"\Pokemon Yellow.sav"); try { List<Pokemon> pokes = save.Team; try { foreach (Pokemon p in pokes) { if (p.DexNumber == 0) continue; Console.WriteLine("Found Pkmn #" + p.DexNumber + "!"); //string sprite_name = p.DexNumber.ToString().PadLeft(3, '0') + ".png"; string local_resource = @"poke_sprites/" + _pokemon[p.DexNumber - 1].ToLower() + ".gif"; if (!Directory.Exists(@"poke_sprites")) { Console.WriteLine("PokemonParty sprites directory does not exist. Creating one..."); Directory.CreateDirectory(@"poke_sprites"); } if (!File.Exists(local_resource)) { /*using (WebClient Client = new WebClient()) { Client.DownloadFile(@"http://www.serebii.net/pokedex-xy/icon/" + sprite_name, sprite_file); }*/ string remote_url = @"http://www.pkparaiso.com/imagenes/xy/sprites/animados/"; using (HeadClient Client = new HeadClient()) { string remote_resource_name = _pokemon[p.DexNumber - 1].ToLower() + ".gif"; Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name); } using (HeadClient Client = new HeadClient()) { for (int i = 2; i <= 5; i++) { string remote_resource_name = _pokemon[p.DexNumber - 1].ToLower() + "-" + i.ToString() + ".gif"; Client.HeadOnly = true; try { Client.DownloadData(remote_url + remote_resource_name); Client.HeadOnly = false; Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name); } catch { Console.WriteLine("Couldn't find remote resource: " + remote_resource_name); break; } } } Console.WriteLine("Done downloading available sprites."); } } } catch { Console.WriteLine("Unable to download pkmn team sprites"); } try { for (int i = 0; i < pokes.Count; i++) { //string sprite_name = pokes[i].DexNumber.ToString().PadLeft(3, '0') + ".png"; string sprite_name = _pokemon[pokes[i].DexNumber - 1].ToLower() + ".gif"; string sprite_file = @"poke_sprites/" + sprite_name; //slots[i].ImageLocation = sprite_file; if (!File.Exists(sprite_file)) { Console.WriteLine("Sprite file does not exist: " + sprite_file); continue; } Image image = null; try { image = Image.FromFile(sprite_file); } catch (Exception e) { Program.ExitWithError(e, "Error loading sprite image."); } _images[i].Clear(); _images[i].Add(image); for (int alt = 2; alt <= 5; alt++) { string local_resource_name = @"poke_sprites/" + _pokemon[pokes[i].DexNumber - 1].ToLower() + "-" + alt.ToString() + ".gif"; if (File.Exists(local_resource_name)) { _images[i].Add(Image.FromFile(local_resource_name)); } else break; } //if (_images[i].Width == 192 && _images[i].Height == 192) { { // Let Paint draw it. slots[i].Image = null; try { slots[i].Tag = new AnimatedSprite(slots[i], _images[i]); } catch { slots[i].Tag = null; Console.WriteLine("Unable to create AnimatedSprite."); }; }/* else { slots[i].Image = _images[i]; }*/ } } catch { Console.WriteLine("Unable to set pkmn team sprites"); } } catch { Console.WriteLine("Unable to extract team."); } Thread.Sleep(1000 * 5); // Hold so duplicate calls fall through. return true; } catch { Console.WriteLine("PokemonParty: Save file does not exist."); } finally { Monitor.Exit(_parse_lock); } } else Console.WriteLine("Couldn't get parse file lock"); return false; }