Bricklayer.Client.IO.LoadContentPacks C# (CSharp) Method

LoadContentPacks() public static method

Finds content packs and loads the selected one
public static LoadContentPacks ( Game game ) : void
game Game
return void
        public static void LoadContentPacks(Game game)
        {
            try
            {
                //Load Content Packs
                List<string> dirs = new List<string>();
                //Load embedded pack directories from Content folder
                dirs.Add(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Content\\Content Packs\\Default");
                //Load packs from Zarknorth folder
                dirs.AddRange(Directory.GetDirectories(Directories["Content Packs"]).ToList<string>());

                //Foreach directory
                for (int x = 0; x < dirs.Count(); x++)
                {
                    string dir = dirs[x];

                    //Load the packs xml data
                    XmlDocument doc = new XmlDocument();
                    doc.Load(dir + "\\pack.xml");

                    //Create the new pack and set it's data
                    ContentPack pack = new ContentPack();
                    pack.Name = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].Value;
                    pack.Description = doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].Value;
                    pack.Version = doc.ChildNodes[1].ChildNodes[2].ChildNodes[0].Value;
                    pack.Author = doc.ChildNodes[1].ChildNodes[3].ChildNodes[0].Value;
                    pack.Path = dir;
                    pack.Embedded = pack.Name == "Default";

                    //If an embedded pack, load from ContentManager, else FromStream
                    if (pack.Embedded)
                        pack.Icon = Game.TextureLoader.Content.Load<Texture2D>("Content\\Content Packs\\" + pack.Name + "\\icon");
                    else
                        using (FileStream fileStream = new FileStream(dir + "\\icon.png", FileMode.Open))
                            pack.Icon = Texture2D.FromStream(game.GraphicsDevice, fileStream);

                    //Add the pack
                    ContentPacks.Add(pack);

                    //If this pack is the current pack, set the game's data to it, so it is aware of the pack to use
                    if (pack.Name == Game.ContentPackName)
                    {
                        Game.ContentPackIndex = x;
                        Game.ContentPackData = pack;
                    }
                }
                //Load the current pack
                ContentPack.LoadPack(Game.ContentPackData);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }