Example #1
0
        public static Image GetItemIcon(string iconName, bool small)
        {
            Image returnImage = null;

            iconName = iconName.Replace(".png", "").Replace(".jpg", "").ToLower();
            if (small && SmallIcons.Images.ContainsKey(iconName))
            {
                returnImage = SmallIcons.Images[iconName];
            }
            else if (!small && LargeIcons.Images.ContainsKey(iconName))
            {
                returnImage = LargeIcons.Images[iconName];
            }
            else
            {
                string pathToIcon = null;
                try
                {
                    WebRequestWrapper wrapper = new WebRequestWrapper();
                    if (!String.IsNullOrEmpty(iconName))
                    {
                        pathToIcon = wrapper.DownloadItemIcon(iconName);
                        //just in case the network code is in a disconnected mode. (e.g. no network traffic sent, so no network exception)
                    }

                    if (pathToIcon == null)
                    {
                        pathToIcon = wrapper.DownloadTempImage();
                    }
                }
                catch (Exception)
                {
                    //Log.Write(ex.Message);
                    //Log.Write(ex.StackTrace);
                    //log.Error("Exception trying to retrieve an icon from the armory", ex);
                }
                if (!String.IsNullOrEmpty(pathToIcon))
                {
                    int retry = 0;
                    do
                    {
                        try
                        {
                            using (Stream fileStream = File.Open(pathToIcon, FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                returnImage = Image.FromStream(fileStream);
                            }
                        }
                        catch
                        {
                            returnImage = null;
                            //possibly still downloading, give it a second
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                            if (retry >= 3)
                            {
                                //log.Error("Exception trying to load an icon from local", ex);
                                MessageBox.Show(
                                    "Rawr encountered an error while attempting to load a saved image. If you encounter this error multiple times, please ensure that Rawr is unzipped in a location that you have full file read/write access, such as your Desktop, or My Documents.");
                                //Log.Write(ex.Message);
                                //Log.Write(ex.StackTrace);
                                #if DEBUG
                                throw;
                                #endif
                            }
                        }
                        retry++;
                    } while (returnImage == null && retry < 5);

                    if (returnImage != null)
                    {
                        if (small)
                        {
                            returnImage = ScaleByPercent(returnImage, 50);
                            SmallIcons.Images.Add(iconName, returnImage);
                        }
                        else
                        {
                            LargeIcons.Images.Add(iconName, returnImage);
                        }
                    }
                }
            }
            return(returnImage);
        }
Example #2
0
        public static Image GetTalentIcon(CharacterClass charClass, string talentTree, string talentName, string icon)
        {
            Image  returnImage = null;
            string key         = string.Format("{0}-{1}-{2}", charClass, talentTree, talentName);

            if (key != "Hunter-Ferocity-invalid" &&
                TalentIcons.Images.ContainsKey(key) &&
                TalentIcons.Images[key] == TalentIcons.Images["Hunter-Ferocity-invalid"])
            {
                return(null);
            }
            if (key != "Hunter-Ferocity-invalid" && TalentIcons.Images.ContainsKey(key))
            {
                returnImage = TalentIcons.Images[key];
            }
            else
            {
                string            pathToIcon = null;
                WebRequestWrapper wrapper    = new WebRequestWrapper();
                try {
                    if (!string.IsNullOrEmpty(talentTree) && !string.IsNullOrEmpty(talentName))
                    {
                        pathToIcon = wrapper.DownloadTalentIcon(charClass, talentTree, talentName, icon);
                        //just in case the network code is in a disconnected mode. (e.g. no network traffic sent, so no network exception)
                    }

                    if (pathToIcon == null)
                    {
                        // Try the Item method
                        pathToIcon = wrapper.DownloadItemIcon(icon);
                    }

                    if (pathToIcon == null)
                    {
                        pathToIcon = wrapper.DownloadTempImage();
                    }
                } catch (Exception) {
                    pathToIcon = wrapper.DownloadTempImage();
                    //Log.Write(ex.Message);
                    //Log.Write(ex.StackTrace);
                    //log.Error("Exception trying to retrieve an icon from the armory", ex);
                }
                if (!string.IsNullOrEmpty(pathToIcon))
                {
                    int retry = 0;
                    do
                    {
                        try {
                            using (Stream fileStream = File.Open(pathToIcon, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                                returnImage = Image.FromStream(fileStream);
                            }
                        } catch {
                            returnImage = null;
                            //possibly still downloading, give it a second
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                            if (retry >= 3)
                            {
                                //log.Error("Exception trying to load an icon from local", ex);
                                MessageBox.Show("Rawr encountered an error while attempting to load "
                                                + "a saved image. If you encounter this error multiple "
                                                + "times, please ensure that Rawr is unzipped in a "
                                                + "location that you have full file read/write access, "
                                                + "such as your Desktop, or My Documents."
                                                + "\r\n\r\n" + pathToIcon,
                                                "Image Loader");
                                //Log.Write(ex.Message);
                                //Log.Write(ex.StackTrace);
                                #if DEBUG
                                throw;
                                #endif
                            }
                        }
                        retry++;
                    } while (returnImage == null && retry < 5);

                    if (returnImage != null)
                    {
                        returnImage = Offset(returnImage, new Size(2, 2));
                        TalentIcons.Images.Add(key, returnImage);
                    }
                }
            }
            return(returnImage);
        }
Example #3
0
		public static Image GetTalentIcon(CharacterClass charClass, string talentTree, string talentName, string icon)
		{
			Image returnImage = null;
			string key = string.Format("{0}-{1}-{2}", charClass, talentTree, talentName);
            if (key != "Hunter-Ferocity-invalid"
                && TalentIcons.Images.ContainsKey(key)
                && TalentIcons.Images[key] == TalentIcons.Images["Hunter-Ferocity-invalid"])
            {
                return null;
            }
            if (key != "Hunter-Ferocity-invalid" && TalentIcons.Images.ContainsKey(key)) {
				returnImage = TalentIcons.Images[key];
			} else {
				string pathToIcon = null;
				WebRequestWrapper wrapper = new WebRequestWrapper();
				try {
					if (!string.IsNullOrEmpty(talentTree) && !string.IsNullOrEmpty(talentName)) {
						pathToIcon = wrapper.DownloadTalentIcon(charClass, talentTree, talentName, icon);
						//just in case the network code is in a disconnected mode. (e.g. no network traffic sent, so no network exception)
					}

					if (pathToIcon == null) {
                        // Try the Item method
                        pathToIcon = wrapper.DownloadItemIcon(icon);
                    }

					if (pathToIcon == null) {
						pathToIcon = wrapper.DownloadTempImage();
					}
				} catch (Exception) {
					pathToIcon = wrapper.DownloadTempImage();
					//Log.Write(ex.Message);
					//Log.Write(ex.StackTrace);
					//log.Error("Exception trying to retrieve an icon from the armory", ex);
				}
				if (!string.IsNullOrEmpty(pathToIcon)) {
					int retry = 0;
					do {
						try {
							using (Stream fileStream = File.Open(pathToIcon, FileMode.Open, FileAccess.Read, FileShare.Read)) {
								returnImage = Image.FromStream(fileStream);
							}
						} catch {
							returnImage = null;
							//possibly still downloading, give it a second
							Thread.Sleep(TimeSpan.FromSeconds(1));
							if (retry >= 3) {
								//log.Error("Exception trying to load an icon from local", ex);
								MessageBox.Show("Rawr encountered an error while attempting to load "
                                              + "a saved image. If you encounter this error multiple "
                                              + "times, please ensure that Rawr is unzipped in a "
                                              + "location that you have full file read/write access, "
                                              + "such as your Desktop, or My Documents."
                                              + "\r\n\r\n" + pathToIcon,
                                              "Image Loader");
								//Log.Write(ex.Message);
								//Log.Write(ex.StackTrace);
                                #if DEBUG
								throw;
                                #endif
							}
						}
						retry++;
					} while (returnImage == null && retry < 5);

					if (returnImage != null) {
						returnImage = Offset(returnImage, new Size(2, 2));
						TalentIcons.Images.Add(key, returnImage);
					}
				}
			}
			return returnImage;
		}
Example #4
0
        public static Image GetTalentIcon(CharacterClass charClass, string talentTree, string talentName, string icon)
        {
            Image  returnImage = null;
            string key         = string.Format("{0}-{1}-{2}", charClass, talentTree, talentName);

            if (TalentIcons.Images.ContainsKey(key))
            {
                returnImage = TalentIcons.Images[key];
            }
            else
            {
                string            pathToIcon = null;
                WebRequestWrapper wrapper    = new WebRequestWrapper();
                try
                {
                    if (!string.IsNullOrEmpty(talentTree) && !string.IsNullOrEmpty(talentName))
                    {
                        pathToIcon = wrapper.DownloadTalentIcon(charClass, talentTree, talentName, icon);
                        //just in case the network code is in a disconnected mode. (e.g. no network traffic sent, so no network exception)
                    }

                    if (pathToIcon == null)
                    {
                        pathToIcon = wrapper.DownloadTempImage();
                    }
                }
                catch (Exception /*ex*/)
                {
                    /*Rawr.Base.ErrorBox eb = new Rawr.Base.ErrorBox("Error Getting Talent Icon",
                     *  ex.Message, "GetTalentIcon(...)",
                     *  string.Format("\r\n- Talent Tree: {0}\r\n- Talent Name: {1}\r\n- Icon: {2}\r\n- PathToIcon: {3}", talentTree, talentName, icon, pathToIcon ?? (pathToIcon = "null")),
                     *  ex.StackTrace);*/
                    pathToIcon = wrapper.DownloadTempImage();
                    //Log.Write(ex.Message);
                    //Log.Write(ex.StackTrace);
                    //log.Error("Exception trying to retrieve an icon from the armory", ex);
                }
                if (!string.IsNullOrEmpty(pathToIcon))
                {
                    int retry = 0;
                    do
                    {
                        try
                        {
                            using (Stream fileStream = File.Open(pathToIcon, FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                returnImage = Image.FromStream(fileStream);
                            }
                        }
                        catch
                        {
                            returnImage = null;
                            //possibly still downloading, give it a second
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                            if (retry >= 3)
                            {
                                //log.Error("Exception trying to load an icon from local", ex);
                                MessageBox.Show(
                                    "Rawr encountered an error while attempting to load a saved image. If you encounter this error multiple times, please ensure that Rawr is unzipped in a location that you have full file read/write access, such as your Desktop, or My Documents.");
                                //Log.Write(ex.Message);
                                //Log.Write(ex.StackTrace);
#if DEBUG
                                throw;
#endif
                            }
                        }
                        retry++;
                    } while (returnImage == null && retry < 5);

                    if (returnImage != null)
                    {
                        returnImage = Offset(returnImage, new Size(4, 4));
                        TalentIcons.Images.Add(key, returnImage);
                    }
                }
            }
            return(returnImage);
        }
Example #5
0
        public static Image GetItemIcon(string iconName, bool small)
        {
            Image returnImage = null;
            iconName = iconName.Replace(".png", "").Replace(".jpg", "").ToLower();
            if (small && TalentIcons.Images.ContainsKey(iconName)) {
                returnImage = TalentIcons.Images[iconName];
            } else if (!small && TalentIcons.Images.ContainsKey(iconName)) {
                returnImage = TalentIcons.Images[iconName];
            } else {
                string pathToIcon = null;
                WebRequestWrapper wrapper = null;
                try {
                    wrapper = new WebRequestWrapper();
                    if (!String.IsNullOrEmpty(iconName)) {

                        pathToIcon = wrapper.DownloadItemIcon(iconName);
                        //just in case the network code is in a disconnected mode. (e.g. no network traffic sent, so no network exception)
                    }

                    if (pathToIcon == null) {
                        pathToIcon = wrapper.DownloadTempImage();
                    }
                } catch (Exception) {
                    try {
                        pathToIcon = wrapper.DownloadTempImage();
                    } catch (Exception) { }
                    //Log.Write(ex.Message);
                    //Log.Write(ex.StackTrace);
                    //log.Error("Exception trying to retrieve an icon from the armory", ex);
                }
                if (!String.IsNullOrEmpty(pathToIcon)) {
                    int retry = 0;
                    do {
                        try {
                            using (Stream fileStream = File.Open(pathToIcon, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                                returnImage = Image.FromStream(fileStream);
                            }
                        } catch {
                            returnImage = null;
                            //possibly still downloading, give it a second
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                            if (retry >= 3) {
                                //log.Error("Exception trying to load an icon from local", ex);
                                MessageBox.Show(
                                    "Rawr encountered an error while attempting to load a saved image. If you encounter this error multiple times, please ensure that Rawr is unzipped in a location that you have full file read/write access, such as your Desktop, or My Documents.");
                                //Log.Write(ex.Message);
                                //Log.Write(ex.StackTrace);
                                #if DEBUG
                                throw;
                                #endif
                            }
                        }
                        retry++;
                    } while (returnImage == null && retry < 5);

                    if (returnImage != null) {
                        if (small) {
                            returnImage = ScaleByPercent(returnImage, 50);
                        }
                        TalentIcons.Images.Add(iconName, returnImage);
                    }
                }
            }
            return returnImage;
        }