diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs | 150 |
1 files changed, 71 insertions, 79 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs index 29d7c5e..0c01cae 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsArchiver.cs | |||
@@ -46,114 +46,106 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
46 | /// <value> | 46 | /// <value> |
47 | /// Post a message to the log every x assets as a progress bar | 47 | /// Post a message to the log every x assets as a progress bar |
48 | /// </value> | 48 | /// </value> |
49 | private static int LOG_ASSET_LOAD_NOTIFICATION_INTERVAL = 50; | 49 | protected static int LOG_ASSET_LOAD_NOTIFICATION_INTERVAL = 50; |
50 | 50 | ||
51 | /// <summary> | 51 | /// <value> |
52 | /// Archive assets | 52 | /// Keep a count of the number of assets written so that we can provide status updates |
53 | /// </summary> | 53 | /// </value> |
54 | protected IDictionary<UUID, AssetBase> m_assets; | 54 | protected int m_assetsWritten; |
55 | |||
56 | protected TarArchiveWriter m_archiveWriter; | ||
55 | 57 | ||
56 | public AssetsArchiver(IDictionary<UUID, AssetBase> assets) | 58 | public AssetsArchiver(TarArchiveWriter archiveWriter) |
57 | { | 59 | { |
58 | m_assets = assets; | 60 | m_archiveWriter = archiveWriter; |
59 | } | 61 | } |
60 | 62 | ||
61 | /// <summary> | 63 | /// <summary> |
62 | /// Archive the assets given to this archiver to the given archive. | 64 | /// Archive the assets given to this archiver to the given archive. |
63 | /// </summary> | 65 | /// </summary> |
64 | /// <param name="archive"></param> | 66 | /// <param name="archive"></param> |
65 | public void Archive(TarArchiveWriter archive) | 67 | public void WriteAsset(AssetBase asset) |
66 | { | 68 | { |
67 | //WriteMetadata(archive); | 69 | //WriteMetadata(archive); |
68 | WriteData(archive); | 70 | WriteData(asset); |
69 | } | 71 | } |
70 | 72 | ||
71 | /// <summary> | 73 | /// <summary> |
72 | /// Write an assets metadata file to the given archive | 74 | /// Write an assets metadata file to the given archive |
73 | /// </summary> | 75 | /// </summary> |
74 | /// <param name="archive"></param> | 76 | /// <param name="archive"></param> |
75 | protected void WriteMetadata(TarArchiveWriter archive) | 77 | // protected void WriteMetadata(TarArchiveWriter archive) |
76 | { | 78 | // { |
77 | StringWriter sw = new StringWriter(); | 79 | // StringWriter sw = new StringWriter(); |
78 | XmlTextWriter xtw = new XmlTextWriter(sw); | 80 | // XmlTextWriter xtw = new XmlTextWriter(sw); |
79 | 81 | // | |
80 | xtw.Formatting = Formatting.Indented; | 82 | // xtw.Formatting = Formatting.Indented; |
81 | xtw.WriteStartDocument(); | 83 | // xtw.WriteStartDocument(); |
82 | 84 | // | |
83 | xtw.WriteStartElement("assets"); | 85 | // xtw.WriteStartElement("assets"); |
84 | 86 | // | |
85 | foreach (UUID uuid in m_assets.Keys) | 87 | // foreach (UUID uuid in m_assets.Keys) |
86 | { | 88 | // { |
87 | AssetBase asset = m_assets[uuid]; | 89 | // AssetBase asset = m_assets[uuid]; |
88 | 90 | // | |
89 | if (asset != null) | 91 | // if (asset != null) |
90 | { | 92 | // { |
91 | xtw.WriteStartElement("asset"); | 93 | // xtw.WriteStartElement("asset"); |
92 | 94 | // | |
93 | string extension = string.Empty; | 95 | // string extension = string.Empty; |
94 | 96 | // | |
95 | if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type)) | 97 | // if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type)) |
96 | { | 98 | // { |
97 | extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type]; | 99 | // extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type]; |
98 | } | 100 | // } |
99 | 101 | // | |
100 | xtw.WriteElementString("filename", uuid.ToString() + extension); | 102 | // xtw.WriteElementString("filename", uuid.ToString() + extension); |
101 | 103 | // | |
102 | xtw.WriteElementString("name", asset.Name); | 104 | // xtw.WriteElementString("name", asset.Name); |
103 | xtw.WriteElementString("description", asset.Description); | 105 | // xtw.WriteElementString("description", asset.Description); |
104 | xtw.WriteElementString("asset-type", asset.Type.ToString()); | 106 | // xtw.WriteElementString("asset-type", asset.Type.ToString()); |
105 | 107 | // | |
106 | xtw.WriteEndElement(); | 108 | // xtw.WriteEndElement(); |
107 | } | 109 | // } |
108 | } | 110 | // } |
109 | 111 | // | |
110 | xtw.WriteEndElement(); | 112 | // xtw.WriteEndElement(); |
111 | 113 | // | |
112 | xtw.WriteEndDocument(); | 114 | // xtw.WriteEndDocument(); |
113 | 115 | // | |
114 | archive.WriteFile("assets.xml", sw.ToString()); | 116 | // archive.WriteFile("assets.xml", sw.ToString()); |
115 | } | 117 | // } |
116 | 118 | ||
117 | /// <summary> | 119 | /// <summary> |
118 | /// Write asset data files to the given archive | 120 | /// Write asset data files to the given archive |
119 | /// </summary> | 121 | /// </summary> |
120 | /// <param name="archive"></param> | 122 | /// <param name="asset"></param> |
121 | protected void WriteData(TarArchiveWriter archive) | 123 | protected void WriteData(AssetBase asset) |
122 | { | 124 | { |
123 | // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar | 125 | // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar |
124 | //archive.AddDir("assets"); | 126 | //archive.AddDir("assets"); |
125 | 127 | ||
126 | int assetsAdded = 0; | 128 | string extension = string.Empty; |
127 | 129 | ||
128 | foreach (UUID uuid in m_assets.Keys) | 130 | if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type)) |
129 | { | 131 | { |
130 | AssetBase asset = m_assets[uuid]; | 132 | extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type]; |
131 | 133 | } | |
132 | string extension = string.Empty; | 134 | else |
133 | 135 | { | |
134 | if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type)) | 136 | m_log.ErrorFormat( |
135 | { | 137 | "[ARCHIVER]: Unrecognized asset type {0} with uuid {1}. This asset will be saved but not reloaded", |
136 | extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type]; | 138 | asset.Type, asset.ID); |
137 | } | 139 | } |
138 | else | ||
139 | { | ||
140 | m_log.ErrorFormat( | ||
141 | "[ARCHIVER]: Unrecognized asset type {0} with uuid {1}. This asset will be saved but not reloaded", | ||
142 | asset.Type, asset.ID); | ||
143 | } | ||
144 | |||
145 | archive.WriteFile( | ||
146 | ArchiveConstants.ASSETS_PATH + uuid.ToString() + extension, | ||
147 | asset.Data); | ||
148 | 140 | ||
149 | assetsAdded++; | 141 | m_archiveWriter.WriteFile( |
142 | ArchiveConstants.ASSETS_PATH + asset.FullID.ToString() + extension, | ||
143 | asset.Data); | ||
150 | 144 | ||
151 | if (assetsAdded % LOG_ASSET_LOAD_NOTIFICATION_INTERVAL == 0) | 145 | m_assetsWritten++; |
152 | m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", assetsAdded); | ||
153 | } | ||
154 | 146 | ||
155 | if (assetsAdded % LOG_ASSET_LOAD_NOTIFICATION_INTERVAL != 0) | 147 | if (m_assetsWritten % LOG_ASSET_LOAD_NOTIFICATION_INTERVAL == 0) |
156 | m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", assetsAdded); | 148 | m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", m_assetsWritten); |
157 | } | 149 | } |
158 | } | 150 | } |
159 | } | 151 | } |