Ejemplo n.º 1
0
        internal GameInstaller(LolGame game)
        {
            if (!Directory.Exists(game.local))
            {
                MessageBoxResult result = MessageBox.Show(
                    string.Format(
                        "The folder {0} doesn't exists. Do you want to create it?",
                        game.local
                    ),
                    "Error", MessageBoxButton.OKCancel
                );
                if (result == MessageBoxResult.Cancel)
                    throw new Exception("Stopped downloading, dir doesn't exist"); ;
                Directory.CreateDirectory(game.local);
            }

            this.game = game;
            foreach (string url in game.urls)
            {
                this.baseUrls.Add(url.Substring(0, url.LastIndexOf('/') + 1));
            }

            //Error check
            this.game.local = (new FileInfo(this.game.local + Path.DirectorySeparatorChar)).FullName;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The background task for reloading the gamelist
        /// </summary>
        void DownloadAllGameInfo(object sender, DoWorkEventArgs e)
        {
            WebClient client = new WebClient();

            foreach (ServerGameList server in this.serverList)
            {
                if (server.status != null && server.status != "Online")
                    continue;

                foreach (string dir in server.dirs)
                {
                    LolGame game = new LolGame();
                    game.status = "OK";

                    string url = server.url.Substring(0, server.url.LastIndexOf("/") + 1) + dir;
                    XmlElement root;

                    game.urls = new List<string>();
                    game.urls.Add(url);

                    Int64 size = 0;

                    try
                    {
                        string result = client.DownloadString(new Uri(url));

                        //Parse the xml
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(result);
                        root = doc.DocumentElement;

                        if (root.Name != "install")
                        {
                            throw new Exception("XML root must be 'install'");
                        }
                        if (root.Attributes["version"].Value != "1.1")
                        {
                            throw new Exception("Error, version of XML file is wrong");
                        }

                        //Count the total size
                        foreach (XmlNode node in root.ChildNodes)
                        {
                            if (node.Name == "name")
                                game.name = node.InnerText;

                            if (node.Name == "files")
                            {
                                foreach (XmlNode child in node.ChildNodes)
                                {
                                    ParseXMLRecursive(child, ref size);
                                }
                            }

                            if (node.Name == "infohash")
                                game.infohash = node.InnerText;

                            if (node.Name == "icon")
                            {
                                XmlAttribute att = node.Attributes["compression"];
                                game.icon = Convert.FromBase64String(node.InnerText);

                                if (att != null && att.InnerText == "gzip")
                                {
                                    game.icon = GzipUtils.Decompress(game.icon);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        game.status = ex.Message;
                    }

                    if (game.infohash == null)
                    {
                        game.status = "Error, no infohash";
                    }

                    game.size = size;

                    //Add the game to the gamelist
                    //If it is already there, add the infohash
                    LolGame previous = null;
                    if (game.status == "OK")
                    {
                        foreach (LolGame g in this.gameList)
                        {
                            if (g.infohash == game.infohash)
                            {
                                previous = g;
                                break;
                            }
                        }
                    }

                    if (previous != null)
                    {
                        this.gameList.Remove(previous);
                        previous.urls.Add(game.urls[0]);
                        this.gameList.Add(previous);
                    }
                    else
                        this.gameList.Add(game);
                }
            }

            //When tha gamelist is refreshed, the queue refresh is easy!
            RefreshGameQueue();
        }
Ejemplo n.º 3
0
        private IEnumerable<LolGame> GetGames(IEnumerable<LolGame> gameList, string fileName)
        {
            foreach (string line in File.ReadAllText(fileName).Split('\0'))
            {
                if (line.Length == 0)
                    continue;
                string hash = line.Substring(0, line.IndexOf('\t'));
                string localName = line.Remove(0, line.IndexOf('\t') + 1);

                //Search for infohash
                IEnumerable<LolGame> selection = from s in gameList
                                                 where s.infohash == hash
                                                 select s;
                if (selection.Count<LolGame>() != 1)
                {
                    LolGame item = new LolGame();
                    item.name = "Error, no or multiple games";
                    item.status = "Error";
                    yield return item;
                }
                else
                {
                    LolGame game = selection.First<LolGame>();
                    game.local = localName;
                    yield return game;
                }
            }
        }