示例#1
0
        public static List <Bitmap> getScreens(ScriptableScraper scraper, Dictionary <string, string> paramList, out Bitmap title, out Bitmap inGame, Conf_OnlineLookup.onProgress progress, int progressStart, int progressEnd, bool unattended)
        {
            List <Bitmap> imageResults = new List <Bitmap>();

            title  = null;
            inGame = null;

            if (scraper == null)
            {
                return(imageResults);
            }

            Dictionary <string, string> results;

            results = scraper.Execute("get_screenshots", paramList);

            if (results == null)
            {
                return(imageResults);
            }

            string screens            = "";
            string screenshotsbaseurl = "";

            results.TryGetValue("game.screenshotsbaseurl", out screenshotsbaseurl);

            if (results.TryGetValue("game.screenshots", out screens))
            {
                string[] screenurls       = screens.Split('|');
                bool     foundTitleScreen = false;
                bool     foundInGame      = false;

                int increment = progressEnd - progressStart;
                if (screenurls.Length > 0)
                {
                    increment = (int)Math.Floor(increment / (double)screenurls.Length);
                }

                for (int i = 1; i < screenurls.Length; i++)
                {
                    progressStart += increment;
                    progress.Invoke(string.Format("Getting screenshot {0}/{1}...", i.ToString(), screenurls.Length.ToString()), progressStart);

                    if (!screenurls[i].ToLower().StartsWith("http://"))
                    {
                        screenurls[i] = screenshotsbaseurl + screenurls[i];
                    }

                    bool isTitle  = false;
                    bool isInGame = false;

                    if (!foundTitleScreen || !foundInGame)
                    {
                        if (screenurls[i].Contains("screenshot-start-screen"))
                        {
                            isTitle          = true;
                            foundTitleScreen = true;
                        }
                        else if (screenurls[i].Contains("screenshot-title-screen"))
                        {
                            if (!foundTitleScreen)
                            {
                                isTitle = true;
                            }
                        }
                        else if (title == null)
                        {
                            isTitle = true;
                        }
                        else if (inGame == null)
                        {
                            isInGame    = true;
                            foundInGame = true;
                        }
                    }

                    if (unattended) //only download image if we need to
                    {
                        if (isTitle)
                        {
                            title = ImageHandler.Instance.BitmapFromWeb(screenurls[i]);
                        }
                        else if (isInGame)
                        {
                            inGame = ImageHandler.Instance.BitmapFromWeb(screenurls[i]);
                        }
                        if (foundInGame && foundTitleScreen) //best matches found, no point in continuing search
                        {
                            break;
                        }
                    }
                    else //if not unattended then download all images to allow user selection
                    {
                        Bitmap thePic = ImageHandler.Instance.BitmapFromWeb(screenurls[i]);
                        imageResults.Add(thePic);
                        if (isTitle)
                        {
                            title = thePic;
                        }
                        else if (isInGame)
                        {
                            inGame = thePic;
                        }
                    }
                }
            }

            return(imageResults);
        }
示例#2
0
        public static List <Bitmap> getCovers(ScriptableScraper scraper, Dictionary <string, string> paramList, out Bitmap front, out Bitmap back, Conf_OnlineLookup.onProgress progress, int progressStart, int progressEnd, bool unattended)
        {
            List <Bitmap> imageResults = new List <Bitmap>();

            front = null;
            back  = null;

            if (scraper == null)
            {
                return(imageResults);
            }

            Dictionary <string, string> results = scraper.Execute("get_cover_art", paramList);

            if (results == null)
            {
                return(imageResults);
            }

            string covers = "";

            if (results.TryGetValue("game.covers", out covers))
            {
                string[] coverurls = covers.Split('|');

                //calculate percentage increment for progress bar based on number of results
                int increment = progressEnd - progressStart;
                if (coverurls.Length > 0)
                {
                    increment = (int)Math.Floor(increment / (double)coverurls.Length);
                }

                for (int i = 1; i < coverurls.Length; i++)
                {
                    progressStart += increment;
                    progress.Invoke(string.Format("Getting cover art {0}/{1}...", i.ToString(), coverurls.Length.ToString()), progressStart);

                    bool isFront = false;
                    bool isBack  = false;
                    //Bitmap pic = ImageHandler.Instance.BitmapFromWeb(coverurls[i]);
                    //imageResults.Add(pic);

                    if (i == 1)
                    {
                        isFront = true;
                    }
                    else if (i == 2)
                    {
                        isBack = true;
                    }

                    if (unattended)
                    {
                        if (isFront)
                        {
                            front = ImageHandler.Instance.BitmapFromWeb(coverurls[i]);
                        }
                        else if (isBack)
                        {
                            back = ImageHandler.Instance.BitmapFromWeb(coverurls[i]);
                        }
                        //no point in getting additional thumbs as import is unattended
                        if (front != null && back != null)
                        {
                            break;
                        }
                    }
                    else
                    {
                        Bitmap thePic = ImageHandler.Instance.BitmapFromWeb(coverurls[i]);
                        imageResults.Add(thePic);
                        if (isFront)
                        {
                            front = thePic;
                        }
                        else if (isBack)
                        {
                            back = thePic;
                        }
                    }
                }
            }

            return(imageResults);
        }