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); }
/// <summary> /// for HTML5 offline access /// </summary> /// <returns></returns> public ActionResult Index() { StringBuilder sb = new StringBuilder(); bool notfound = false; sb.AppendLine("CACHE MANIFEST"); sb.AppendLine("# " + GeneralConstants.TIMESTAMP); sb.AppendLine("FALLBACK:"); sb.AppendLine("/dashboard/product/edit /dashboard/product/edit"); sb.AppendLine("/dashboard/category/addsub /dashboard/category/addsub"); sb.AppendLine("NETWORK:"); sb.AppendLine("*"); sb.AppendLine("CACHE:"); foreach (var entry in URLS_TO_CACHE) { #if DEBUG // ignore invalid certificates ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; // verify that url is valid as it is a pita to debug applicationCache errors using (var client = new HeadClient()) { try { var head = client.DownloadString(accountHostname.ToDomainUrl(entry)); } catch (Exception ex) { Syslog.Write(ex); notfound = true; } } #endif sb.AppendLine(entry); } Debug.Assert(!notfound); // cannot cache all images as we're limited to 5mb offline cache /* * var images = db.images.Where(x => x.subdomain == subdomainid.Value); * var sizes = Enum.GetValues(typeof (Imgsize)); * foreach (var image in images) * { * foreach (Imgsize size in sizes) * { * try * { * var url = Img.by_size(image.url, size); * sb.AppendLine(url); * } * catch (Exception ex) * { * Syslog.Write(ex); * } * } * } */ Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); Response.Cache.SetValidUntilExpires(false); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Response.ContentType = "text/cache-manifest"; return(Content(sb.ToString())); }
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; }