diff options
author | Jeff Ames | 2008-05-28 03:44:49 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-28 03:44:49 +0000 |
commit | 5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4 (patch) | |
tree | ea980f49f1a6bb40ba037a87581a3d741c3d3c56 /OpenSim/Region/Environment/Modules/World/Archiver | |
parent | Thank you kindly, Melanie for a patch that: (diff) | |
download | opensim-SC_OLD-5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4.zip opensim-SC_OLD-5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4.tar.gz opensim-SC_OLD-5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4.tar.bz2 opensim-SC_OLD-5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4.tar.xz |
Formatting cleanup.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs | 68 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs | 82 |
2 files changed, 75 insertions, 75 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs index 1579485..ea74941 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs | |||
@@ -37,37 +37,37 @@ using log4net; | |||
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | 38 | ||
39 | namespace OpenSim.Region.Environment | 39 | namespace OpenSim.Region.Environment |
40 | { | 40 | { |
41 | /// <summary> | 41 | /// <summary> |
42 | /// Method called when all the necessary assets for an archive request have been received. | 42 | /// Method called when all the necessary assets for an archive request have been received. |
43 | /// </summary> | 43 | /// </summary> |
44 | public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets); | 44 | public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets); |
45 | 45 | ||
46 | /// <summary> | 46 | /// <summary> |
47 | /// Handles an individual archive request | 47 | /// Handles an individual archive request |
48 | /// </summary> | 48 | /// </summary> |
49 | public class ArchiveRequest | 49 | public class ArchiveRequest |
50 | { | 50 | { |
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
52 | 52 | ||
53 | private Scene m_scene; | 53 | private Scene m_scene; |
54 | private string m_savePath; | 54 | private string m_savePath; |
55 | 55 | ||
56 | private string m_serializedEntities; | 56 | private string m_serializedEntities; |
57 | 57 | ||
58 | public ArchiveRequest(Scene scene, string savePath) | 58 | public ArchiveRequest(Scene scene, string savePath) |
59 | { | 59 | { |
60 | m_scene = scene; | 60 | m_scene = scene; |
61 | m_savePath = savePath; | 61 | m_savePath = savePath; |
62 | 62 | ||
63 | ArchiveRegion(); | 63 | ArchiveRegion(); |
64 | } | 64 | } |
65 | 65 | ||
66 | protected void ArchiveRegion() | 66 | protected void ArchiveRegion() |
67 | { | 67 | { |
68 | m_log.Warn("[ARCHIVER]: Archive region not yet implemented"); | 68 | m_log.Warn("[ARCHIVER]: Archive region not yet implemented"); |
69 | 69 | ||
70 | Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>(); | 70 | Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>(); |
71 | 71 | ||
72 | List<EntityBase> entities = m_scene.GetEntities(); | 72 | List<EntityBase> entities = m_scene.GetEntities(); |
73 | 73 | ||
@@ -76,14 +76,14 @@ namespace OpenSim.Region.Environment | |||
76 | if (entity is SceneObjectGroup) | 76 | if (entity is SceneObjectGroup) |
77 | { | 77 | { |
78 | SceneObjectGroup sceneObject = (SceneObjectGroup)entity; | 78 | SceneObjectGroup sceneObject = (SceneObjectGroup)entity; |
79 | 79 | ||
80 | foreach (SceneObjectPart part in sceneObject.GetParts()) | 80 | foreach (SceneObjectPart part in sceneObject.GetParts()) |
81 | { | 81 | { |
82 | LLUUID texture = new LLUUID(part.Shape.TextureEntry, 0); | 82 | LLUUID texture = new LLUUID(part.Shape.TextureEntry, 0); |
83 | textureUuids[texture] = 1; | 83 | textureUuids[texture] = 1; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | m_serializedEntities = SerializeObjects(entities); | 88 | m_serializedEntities = SerializeObjects(entities); |
89 | 89 | ||
@@ -91,30 +91,30 @@ namespace OpenSim.Region.Environment | |||
91 | { | 91 | { |
92 | m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count); | 92 | m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count); |
93 | m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count); | 93 | m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count); |
94 | 94 | ||
95 | // Asynchronously request all the assets required to perform this archive operation | 95 | // Asynchronously request all the assets required to perform this archive operation |
96 | new AssetsRequest(ReceivedAllAssets, m_scene.AssetCache, textureUuids.Keys); | 96 | new AssetsRequest(ReceivedAllAssets, m_scene.AssetCache, textureUuids.Keys); |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | protected internal void ReceivedAllAssets(IDictionary<LLUUID, AssetBase> assets) | 100 | protected internal void ReceivedAllAssets(IDictionary<LLUUID, AssetBase> assets) |
101 | { | 101 | { |
102 | m_log.DebugFormat("[ARCHIVER]: Received all {0} textures required", assets.Count); | 102 | m_log.DebugFormat("[ARCHIVER]: Received all {0} textures required", assets.Count); |
103 | 103 | ||
104 | // XXX: Shouldn't hijack the asset async callback thread like this - this is only temporary | 104 | // XXX: Shouldn't hijack the asset async callback thread like this - this is only temporary |
105 | 105 | ||
106 | TarArchive archive = new TarArchive(); | 106 | TarArchive archive = new TarArchive(); |
107 | 107 | ||
108 | archive.AddFile("prims.xml", m_serializedEntities); | 108 | archive.AddFile("prims.xml", m_serializedEntities); |
109 | 109 | ||
110 | foreach (LLUUID uuid in assets.Keys) | 110 | foreach (LLUUID uuid in assets.Keys) |
111 | { | 111 | { |
112 | archive.AddFile(uuid.ToString() + ".jp2", assets[uuid].Data); | 112 | archive.AddFile(uuid.ToString() + ".jp2", assets[uuid].Data); |
113 | } | 113 | } |
114 | 114 | ||
115 | archive.WriteTar(m_savePath); | 115 | archive.WriteTar(m_savePath); |
116 | } | 116 | } |
117 | 117 | ||
118 | /// <summary> | 118 | /// <summary> |
119 | /// Get an xml representation of the given scene objects. | 119 | /// Get an xml representation of the given scene objects. |
120 | /// </summary> | 120 | /// </summary> |
@@ -152,38 +152,38 @@ namespace OpenSim.Region.Environment | |||
152 | /// Callback used when all the assets requested have been received. | 152 | /// Callback used when all the assets requested have been received. |
153 | /// </summary> | 153 | /// </summary> |
154 | protected AssetsRequestCallback m_assetsRequestCallback; | 154 | protected AssetsRequestCallback m_assetsRequestCallback; |
155 | 155 | ||
156 | /// <summary> | 156 | /// <summary> |
157 | /// Assets retrieved in this request | 157 | /// Assets retrieved in this request |
158 | /// </summary> | 158 | /// </summary> |
159 | protected Dictionary<LLUUID, AssetBase> m_assets = new Dictionary<LLUUID, AssetBase>(); | 159 | protected Dictionary<LLUUID, AssetBase> m_assets = new Dictionary<LLUUID, AssetBase>(); |
160 | 160 | ||
161 | /// <summary> | 161 | /// <summary> |
162 | /// Record the number of asset replies required so we know when we've finished | 162 | /// Record the number of asset replies required so we know when we've finished |
163 | /// </summary> | 163 | /// </summary> |
164 | private int m_repliesRequired; | 164 | private int m_repliesRequired; |
165 | 165 | ||
166 | /// <summary> | 166 | /// <summary> |
167 | /// Asset cache used to request the assets | 167 | /// Asset cache used to request the assets |
168 | /// </summary> | 168 | /// </summary> |
169 | protected AssetCache m_assetCache; | 169 | protected AssetCache m_assetCache; |
170 | 170 | ||
171 | protected internal AssetsRequest(AssetsRequestCallback assetsRequestCallback, AssetCache assetCache, ICollection<LLUUID> uuids) | 171 | protected internal AssetsRequest(AssetsRequestCallback assetsRequestCallback, AssetCache assetCache, ICollection<LLUUID> uuids) |
172 | { | 172 | { |
173 | m_assetsRequestCallback = assetsRequestCallback; | 173 | m_assetsRequestCallback = assetsRequestCallback; |
174 | m_assetCache = assetCache; | 174 | m_assetCache = assetCache; |
175 | m_repliesRequired = uuids.Count; | 175 | m_repliesRequired = uuids.Count; |
176 | 176 | ||
177 | // We can stop here if there are no assets to fetch | 177 | // We can stop here if there are no assets to fetch |
178 | if (m_repliesRequired == 0) | 178 | if (m_repliesRequired == 0) |
179 | m_assetsRequestCallback(m_assets); | 179 | m_assetsRequestCallback(m_assets); |
180 | 180 | ||
181 | foreach (LLUUID uuid in uuids) | 181 | foreach (LLUUID uuid in uuids) |
182 | { | 182 | { |
183 | m_assetCache.GetAsset(uuid, AssetRequestCallback, true); | 183 | m_assetCache.GetAsset(uuid, AssetRequestCallback, true); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | /// <summary> | 187 | /// <summary> |
188 | /// Called back by the asset cache when it has the asset | 188 | /// Called back by the asset cache when it has the asset |
189 | /// </summary> | 189 | /// </summary> |
@@ -192,7 +192,7 @@ namespace OpenSim.Region.Environment | |||
192 | public void AssetRequestCallback(LLUUID assetID, AssetBase asset) | 192 | public void AssetRequestCallback(LLUUID assetID, AssetBase asset) |
193 | { | 193 | { |
194 | m_assets[assetID] = asset; | 194 | m_assets[assetID] = asset; |
195 | 195 | ||
196 | if (m_assets.Count == m_repliesRequired) | 196 | if (m_assets.Count == m_repliesRequired) |
197 | { | 197 | { |
198 | m_assetsRequestCallback(m_assets); | 198 | m_assetsRequestCallback(m_assets); |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs index 5e5be34..3a7518c 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs | |||
@@ -34,16 +34,16 @@ using System.Reflection; | |||
34 | using log4net; | 34 | using log4net; |
35 | 35 | ||
36 | namespace OpenSim.Region.Environment | 36 | namespace OpenSim.Region.Environment |
37 | { | 37 | { |
38 | /// <summary> | 38 | /// <summary> |
39 | /// Temporary code to produce a tar archive in tar v7 format | 39 | /// Temporary code to produce a tar archive in tar v7 format |
40 | /// </summary> | 40 | /// </summary> |
41 | public class TarArchive | 41 | public class TarArchive |
42 | { | 42 | { |
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 44 | ||
45 | protected Dictionary<string, byte[]> m_files = new Dictionary<string, byte[]>(); | 45 | protected Dictionary<string, byte[]> m_files = new Dictionary<string, byte[]>(); |
46 | 46 | ||
47 | protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); | 47 | protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); |
48 | 48 | ||
49 | /// <summary> | 49 | /// <summary> |
@@ -55,7 +55,7 @@ namespace OpenSim.Region.Environment | |||
55 | { | 55 | { |
56 | AddFile(filePath, m_asciiEncoding.GetBytes(data)); | 56 | AddFile(filePath, m_asciiEncoding.GetBytes(data)); |
57 | } | 57 | } |
58 | 58 | ||
59 | /// <summary> | 59 | /// <summary> |
60 | /// Add a file to the tar archive | 60 | /// Add a file to the tar archive |
61 | /// </summary> | 61 | /// </summary> |
@@ -65,117 +65,117 @@ namespace OpenSim.Region.Environment | |||
65 | { | 65 | { |
66 | m_files[filePath] = data; | 66 | m_files[filePath] = data; |
67 | } | 67 | } |
68 | 68 | ||
69 | /// <summary> | 69 | /// <summary> |
70 | /// Write the raw tar archive data to a file | 70 | /// Write the raw tar archive data to a file |
71 | /// </summary> | 71 | /// </summary> |
72 | /// <returns></returns> | 72 | /// <returns></returns> |
73 | public void WriteTar(string archivePath) | 73 | public void WriteTar(string archivePath) |
74 | { | 74 | { |
75 | BinaryWriter bw = new BinaryWriter(new FileStream(archivePath, FileMode.Create)); | 75 | BinaryWriter bw = new BinaryWriter(new FileStream(archivePath, FileMode.Create)); |
76 | 76 | ||
77 | foreach (string filePath in m_files.Keys) | 77 | foreach (string filePath in m_files.Keys) |
78 | { | 78 | { |
79 | byte[] header = new byte[512]; | 79 | byte[] header = new byte[512]; |
80 | byte[] data = m_files[filePath]; | 80 | byte[] data = m_files[filePath]; |
81 | 81 | ||
82 | //string filePath = "test.txt"; | 82 | //string filePath = "test.txt"; |
83 | //byte[] data = m_asciiEncoding.GetBytes("hello\n"); | 83 | //byte[] data = m_asciiEncoding.GetBytes("hello\n"); |
84 | 84 | ||
85 | // file path field (100) | 85 | // file path field (100) |
86 | byte[] nameBytes = m_asciiEncoding.GetBytes(filePath); | 86 | byte[] nameBytes = m_asciiEncoding.GetBytes(filePath); |
87 | int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length; | 87 | int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length; |
88 | Array.Copy(nameBytes, header, nameSize); | 88 | Array.Copy(nameBytes, header, nameSize); |
89 | 89 | ||
90 | // file mode (8) | 90 | // file mode (8) |
91 | byte[] modeBytes = m_asciiEncoding.GetBytes("0000644"); | 91 | byte[] modeBytes = m_asciiEncoding.GetBytes("0000644"); |
92 | Array.Copy(modeBytes, 0, header, 100, 7); | 92 | Array.Copy(modeBytes, 0, header, 100, 7); |
93 | 93 | ||
94 | // owner user id (8) | 94 | // owner user id (8) |
95 | byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764"); | 95 | byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764"); |
96 | Array.Copy(ownerIdBytes, 0, header, 108, 7); | 96 | Array.Copy(ownerIdBytes, 0, header, 108, 7); |
97 | 97 | ||
98 | // group user id (8) | 98 | // group user id (8) |
99 | byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764"); | 99 | byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764"); |
100 | Array.Copy(groupIdBytes, 0, header, 116, 7); | 100 | Array.Copy(groupIdBytes, 0, header, 116, 7); |
101 | 101 | ||
102 | // file size in bytes (12) | 102 | // file size in bytes (12) |
103 | int fileSize = data.Length; | 103 | int fileSize = data.Length; |
104 | m_log.DebugFormat("[TAR ARCHIVE]: File size of {0} is {1}", filePath, fileSize); | 104 | m_log.DebugFormat("[TAR ARCHIVE]: File size of {0} is {1}", filePath, fileSize); |
105 | 105 | ||
106 | byte[] fileSizeBytes = ConvertDecimalToPaddedOctalBytes(fileSize, 11); | 106 | byte[] fileSizeBytes = ConvertDecimalToPaddedOctalBytes(fileSize, 11); |
107 | 107 | ||
108 | Array.Copy(fileSizeBytes, 0, header, 124, 11); | 108 | Array.Copy(fileSizeBytes, 0, header, 124, 11); |
109 | 109 | ||
110 | // last modification time (12) | 110 | // last modification time (12) |
111 | byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332"); | 111 | byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332"); |
112 | Array.Copy(lastModTimeBytes, 0, header, 136, 11); | 112 | Array.Copy(lastModTimeBytes, 0, header, 136, 11); |
113 | 113 | ||
114 | // link indicator (1) | 114 | // link indicator (1) |
115 | //header[156] = m_asciiEncoding.GetBytes("0")[0]; | 115 | //header[156] = m_asciiEncoding.GetBytes("0")[0]; |
116 | header[156] = 0; | 116 | header[156] = 0; |
117 | 117 | ||
118 | Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7); | 118 | Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7); |
119 | Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7); | 119 | Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7); |
120 | 120 | ||
121 | // check sum for header block (8) [calculated last] | 121 | // check sum for header block (8) [calculated last] |
122 | Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8); | 122 | Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8); |
123 | 123 | ||
124 | int checksum = 0; | 124 | int checksum = 0; |
125 | foreach (byte b in header) | 125 | foreach (byte b in header) |
126 | { | 126 | { |
127 | checksum += b; | 127 | checksum += b; |
128 | } | 128 | } |
129 | 129 | ||
130 | m_log.DebugFormat("[TAR ARCHIVE]: Decimal header checksum is {0}", checksum); | 130 | m_log.DebugFormat("[TAR ARCHIVE]: Decimal header checksum is {0}", checksum); |
131 | 131 | ||
132 | byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6); | 132 | byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6); |
133 | //byte[] checkSumBytes = m_asciiEncoding.GetBytes("007520"); | 133 | //byte[] checkSumBytes = m_asciiEncoding.GetBytes("007520"); |
134 | 134 | ||
135 | Array.Copy(checkSumBytes, 0, header, 148, 6); | 135 | Array.Copy(checkSumBytes, 0, header, 148, 6); |
136 | 136 | ||
137 | header[154] = 0; | 137 | header[154] = 0; |
138 | 138 | ||
139 | // Write out header | 139 | // Write out header |
140 | bw.Write(header); | 140 | bw.Write(header); |
141 | 141 | ||
142 | // Write out data | 142 | // Write out data |
143 | bw.Write(data); | 143 | bw.Write(data); |
144 | 144 | ||
145 | int paddingRequired = 512 - (data.Length % 512); | 145 | int paddingRequired = 512 - (data.Length % 512); |
146 | if (paddingRequired > 0) | 146 | if (paddingRequired > 0) |
147 | { | 147 | { |
148 | m_log.DebugFormat("Padding data with {0} bytes", paddingRequired); | 148 | m_log.DebugFormat("Padding data with {0} bytes", paddingRequired); |
149 | 149 | ||
150 | byte[] padding = new byte[paddingRequired]; | 150 | byte[] padding = new byte[paddingRequired]; |
151 | bw.Write(padding); | 151 | bw.Write(padding); |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | // Write two consecutive 0 blocks to end the archive | 155 | // Write two consecutive 0 blocks to end the archive |
156 | byte[] finalZeroPadding = new byte[1024]; | 156 | byte[] finalZeroPadding = new byte[1024]; |
157 | bw.Write(finalZeroPadding); | 157 | bw.Write(finalZeroPadding); |
158 | 158 | ||
159 | bw.Close(); | 159 | bw.Close(); |
160 | } | 160 | } |
161 | 161 | ||
162 | public static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding) | 162 | public static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding) |
163 | { | 163 | { |
164 | string oString = ""; | 164 | string oString = ""; |
165 | 165 | ||
166 | while (d > 0) | 166 | while (d > 0) |
167 | { | 167 | { |
168 | oString = Convert.ToString((byte)'0' + d & 7) + oString; | 168 | oString = Convert.ToString((byte)'0' + d & 7) + oString; |
169 | d >>= 3; | 169 | d >>= 3; |
170 | } | 170 | } |
171 | 171 | ||
172 | while (oString.Length < padding) | 172 | while (oString.Length < padding) |
173 | { | 173 | { |
174 | oString = "0" + oString; | 174 | oString = "0" + oString; |
175 | } | 175 | } |
176 | 176 | ||
177 | byte[] oBytes = m_asciiEncoding.GetBytes(oString); | 177 | byte[] oBytes = m_asciiEncoding.GetBytes(oString); |
178 | 178 | ||
179 | return oBytes; | 179 | return oBytes; |
180 | } | 180 | } |
181 | } | 181 | } |