Ejemplo n.º 1
0
        /// <summary>
        /// Update the level's xml on disk.
        /// Does not change the level's timestamp.
        /// </summary>
        /// <param name="level"></param>
        public static void UpdateWorldXml(XmlWorldData xml)
        {
            try
            {
                string bucket = Utils.FolderNameFromFlags((Genres)xml.genres);

                string fullPath = BokuGame.Settings.MediaPath + bucket + xml.id.ToString() + @".Xml";

                //make sure the world exists
                if (!Storage4.FileExists(fullPath, StorageSource.All))
                {
                    return;
                }

                if (xml != null)
                {
                    bool isDownload = (xml.genres & (int)Genres.Downloads) != 0;

                    // Manage the stream ourselves so avoid level timestamp being changed.
                    Stream stream = Storage4.OpenWrite(fullPath);
                    xml.Save(stream, isDownload);
                    Storage4.Close(stream);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the level's metadata on disk.
        /// Does not change the level's timestamp.
        /// </summary>
        /// <param name="level"></param>
        public static void UpdateWorldMetadata(LevelMetadata level)
        {
            try
            {
                string bucket = Utils.FolderNameFromFlags(level.Genres);

                string fullPath = BokuGame.Settings.MediaPath + bucket + level.WorldId.ToString() + @".Xml";

                Xml.XmlWorldData xml = XmlWorldData.Load(fullPath, XnaStorageHelper.Instance);
                if (xml != null)
                {
                    level.ToXml(xml);

                    bool isDownload = (level.Genres & Genres.Downloads) != 0;

                    // Manage the stream ourselves so avoid level timestamp being changed.
                    Stream stream = Storage4.OpenWrite(fullPath);
                    xml.Save(stream, isDownload);
                    Storage4.Close(stream);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Ejemplo n.º 3
0
        static public bool TextureSaveAsPng(Texture2D tex, string name)
        {
            if (tex != null)
            {
                Stream stream = Storage4.OpenWrite(name);
                tex.SaveAsPng(stream, tex.Width, tex.Height);
                stream.Close();

                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static bool WriteWorldDataPacketToDisk(BokuShared.Wire.WorldDataPacket packet, byte[] thumbnailBytes, DateTime timeStamp)
        {
            Stream file = null;

            try
            {
                // Check for presence of the essential world data
                if (packet == null)
                {
                    return(false);
                }
                if (packet.WorldXmlBytes == null)
                {
                    return(false);
                }
                if (packet.StuffXmlBytes == null)
                {
                    return(false);
                }

                // Read in contents of world xml buffer
                Xml.XmlWorldData xmlWorldData = Xml.XmlWorldData.Load(packet.WorldXmlBytes);
                if (xmlWorldData == null)
                {
                    return(false);
                }

                xmlWorldData.overrideLastWriteTime = timeStamp;

                xmlWorldData.id            = packet.WorldId;
                xmlWorldData.stuffFilename = BokuGame.DownloadsStuffPath + xmlWorldData.Filename;

                // Non-essential file: Write thumbnail image to disk
                if (thumbnailBytes != null)
                {
                    string ext           = Storage4.TextureExt(thumbnailBytes);
                    string thumbFilename = xmlWorldData.GetImageFilenameWithoutExtension() + "." + ext;
                    file = Storage4.OpenWrite(BokuGame.Settings.MediaPath + BokuGame.DownloadsPath + thumbFilename);
                    file.Write(thumbnailBytes, 0, thumbnailBytes.Length);
                    Storage4.Close(file);
                    file = null;
                }

                // Cubeworld virtual terrain map
                if (packet.VirtualMapBytes != null)
                {
                    file = Storage4.OpenWrite(BokuGame.Settings.MediaPath + xmlWorldData.xmlTerrainData2.virtualMapFile);
                    file.Write(packet.VirtualMapBytes, 0, packet.VirtualMapBytes.Length);
                    Storage4.Close(file);
                    file = null;
                }

                // Write stuff xml to disk
                file = Storage4.OpenWrite(BokuGame.Settings.MediaPath + xmlWorldData.stuffFilename);
                file.Write(packet.StuffXmlBytes, 0, packet.StuffXmlBytes.Length);
                Storage4.Close(file);
                file = null;

                // Clear virtual genre bits because they should not be stored.
                xmlWorldData.genres &= ~(int)Genres.Virtual;
                xmlWorldData.genres &= ~(int)Genres.Favorite;

                // Serialize xmlWorldData to disk
                string fullPath = BokuGame.Settings.MediaPath + BokuGame.DownloadsPath + xmlWorldData.Filename;
                xmlWorldData.Save(fullPath, XnaStorageHelper.Instance);

                Instrumentation.RecordEvent(Instrumentation.EventId.LevelDownloaded, xmlWorldData.name);

                return(true);
            }
            catch
            {
                if (file != null)
                {
                    Storage4.Close(file);
                }

                return(false);
            }
        }
Ejemplo n.º 5
0
 public override Stream OpenWrite(string filename)
 {
     return(Storage4.OpenWrite(filename));
 }