/// <summary>
        /// Loads Actors.xml and initializes the list of static actors.
        /// </summary>
        /// <remarks>
        /// The actors' model and xml file isn't loaded until LoadModels is called.
        /// </remarks>
        public static void LoadActors()
        {
            if (Storage4.FileExists(XmlActorsListFileName, StorageSource.TitleSpace))
            {
                // Read our actor list from file
                var stream     = Storage4.OpenRead(XmlActorsListFileName, StorageSource.TitleSpace);
                var serializer = new XmlSerializer(typeof(XmlActorsList));
                var xmlActors  = serializer.Deserialize(stream) as XmlActorsList;
                Storage4.Close(stream);

                if (xmlActors != null)
                {
                    for (int i = 0; i < xmlActors.Actors.Length; i++)
                    {
                        var xmlStaticActor = xmlActors.Actors[i];
                        Actors.Add(xmlStaticActor.NonLocalizedName, new StaticActor(xmlStaticActor));
                    }
                }
            }
            else
            {
                Debug.Assert(false, "Missing actor file.");
            }
        }
        public static BokuShared.Wire.WorldPacket ReadWorldPacketFromDisk(string worldFullPathAndName, string bucket)
        {
            BokuShared.Wire.WorldPacket packet = null;
            Stream file = null;

            try
            {
                string localLevelPath = BokuGame.Settings.MediaPath + bucket;
                string worldFilename  = Path.GetFileName(worldFullPathAndName);

                // Read contents of world xml to retrieve the names of the dependent
                // files we need to upload
                Xml.XmlWorldData xmlWorldData = XmlWorldData.Load(localLevelPath + worldFilename, XnaStorageHelper.Instance);
                if (xmlWorldData == null)
                {
                    return(null);
                }

                // Clear virtual genre bits in case they got saved (server clears them too).
                xmlWorldData.genres &= ~(int)Genres.Virtual;

                packet = new BokuShared.Wire.WorldPacket();
                packet.Info.WorldId     = packet.Data.WorldId = xmlWorldData.id;
                packet.Info.Name        = xmlWorldData.name;
                packet.Info.Description = xmlWorldData.description;
                packet.Info.Creator     = xmlWorldData.creator;
                packet.Info.IdHash      = "";
                packet.Info.Genres      = xmlWorldData.genres;

                string imageFileName = xmlWorldData.GetImageFilenameWithoutExtension();

                // VirtualMap
                file = Storage4.OpenRead(BokuGame.Settings.MediaPath + xmlWorldData.xmlTerrainData2.virtualMapFile, StorageSource.All);
                packet.Data.VirtualMapBytes = new byte[file.Length];
                file.Read(packet.Data.VirtualMapBytes, 0, (int)file.Length);
                Storage4.Close(file);

                // Stuff xml
                file = Storage4.OpenRead(BokuGame.Settings.MediaPath + xmlWorldData.stuffFilename, StorageSource.All);
                packet.Data.StuffXmlBytes = new byte[file.Length];
                file.Read(packet.Data.StuffXmlBytes, 0, (int)file.Length);
                Storage4.Close(file);

                // Optional: don't worry if we don't have a thumbnail image.
                try
                {
                    file = null;
                    file = Storage4.TextureFileOpenRead(localLevelPath + imageFileName);

                    if (file != null)
                    {
                        packet.Info.ThumbnailBytes = new byte[file.Length];
                        file.Read(packet.Info.ThumbnailBytes, 0, (int)file.Length);
                        Storage4.Close(file);
                    }
                }
                catch { }


                // Try To load Snapshot image.
                try
                {
                    file = null;
                    file = Storage4.TextureFileOpenRead(localLevelPath + imageFileName, Storage4.TextureFileType.jpg);

                    if (file != null)
                    {
                        packet.Info.ScreenshotBytes = new byte[file.Length];
                        file.Read(packet.Info.ScreenshotBytes, 0, (int)file.Length);
                        Storage4.Close(file);
                    }
                }
                catch { }


                // We've successfully read all required files. We may now upload them to the server.
                file = Storage4.OpenRead(localLevelPath + worldFilename, StorageSource.All);
                packet.Data.WorldXmlBytes = new byte[file.Length];
                file.Read(packet.Data.WorldXmlBytes, 0, (int)file.Length);
                Storage4.Close(file);

                Instrumentation.RecordEvent(Instrumentation.EventId.LevelUploaded, xmlWorldData.name);
            }
            catch
            {
                if (file != null)
                {
                    Storage4.Close(file);
                }
                packet = null;
            }

            return(packet);
        }
        }   // end of XmlHelpTextData ReadFromXml()

        private static XmlHelpTextData Load(string filename)
        {
            XmlHelpTextData data   = null;
            Stream          stream = null;

            // First try with StorageSoruce.All so we get the version downloaded
            // from the servers.  If that fails then get the TitleSpace version.
            try
            {
                stream = Storage4.OpenRead(filename, StorageSource.All);

                XmlSerializer serializer = new XmlSerializer(typeof(XmlHelpTextData));
                data = (XmlHelpTextData)serializer.Deserialize(stream);
            }
            catch (Exception e)
            {
                data = null;
                if (e != null)
                {
#if !NETFX_CORE
                    string message = e.Message;
                    if (e.InnerException != null)
                    {
                        message += e.InnerException.Message;
                    }
                    System.Windows.Forms.MessageBox.Show(
                        message,
                        "Error reading " + filename,
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Error
                        );
#endif
                }
            }
            finally
            {
                Storage4.Close(stream);
            }

            // If we don't have data.  Delete the server version of
            // the file and try loading the TitleSpace version.
            if (data == null)
            {
                // Don't delete the server version since this might actually be someone
                // trying to do a localization.
                //Storage4.Delete(filename);

                try
                {
                    stream = Storage4.OpenRead(filename, StorageSource.TitleSpace);

                    XmlSerializer serializer = new XmlSerializer(typeof(XmlHelpTextData));
                    data = (XmlHelpTextData)serializer.Deserialize(stream);
                }
                catch (Exception)
                {
                    data = null;
                }
                finally
                {
                    Storage4.Close(stream);
                }
            }

            return(data);
        } // end of XmlHelpTextData Load()
 public override Stream OpenRead(string filename, int flags)
 {
     return(Storage4.OpenRead(filename, (StorageSource)flags));
 }
 public override Stream OpenRead(string filename)
 {
     return(Storage4.OpenRead(filename, StorageSource.All));
 }