Example #1
0
        public static void CacheAllIcons(Item[] items)
        {
            StatusMessaging.UpdateStatus("Cache Item Icons", "Caching all Item Icons");
            WebRequestWrapper webRequests      = new WebRequestWrapper();
            List <string>     filesDownloading = new List <string>();

            for (int i = 0; i < items.Length && !WebRequestWrapper.LastWasFatalError; i++)
            {
                string iconName = items[i].IconPath.Replace(".png", "").Replace(".jpg", "").ToLower();
                webRequests.DownloadItemIconAsync(iconName);
            }

            while (webRequests.RequestQueueCount > 0 && !WebRequestWrapper.LastWasFatalError)
            {
                Thread.Sleep(200);
            }

            //TODO: Display any error information appropriotly here,
            //such as, proxy information incorrect or network connection down. Can get pretty detailed about exactly what went
            //wrong by analyzing the exception.
            if (WebRequestWrapper.LastWasFatalError)
            {
                StatusMessaging.ReportError("Cache All Icons", null, "There was an error trying to retrieve images from the armory.  Please check your proxy settings and network connection.");
            }
            StatusMessaging.UpdateStatusFinished("Cache Item Icons");
        }
Example #2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            FormEnterId form = new FormEnterId();

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                _changingItemCache = true;
                try
                {
                    WebRequestWrapper.ResetFatalErrorIndicator();
                    int itemId = form.Value;
                    if (itemId > 0)
                    {
                        AddItemById(form.Value, form.UseArmory, form.UseWowhead);
                    }
                    else
                    {
                        AddItemByName(form.ItemName, form.UseArmory, form.UseWowhead);
                    }
                }
                finally
                {
                    _changingItemCache = false;
                }
            }
            form.Dispose();
        }
Example #3
0
        public override ItemLocation Fill(XmlDocument doc, XmlNode node, string itemId)
        {
            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/createdBy/spell/item");

            if (subNode != null)
            {
                Bind = (BindsOn)Enum.Parse(typeof(BindsOn), node.SelectSingleNode("/page/itemTooltips/itemTooltip/bonding").InnerText);
            }
            else
            {
                subNode = doc.SelectSingleNode("/page/itemInfo/item");
                if (subNode.Attributes["requiredSkill"] != null)
                {
                    Bind = BindsOn.BoP;
                }
                else
                {
                    Bind = BindsOn.BoE;
                }
            }
            if (subNode.Attributes["requiredSkill"] != null)
            {
                Skill = subNode.Attributes["requiredSkill"].Value;
                Level = int.Parse(subNode.Attributes["requiredSkillRank"].Value);
            }
            else
            {
                Skill = "Unknown";
            }

            subNode = doc.SelectSingleNode("/page/itemInfo/item/createdBy/spell/@name");
            if (subNode != null)
            {
                SpellName = subNode.InnerText;
            }


            foreach (XmlNode reagent in doc.SelectNodes("/page/itemInfo/item/createdBy/spell/reagent"))
            {
                string name  = reagent.Attributes["name"].Value;
                int    count = int.Parse(reagent.Attributes["count"].Value);
                if (!_materialBindMap.ContainsKey(name))
                {
                    WebRequestWrapper wrw = new WebRequestWrapper();
                    doc = wrw.DownloadItemToolTipSheet(reagent.Attributes["id"].Value);

                    _materialBindMap[name] = (BindsOn)Enum.Parse(typeof(BindsOn), doc.SelectSingleNode("/page/itemTooltips/itemTooltip/bonding").InnerText);
                }

                if (_materialBindMap[name] == BindsOn.BoP)
                {
                    BopMats[name] = count;
                }
            }

            return(this);
        }
Example #4
0
        public override ItemLocation Fill(XmlDocument doc, XmlNode node, string itemId)
        {
            if (doc != null)
            {
                // Save the informations of the vendor.
                string      _vendorName = "Unknown";
                string      _vendorArea = "*";
                XmlNodeList listVendor  = doc.SelectNodes("/page/itemInfo/item/vendors/creature");
                if (listVendor.Count > 0)
                {
                    _vendorName = listVendor[0].Attributes["name"].Value.Replace("quot;", "'");
                    _vendorArea = listVendor[0].Attributes["area"].Value;
                }

                foreach (XmlNode subNode in doc.SelectNodes("/page/itemInfo/item/cost/token"))
                {
                    string tokenId = subNode.Attributes["id"].Value;
                    int    count   = int.Parse(subNode.Attributes["count"].Value);

                    string tokenName = null;

                    if (!_idToNameMap.TryGetValue(tokenId, out tokenName))
                    {
                        WebRequestWrapper wrw = new WebRequestWrapper();
                        doc = wrw.DownloadItemInformation(int.Parse(tokenId));

                        _idToNameMap[tokenId] = tokenName = doc.SelectSingleNode("/page/itemInfo/item/@name").InnerText;
                    }

                    _tokenMap[tokenName] = count;
                }

                // The armory (falsly) list a buy price for some items which have a cost in badges.
                // So only check for a gold price if there's not also a token cost.
                Cost = 0;
                if (_tokenMap.Count == 0)
                {
                    XmlNode costNode = doc.SelectSingleNode("/page/itemInfo/item/cost/@buyPrice");
                    if (costNode != null)
                    {
                        Cost = int.Parse(costNode.InnerText);
                    }
                }

                if (listVendor.Count > 0)
                {
                    VendorName = _vendorName;
                    VendorArea = _vendorArea;
                }
                else if (_tokenMap.Count == 0)
                {
                    return(new ItemLocation("Vendor"));
                }
            }

            return(this);
        }
Example #5
0
 private void buildTreeFramework()
 {
     if (fullyQualified())
     {
         WebRequestWrapper wrw        = new WebRequestWrapper();
         string            talentTree = wrw.DownloadClassTalentTree(_class);
         string            talentCode = wrw.DownloadCharacterTalentTree(_name, _region, _realm).SelectSingleNode("page/characterInfo/talentTab/talentTree").Attributes["value"].Value;
         populateTrees(talentTree, talentCode);
     }
 }
Example #6
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/containerObjects/object[1]");

            Area      = subNode.Attributes["area"].Value;
            Container = subNode.Attributes["name"].Value;
            return(this);
        }
Example #7
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/rewardFromQuests/quest[1]");

            Area     = subNode.Attributes["area"].Value;
            Quest    = subNode.Attributes["name"].Value;
            MinLevel = int.Parse(subNode.Attributes["reqMinLevel"].Value);
            Party    = int.Parse(subNode.Attributes["suggestedPartySize"].Value);
            return(this);
        }
Example #8
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/rewardFromQuests/quest[1]");

            if (subNode != null)
            {
                return(QuestItem.Construct().Fill(node, itemId));
            }



            subNode = doc.SelectSingleNode("/page/itemInfo/item/cost/@buyPrice");

            if (subNode != null)
            {
                Cost = int.Parse(subNode.InnerText);
            }
            else
            {
                Cost = 0;
            }

            foreach (XmlNode token in doc.SelectNodes("/page/itemInfo/item/cost/token"))
            {
                int    Count = int.Parse(token.Attributes["count"].Value);
                string id    = token.Attributes["id"].Value;
                if (!tokenIDMap.ContainsKey(id))
                {
                    WebRequestWrapper wrw2 = new WebRequestWrapper();
                    XmlDocument       doc2 = wrw.DownloadItemInformation(int.Parse(id));

                    tokenIDMap[id] = doc2.SelectSingleNode("/page/itemInfo/item/@name").InnerText;
                }

                _tokenMap[tokenIDMap[id]] = Count;
            }


            subNode = node.SelectSingleNode("/page/itemTooltips/itemTooltip/requiredFaction");
            if (subNode != null)
            {
                FactionName = subNode.Attributes["name"].Value;
                Level       = (ReputationLevel)System.Enum.Parse(typeof(ReputationLevel), subNode.Attributes["rep"].Value);
            }

            return(this);
        }
Example #9
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/dropCreatures/creature[1]/@area");

            if (subNode != null)
            {
                Location = subNode.InnerText;
            }

            return(this);
        }
Example #10
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            string  TokenId;
            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/cost/@honor");

            if (subNode != null)
            {
                Points    = int.Parse(subNode.InnerText);
                PointType = "Honor";
                subNode   = doc.SelectSingleNode("/page/itemInfo/item/cost/token/@count");
                if (subNode != null)
                {
                    TokenCount = int.Parse(subNode.InnerText);
                    TokenId    = doc.SelectSingleNode("/page/itemInfo/item/cost/token").Attributes["id"].Value;

                    if (_tokenMap.ContainsKey(TokenId))
                    {
                        TokenType = _tokenMap[TokenId];
                    }
                    else
                    {
                        wrw = new WebRequestWrapper();
                        doc = wrw.DownloadItemInformation(int.Parse(TokenId));

                        TokenType = doc.SelectSingleNode("/page/itemInfo/item").Attributes["name"].Value;

                        _tokenMap[TokenId] = TokenType;
                    }
                }
            }
            else
            {
                subNode = doc.SelectSingleNode("/page/itemInfo/item/cost/@arena");
                if (subNode != null)
                {
                    Points    = int.Parse(subNode.InnerText);
                    PointType = "Arena";
                }
            }

            return(this);
        }
Example #11
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            FormEnterId form = new FormEnterId();

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                _changingItemCache = true;
                try
                {
                    WebRequestWrapper.ResetFatalErrorIndicator();
                    AddItemById(form.Value);
                }
                finally
                {
                    _changingItemCache = false;
                }
            }
            form.Dispose();
        }
Example #12
0
        public static ItemLocation Create(XmlNode node, string itemId)
        {
            ItemLocation item = null;

            try
            {
                if (node != null && node.SelectSingleNode("page/itemTooltips/itemTooltip/itemSource") != null)
                {
                    WebRequestWrapper wrw        = new WebRequestWrapper();
                    XmlDocument       doc        = wrw.DownloadItemInformation(int.Parse(itemId));
                    string            sourceType = node.SelectSingleNode("page/itemTooltips/itemTooltip/itemSource").Attributes["value"].Value;

                    // If the armory has an item source set to creatureDrop, check to see if it might also be a vendor sold item
                    // and if so, switch it's type to vendor
                    if (sourceType == "sourceType.creatureDrop")
                    {
                        if (doc != null)
                        {
                            XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/cost/token");
                            if (subNode != null)
                            {
                                sourceType = "sourceType.vendor";
                            }
                        }
                    }
                    // If the armory has an item source set to vendor, check to see if it cost honor or arena point to purchase and if so,
                    // switch it's type to pvpItem
                    if (sourceType == "sourceType.vendor")
                    {
                        if (doc != null)
                        {
                            XmlNode subNodeH = doc.SelectSingleNode("/page/itemInfo/item/cost/@honor");
                            XmlNode subNodeA = doc.SelectSingleNode("/page/itemInfo/item/cost/@arena");

                            if (subNodeH != null || subNodeA != null)
                            {
                                sourceType = "sourceType.pvpReward";
                            }
                        }
                    }
                    if (_LocationFactory.ContainsKey(sourceType))
                    {
                        item = _LocationFactory[sourceType]();
                        item = item.Fill(doc, node, itemId);
                    }
                    else
                    {
                        throw new Exception("Unrecognized item source " + sourceType);
                    }
                }
                else
                {
                    item = UnknownItem.Construct();
                }
            }
            catch (System.Exception e)
            {
                item = new ItemLocation("Failed - " + e.Message);
            }
            ItemLocation[] prev = { null, null };
            _allLocations.TryGetValue(itemId, out prev);
            if (prev != null)
            {
                item.Note = prev[0].Note;
            }
            _allLocations[itemId] = new ItemLocation[] { item, null };

            return(item);
        }
Example #13
0
        public override ItemLocation Fill(XmlNode node, string itemId)
        {
            WebRequestWrapper wrw = new WebRequestWrapper();
            XmlDocument       doc = wrw.DownloadItemInformation(int.Parse(itemId));

            if (doc != null)
            {
                XmlNode subNode = doc.SelectSingleNode("/page/itemInfo/item/cost/token");
                if (subNode != null)
                {
                    string tokenId = subNode.Attributes["id"].Value;
                    int    count   = int.Parse(subNode.Attributes["count"].Value);

                    string Boss = null;
                    string Area = null;

                    if (!_idToBossMap.ContainsKey(tokenId))
                    {
                        doc = wrw.DownloadItemInformation(int.Parse(tokenId));

                        XmlNodeList list = doc.SelectNodes("/page/itemInfo/item/dropCreatures/creature");

                        subNode = list[0];
                        if (list.Count == 1)
                        {
                            Boss = subNode.Attributes["name"].Value;
                            Area = subNode.Attributes["area"].Value;
                            _idToBossMap[tokenId] = Boss;
                            _bossToAreaMap[Boss]  = Area;
                        }
                        else if (list.Count > 1)
                        {
                            Boss = subNode.SelectSingleNode("/page/itemInfo/item/@name").InnerText;
                            Area = "*";
                        }
                        else
                        {
                            Boss = "Unknown";
                            Area = "*";
                        }

                        _idToBossMap[tokenId] = Boss;
                        _bossToAreaMap[Boss]  = Area;
                    }
                    else
                    {
                        Boss = _idToBossMap[tokenId];
                        Area = _bossToAreaMap[Boss];
                    }
                    if (Area != "*")
                    {
                        return(new StaticDrop()
                        {
                            Area = Area,
                            Boss = Boss,
                            Heroic = false
                        });
                    }

                    Count = count;
                    Token = Boss;
                }
                else
                {
                    return(new ItemLocation("Vendor"));
                }
            }

            return(this);
        }
Example #14
0
        public override ItemLocation Fill(XmlDocument doc, XmlNode node, string itemId)
        {
            string      TokenId;
            XmlNode     subNodeH   = doc.SelectSingleNode("/page/itemInfo/item/cost/@honor");
            XmlNode     subNodeA   = doc.SelectSingleNode("/page/itemInfo/item/cost/@arena");
            XmlNode     subNodeRAR = node.SelectSingleNode("page/itemTooltips/itemTooltip/requiredPersonalArenaRating/@personalArenaRating");
            XmlNodeList vendorList = doc.SelectNodes("/page/itemInfo/item/vendors/creature");

            if (subNodeRAR != null)
            {
                RequiredArenaRating = int.Parse(subNodeRAR.InnerText);
            }

            if (subNodeH != null && subNodeA != null)
            {
                Points    = int.Parse(subNodeH.InnerText);
                PointType = "Honor";
                subNodeH  = doc.SelectSingleNode("/page/itemInfo/item/cost/token/@count");
                if (subNodeH != null)
                {
                    TokenCount = int.Parse(subNodeH.InnerText);
                    TokenId    = doc.SelectSingleNode("/page/itemInfo/item/cost/token").Attributes["id"].Value;

                    if (_tokenMap.ContainsKey(TokenId))
                    {
                        TokenType = _tokenMap[TokenId];
                    }
                    else
                    {
                        WebRequestWrapper wrw = new WebRequestWrapper();
                        doc = wrw.DownloadItemInformation(int.Parse(TokenId));

                        TokenType = doc.SelectSingleNode("/page/itemInfo/item").Attributes["name"].Value;

                        _tokenMap[TokenId] = TokenType;
                    }
                }
                subNodeA = doc.SelectSingleNode("/page/itemInfo/item/cost/@arena");
                if (subNodeA != null)
                {
                    PointsA    = int.Parse(subNodeA.InnerText);
                    PointTypeA = "Arena";
                }
            }
            else if (subNodeH != null)
            {
                Points    = int.Parse(subNodeH.InnerText);
                PointType = "Honor";
                subNodeH  = doc.SelectSingleNode("/page/itemInfo/item/cost/token/@count");
                if (subNodeH != null)
                {
                    TokenCount = int.Parse(subNodeH.InnerText);
                    TokenId    = doc.SelectSingleNode("/page/itemInfo/item/cost/token").Attributes["id"].Value;

                    if (_tokenMap.ContainsKey(TokenId))
                    {
                        TokenType = _tokenMap[TokenId];
                    }
                    else
                    {
                        WebRequestWrapper wrw = new WebRequestWrapper();
                        doc = wrw.DownloadItemInformation(int.Parse(TokenId));

                        TokenType = doc.SelectSingleNode("/page/itemInfo/item").Attributes["name"].Value;

                        _tokenMap[TokenId] = TokenType;
                    }
                }
            }
            else if (subNodeA != null)
            {
                Points    = int.Parse(subNodeA.InnerText);
                PointType = "Arena";
                subNodeH  = doc.SelectSingleNode("/page/itemInfo/item/cost/token/@count");
                if (subNodeH != null)
                {
                    TokenCount = int.Parse(subNodeH.InnerText);
                    TokenId    = doc.SelectSingleNode("/page/itemInfo/item/cost/token").Attributes["id"].Value;

                    if (_tokenMap.ContainsKey(TokenId))
                    {
                        TokenType = _tokenMap[TokenId];
                    }
                    else
                    {
                        WebRequestWrapper wrw2 = new WebRequestWrapper();
                        doc = wrw2.DownloadItemInformation(int.Parse(TokenId));

                        TokenType = doc.SelectSingleNode("/page/itemInfo/item").Attributes["name"].Value;

                        _tokenMap[TokenId] = TokenType;
                    }
                }
            }
            else if (vendorList.Count > 0)
            {
                VendorName = vendorList[0].Attributes["name"].Value;
                VendorArea = vendorList[0].Attributes["area"].Value;
            }
            if (string.IsNullOrEmpty(PointType))
            {
                PointType = "Unknown";
            }
            return(this);
        }
Example #15
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 #16
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;
        }
Example #17
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 #18
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 #19
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;
		}