Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private Stream OpenTextureStream(string texFilename)
 {
     return(Storage4.TextureFileOpenRead(texFilename));
 }