Esempio n. 1
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 + "/assets");
            foreach (string file in files)
                archive.WriteFile("assets/" + Path.GetFileName(file), File.ReadAllBytes(file));

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

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

            archive.Close();
        }
Esempio n. 2
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();
            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());
        }
Esempio n. 3
0
 /// <summary>
 /// Archive the assets given to this archiver to the given archive.
 /// </summary>
 /// <param name="archive"></param>
 public void Archive(TarArchiveWriter archive)
 {
     //WriteMetadata(archive);
     WriteData(archive);
 }
Esempio n. 4
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(
                        "[ARCHIVER]: 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++;
            }
        }