コード例 #1
0
        /// <summary>
        /// Write asset data files to the given archive
        /// </summary>
        /// <param name="archive"></param>
        protected void WriteData(TarArchiveWriter archive)
        {
            // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar
            //archive.AddDir("assets");

            int assetsAdded = 0;

            foreach (UUID uuid in m_assets.Keys)
            {
                Asset asset = m_assets[uuid];

                string extension = string.Empty;

                if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.AssetType))
                {
                    extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.AssetType];
                }
                else
                {
                    Logger.Log(String.Format(
                        "Unrecognized asset type {0} with uuid {1}.  This asset will be saved but not reloaded",
                        asset.AssetType, asset.AssetID), Helpers.LogLevel.Warning);
                }

                asset.Encode();

                archive.WriteFile(
                    ArchiveConstants.ASSETS_PATH + uuid.ToString() + extension,
                    asset.AssetData);

                assetsAdded++;
            }
        }
コード例 #2
0
        public static void PackageArchive(string directoryName, string filename)
        {
            const string ARCHIVE_XML = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<archive major_version=\"0\" minor_version=\"1\" />";

            TarArchiveWriter archive = new TarArchiveWriter(new GZipStream(new FileStream(filename, FileMode.Create), CompressionMode.Compress));

            // Create the archive.xml file
            archive.WriteFile("archive.xml", ARCHIVE_XML);

            // Add the assets
            string[] files = Directory.GetFiles(directoryName + "/" + ArchiveConstants.ASSETS_PATH);
            foreach (string file in files)
                archive.WriteFile(ArchiveConstants.ASSETS_PATH + Path.GetFileName(file), File.ReadAllBytes(file));

            // Add the objects
            files = Directory.GetFiles(directoryName + "/" + ArchiveConstants.OBJECTS_PATH);
            foreach (string file in files)
                archive.WriteFile(ArchiveConstants.OBJECTS_PATH + Path.GetFileName(file), File.ReadAllBytes(file));

            // Add the terrain(s)
            files = Directory.GetFiles(directoryName + "/" + ArchiveConstants.TERRAINS_PATH);
            foreach (string file in files)
                archive.WriteFile(ArchiveConstants.TERRAINS_PATH + Path.GetFileName(file), File.ReadAllBytes(file));

            // Add the parcels(s)
            files = Directory.GetFiles(directoryName + "/" + ArchiveConstants.LANDDATA_PATH);
            foreach (string file in files)
                archive.WriteFile(ArchiveConstants.LANDDATA_PATH + Path.GetFileName(file), File.ReadAllBytes(file));

            // Add the setting(s)
            files = Directory.GetFiles(directoryName + "/" + ArchiveConstants.SETTINGS_PATH);
            foreach (string file in files)
                archive.WriteFile(ArchiveConstants.SETTINGS_PATH + Path.GetFileName(file), File.ReadAllBytes(file));

            archive.Close();
        }
コード例 #3
0
        /// <summary>
        /// Write an assets metadata file to the given archive
        /// </summary>
        /// <param name="archive"></param>
        protected void WriteMetadata(TarArchiveWriter archive)
        {
            StringWriter sw = new StringWriter();
            using (XmlTextWriter xtw = new XmlTextWriter(sw))
            {
                xtw.Formatting = Formatting.Indented;
                xtw.WriteStartDocument();

                xtw.WriteStartElement("assets");

                foreach (UUID uuid in m_assets.Keys)
                {
                    Asset asset = m_assets[uuid];

                    if (asset != null)
                    {
                        xtw.WriteStartElement("asset");

                        string extension = string.Empty;

                        if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.AssetType))
                        {
                            extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.AssetType];
                        }

                        xtw.WriteElementString("filename", uuid.ToString() + extension);

                        xtw.WriteElementString("name", uuid.ToString());
                        xtw.WriteElementString("description", String.Empty);
                        xtw.WriteElementString("asset-type", asset.AssetType.ToString());

                        xtw.WriteEndElement();
                    }
                }

                xtw.WriteEndElement();
                xtw.WriteEndDocument();
                archive.WriteFile("assets.xml", sw.ToString());
            }
        }