diff options
author | Justin Clarke Casey | 2009-02-11 18:46:51 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-02-11 18:46:51 +0000 |
commit | 162a59ba17af6c1fe16036ae3d1510d5c895b914 (patch) | |
tree | 610429265416a6c6ac13500795d049eac324a9da /OpenSim/Region/CoreModules | |
parent | * More inventory archive invocation to a proper region module (diff) | |
download | opensim-SC-162a59ba17af6c1fe16036ae3d1510d5c895b914.zip opensim-SC-162a59ba17af6c1fe16036ae3d1510d5c895b914.tar.gz opensim-SC-162a59ba17af6c1fe16036ae3d1510d5c895b914.tar.bz2 opensim-SC-162a59ba17af6c1fe16036ae3d1510d5c895b914.tar.xz |
* Refactor inventory archive code to allow direct invocation in order to support future unit tests
* Add a file I missed out from the last commit (the build was probably fine without it)
Diffstat (limited to 'OpenSim/Region/CoreModules')
3 files changed, 274 insertions, 52 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 704296c..7e57275 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -50,13 +50,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
50 | protected TarArchiveReader archive; | 50 | protected TarArchiveReader archive; |
51 | private static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); | 51 | private static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); |
52 | 52 | ||
53 | private string m_firstName; | ||
54 | private string m_lastName; | ||
55 | private string m_invPath; | ||
56 | |||
57 | /// <value> | ||
58 | /// The stream from which the inventory archive will be loaded. | ||
59 | /// </value> | ||
60 | private Stream m_loadStream; | ||
61 | |||
53 | CommunicationsManager commsManager; | 62 | CommunicationsManager commsManager; |
54 | 63 | ||
55 | public InventoryArchiveReadRequest(CommunicationsManager commsManager) | 64 | public InventoryArchiveReadRequest( |
65 | string firstName, string lastName, string invPath, string loadPath, CommunicationsManager commsManager) | ||
66 | : this( | ||
67 | firstName, | ||
68 | lastName, | ||
69 | invPath, | ||
70 | new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress), | ||
71 | commsManager) | ||
56 | { | 72 | { |
57 | //List<string> serialisedObjects = new List<string>(); | ||
58 | this.commsManager = commsManager; | ||
59 | } | 73 | } |
74 | |||
75 | public InventoryArchiveReadRequest( | ||
76 | string firstName, string lastName, string invPath, Stream loadStream, CommunicationsManager commsManager) | ||
77 | { | ||
78 | m_firstName = firstName; | ||
79 | m_lastName = lastName; | ||
80 | m_invPath = invPath; | ||
81 | m_loadStream = loadStream; | ||
82 | this.commsManager = commsManager; | ||
83 | } | ||
60 | 84 | ||
61 | protected InventoryItemBase loadInvItem(string path, string contents) | 85 | protected InventoryItemBase loadInvItem(string path, string contents) |
62 | { | 86 | { |
@@ -137,17 +161,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
137 | return item; | 161 | return item; |
138 | } | 162 | } |
139 | 163 | ||
140 | public void execute(string firstName, string lastName, string invPath, string loadPath) | 164 | public void Execute() |
141 | { | 165 | { |
142 | string filePath = "ERROR"; | 166 | string filePath = "ERROR"; |
143 | int successfulAssetRestores = 0; | 167 | int successfulAssetRestores = 0; |
144 | int failedAssetRestores = 0; | 168 | int failedAssetRestores = 0; |
145 | int successfulItemRestores = 0; | 169 | int successfulItemRestores = 0; |
146 | 170 | ||
147 | UserProfileData userProfile = commsManager.UserService.GetUserProfile(firstName, lastName); | 171 | UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName); |
148 | if (null == userProfile) | 172 | if (null == userProfile) |
149 | { | 173 | { |
150 | m_log.ErrorFormat("[CONSOLE]: Failed to find user {0} {1}", firstName, lastName); | 174 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName); |
151 | return; | 175 | return; |
152 | } | 176 | } |
153 | 177 | ||
@@ -155,8 +179,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
155 | if (null == userInfo) | 179 | if (null == userInfo) |
156 | { | 180 | { |
157 | m_log.ErrorFormat( | 181 | m_log.ErrorFormat( |
158 | "[CONSOLE]: Failed to find user info for {0} {1} {2}", | 182 | "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", |
159 | firstName, lastName, userProfile.ID); | 183 | m_firstName, m_lastName, userProfile.ID); |
160 | 184 | ||
161 | return; | 185 | return; |
162 | } | 186 | } |
@@ -164,33 +188,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
164 | if (!userInfo.HasReceivedInventory) | 188 | if (!userInfo.HasReceivedInventory) |
165 | { | 189 | { |
166 | m_log.ErrorFormat( | 190 | m_log.ErrorFormat( |
167 | "[CONSOLE]: Have not yet received inventory info for user {0} {1} {2}", | 191 | "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}", |
168 | firstName, lastName, userProfile.ID); | 192 | m_firstName, m_lastName, userProfile.ID); |
169 | 193 | ||
170 | return; | 194 | return; |
171 | } | 195 | } |
172 | 196 | ||
173 | InventoryFolderImpl inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath); | 197 | InventoryFolderImpl inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath); |
174 | 198 | ||
175 | if (null == inventoryFolder) | 199 | if (null == inventoryFolder) |
176 | { | 200 | { |
177 | // TODO: Later on, automatically create this folder if it does not exist | 201 | // TODO: Later on, automatically create this folder if it does not exist |
178 | m_log.ErrorFormat("[ARCHIVER]: Inventory path {0} does not exist", invPath); | 202 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); |
179 | 203 | ||
180 | return; | 204 | return; |
181 | } | 205 | } |
182 | 206 | ||
183 | archive | 207 | archive = new TarArchiveReader(m_loadStream); |
184 | = new TarArchiveReader(new GZipStream( | ||
185 | new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress)); | ||
186 | 208 | ||
187 | byte[] data; | 209 | byte[] data; |
188 | TarArchiveReader.TarEntryType entryType; | 210 | TarArchiveReader.TarEntryType entryType; |
189 | while ((data = archive.ReadEntry(out filePath, out entryType)) != null) | 211 | while ((data = archive.ReadEntry(out filePath, out entryType)) != null) |
190 | { | 212 | { |
191 | if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY) { | 213 | if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY) { |
192 | m_log.WarnFormat("[ARCHIVER]: Ignoring directory entry {0}", filePath); | 214 | m_log.WarnFormat("[INVENTORY ARCHIVER]: Ignoring directory entry {0}", filePath); |
193 | } else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) | 215 | } |
216 | else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) | ||
194 | { | 217 | { |
195 | if (LoadAsset(filePath, data)) | 218 | if (LoadAsset(filePath, data)) |
196 | successfulAssetRestores++; | 219 | successfulAssetRestores++; |
@@ -219,8 +242,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
219 | 242 | ||
220 | archive.Close(); | 243 | archive.Close(); |
221 | 244 | ||
222 | m_log.DebugFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores); | 245 | m_log.DebugFormat("[INVENTORY ARCHIVER]: Restored {0} assets", successfulAssetRestores); |
223 | m_log.InfoFormat("[ARCHIVER]: Restored {0} items", successfulItemRestores); | 246 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Restored {0} items", successfulItemRestores); |
224 | } | 247 | } |
225 | 248 | ||
226 | /// <summary> | 249 | /// <summary> |
@@ -239,7 +262,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
239 | if (i == -1) | 262 | if (i == -1) |
240 | { | 263 | { |
241 | m_log.ErrorFormat( | 264 | m_log.ErrorFormat( |
242 | "[ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping", | 265 | "[INVENTORY ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping", |
243 | assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR); | 266 | assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR); |
244 | 267 | ||
245 | return false; | 268 | return false; |
@@ -252,7 +275,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
252 | { | 275 | { |
253 | sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; | 276 | sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; |
254 | 277 | ||
255 | m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); | 278 | m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); |
256 | 279 | ||
257 | AssetBase asset = new AssetBase(new UUID(uuid), "RandomName"); | 280 | AssetBase asset = new AssetBase(new UUID(uuid), "RandomName"); |
258 | 281 | ||
@@ -266,7 +289,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
266 | else | 289 | else |
267 | { | 290 | { |
268 | m_log.ErrorFormat( | 291 | m_log.ErrorFormat( |
269 | "[ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}", | 292 | "[INVENTORY ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}", |
270 | assetPath, extension); | 293 | assetPath, extension); |
271 | 294 | ||
272 | return false; | 295 | return false; |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 90e2fcd..bfa4de9 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -43,29 +43,53 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
43 | { | 43 | { |
44 | public class InventoryArchiveWriteRequest | 44 | public class InventoryArchiveWriteRequest |
45 | { | 45 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | protected TarArchiveWriter archive; | 48 | protected TarArchiveWriter archive = new TarArchiveWriter(); |
49 | protected CommunicationsManager commsManager; | 49 | protected CommunicationsManager commsManager; |
50 | Dictionary<UUID, int> assetUuids; | 50 | protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>(); |
51 | |||
52 | private string m_firstName; | ||
53 | private string m_lastName; | ||
54 | private string m_invPath; | ||
51 | 55 | ||
52 | /// <value> | 56 | /// <value> |
53 | /// The path to which the inventory archive will be saved. | 57 | /// The stream to which the inventory archive will be saved. |
54 | /// </value> | 58 | /// </value> |
55 | private string m_savePath; | 59 | private Stream m_saveStream; |
56 | 60 | ||
57 | public InventoryArchiveWriteRequest(CommunicationsManager commsManager) | 61 | /// <summary> |
62 | /// Constructor | ||
63 | /// </summary> | ||
64 | public InventoryArchiveWriteRequest( | ||
65 | string firstName, string lastName, string invPath, string savePath, CommunicationsManager commsManager) | ||
66 | : this( | ||
67 | firstName, | ||
68 | lastName, | ||
69 | invPath, | ||
70 | new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress), | ||
71 | commsManager) | ||
72 | { | ||
73 | } | ||
74 | |||
75 | /// <summary> | ||
76 | /// Constructor | ||
77 | /// </summary> | ||
78 | public InventoryArchiveWriteRequest( | ||
79 | string firstName, string lastName, string invPath, Stream saveStream, CommunicationsManager commsManager) | ||
58 | { | 80 | { |
59 | archive = new TarArchiveWriter(); | 81 | m_firstName = firstName; |
82 | m_lastName = lastName; | ||
83 | m_invPath = invPath; | ||
84 | m_saveStream = saveStream; | ||
60 | this.commsManager = commsManager; | 85 | this.commsManager = commsManager; |
61 | assetUuids = new Dictionary<UUID, int>(); | ||
62 | } | 86 | } |
63 | 87 | ||
64 | protected void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids) | 88 | protected void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids) |
65 | { | 89 | { |
66 | AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound); | 90 | AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound); |
67 | assetsArchiver.Archive(archive); | 91 | assetsArchiver.Archive(archive); |
68 | archive.WriteTar(new GZipStream(new FileStream(m_savePath, FileMode.Create), CompressionMode.Compress)); | 92 | archive.WriteTar(m_saveStream); |
69 | } | 93 | } |
70 | 94 | ||
71 | protected void saveInvItem(InventoryItemBase inventoryItem, string path) | 95 | protected void saveInvItem(InventoryItemBase inventoryItem, string path) |
@@ -158,21 +182,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
158 | } | 182 | } |
159 | } | 183 | } |
160 | 184 | ||
161 | public void execute(string firstName, string lastName, string invPath, string savePath) | 185 | public void Execute() |
162 | { | 186 | { |
163 | m_savePath = savePath; | 187 | UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName); |
164 | |||
165 | UserProfileData userProfile = commsManager.UserService.GetUserProfile(firstName, lastName); | ||
166 | if (null == userProfile) | 188 | if (null == userProfile) |
167 | { | 189 | { |
168 | m_log.ErrorFormat("[CONSOLE]: Failed to find user {0} {1}", firstName, lastName); | 190 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName); |
169 | return; | 191 | return; |
170 | } | 192 | } |
171 | 193 | ||
172 | CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); | 194 | CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); |
173 | if (null == userInfo) | 195 | if (null == userInfo) |
174 | { | 196 | { |
175 | m_log.ErrorFormat("[CONSOLE]: Failed to find user info for {0} {1} {2}", firstName, lastName, userProfile.ID); | 197 | m_log.ErrorFormat( |
198 | "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", | ||
199 | m_firstName, m_lastName, userProfile.ID); | ||
176 | return; | 200 | return; |
177 | } | 201 | } |
178 | 202 | ||
@@ -184,34 +208,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
184 | // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl | 208 | // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl |
185 | // itself (possibly at a small loss in efficiency). | 209 | // itself (possibly at a small loss in efficiency). |
186 | string[] components | 210 | string[] components |
187 | = invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); | 211 | = m_invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); |
188 | invPath = String.Empty; | 212 | m_invPath = String.Empty; |
189 | foreach (string c in components) | 213 | foreach (string c in components) |
190 | { | 214 | { |
191 | invPath += c + InventoryFolderImpl.PATH_DELIMITER; | 215 | m_invPath += c + InventoryFolderImpl.PATH_DELIMITER; |
192 | } | 216 | } |
193 | 217 | ||
194 | // Annoyingly Split actually returns the original string if the input string consists only of delimiters | 218 | // Annoyingly Split actually returns the original string if the input string consists only of delimiters |
195 | // Therefore if we still start with a / after the split, then we need the root folder | 219 | // Therefore if we still start with a / after the split, then we need the root folder |
196 | if (invPath.Length == 0) | 220 | if (m_invPath.Length == 0) |
197 | { | 221 | { |
198 | inventoryFolder = userInfo.RootFolder; | 222 | inventoryFolder = userInfo.RootFolder; |
199 | } | 223 | } |
200 | else | 224 | else |
201 | { | 225 | { |
202 | invPath = invPath.Remove(invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); | 226 | m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); |
203 | inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath); | 227 | inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath); |
204 | } | 228 | } |
205 | 229 | ||
206 | // The path may point to an item instead | 230 | // The path may point to an item instead |
207 | if (inventoryFolder == null) | 231 | if (inventoryFolder == null) |
208 | { | 232 | { |
209 | inventoryItem = userInfo.RootFolder.FindItemByPath(invPath); | 233 | inventoryItem = userInfo.RootFolder.FindItemByPath(m_invPath); |
210 | } | 234 | } |
211 | } | 235 | } |
212 | else | 236 | else |
213 | { | 237 | { |
214 | m_log.ErrorFormat("[CONSOLE]: Have not yet received inventory info for user {0} {1} {2}", firstName, lastName, userProfile.ID); | 238 | m_log.ErrorFormat( |
239 | "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}", | ||
240 | m_firstName, m_lastName, userProfile.ID); | ||
215 | return; | 241 | return; |
216 | } | 242 | } |
217 | 243 | ||
@@ -219,21 +245,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
219 | { | 245 | { |
220 | if (null == inventoryItem) | 246 | if (null == inventoryItem) |
221 | { | 247 | { |
222 | m_log.ErrorFormat("[CONSOLE]: Could not find inventory entry at path {0}", invPath); | 248 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Could not find inventory entry at path {0}", m_invPath); |
223 | return; | 249 | return; |
224 | } | 250 | } |
225 | else | 251 | else |
226 | { | 252 | { |
227 | m_log.InfoFormat("[CONSOLE]: Found item {0} {1} at {2}", inventoryItem.Name, inventoryItem.ID, | 253 | m_log.InfoFormat( |
228 | invPath); | 254 | "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}", |
255 | inventoryItem.Name, inventoryItem.ID, m_invPath); | ||
256 | |||
229 | //get and export item info | 257 | //get and export item info |
230 | saveInvItem(inventoryItem, invPath); | 258 | saveInvItem(inventoryItem, m_invPath); |
231 | } | 259 | } |
232 | } | 260 | } |
233 | else | 261 | else |
234 | { | 262 | { |
235 | m_log.InfoFormat("[CONSOLE]: Found folder {0} {1} at {2}", inventoryFolder.Name, inventoryFolder.ID, | 263 | m_log.InfoFormat( |
236 | invPath); | 264 | "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}", |
265 | inventoryFolder.Name, inventoryFolder.ID, m_invPath); | ||
266 | |||
237 | //recurse through all dirs getting dirs and files | 267 | //recurse through all dirs getting dirs and files |
238 | saveInvDir(inventoryFolder, ""); | 268 | saveInvDir(inventoryFolder, ""); |
239 | } | 269 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs new file mode 100644 index 0000000..0c489e5 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs | |||
@@ -0,0 +1,169 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | |||
38 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// This module loads and saves OpenSimulator inventory archives | ||
42 | /// </summary> | ||
43 | public class InventoryArchiverModule : IRegionModule, IInventoryArchiverModule | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public string Name { get { return "Inventory Archiver Module"; } } | ||
48 | |||
49 | public bool IsSharedModule { get { return true; } } | ||
50 | |||
51 | /// <summary> | ||
52 | /// The file to load and save inventory if no filename has been specified | ||
53 | /// </summary> | ||
54 | protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz"; | ||
55 | |||
56 | /// <value> | ||
57 | /// All scenes that this module knows about | ||
58 | /// </value> | ||
59 | private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>(); | ||
60 | |||
61 | /// <value> | ||
62 | /// The comms manager we will use for all comms requests | ||
63 | /// </value> | ||
64 | private CommunicationsManager m_commsManager; | ||
65 | |||
66 | public void Initialise(Scene scene, IConfigSource source) | ||
67 | { | ||
68 | if (m_scenes.Count == 0) | ||
69 | { | ||
70 | scene.RegisterModuleInterface<IInventoryArchiverModule>(this); | ||
71 | m_commsManager = scene.CommsManager; | ||
72 | |||
73 | scene.AddCommand( | ||
74 | this, "load iar", | ||
75 | "load iar <first> <last> <inventory path> [<archive path>]", | ||
76 | "Load user inventory archive. EXPERIMENTAL, PLEASE DO NOT USE YET", HandleLoadInvConsoleCommand); | ||
77 | |||
78 | scene.AddCommand( | ||
79 | this, "save iar", | ||
80 | "save iar <first> <last> <inventory path> [<archive path>]", | ||
81 | "Save user inventory archive. EXPERIMENTAL, PLEASE DO NOT USE YET", HandleSaveInvConsoleCommand); | ||
82 | } | ||
83 | |||
84 | m_scenes[scene.RegionInfo.RegionID] = scene; | ||
85 | } | ||
86 | |||
87 | public void PostInitialise() | ||
88 | { | ||
89 | } | ||
90 | |||
91 | public void Close() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) | ||
96 | { | ||
97 | if (m_scenes.Count > 0) | ||
98 | { | ||
99 | new InventoryArchiveReadRequest(firstName, lastName, invPath, loadStream, m_commsManager).Execute(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public void ArchiveInventory(string firstName, string lastName, string invPath, Stream saveStream) | ||
104 | { | ||
105 | if (m_scenes.Count > 0) | ||
106 | { | ||
107 | new InventoryArchiveWriteRequest(firstName, lastName, invPath, saveStream, m_commsManager).Execute(); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath) | ||
112 | { | ||
113 | if (m_scenes.Count > 0) | ||
114 | { | ||
115 | new InventoryArchiveReadRequest(firstName, lastName, invPath, loadPath, m_commsManager).Execute(); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | public void ArchiveInventory(string firstName, string lastName, string invPath, string savePath) | ||
120 | { | ||
121 | if (m_scenes.Count > 0) | ||
122 | { | ||
123 | new InventoryArchiveWriteRequest(firstName, lastName, invPath, savePath, m_commsManager).Execute(); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Load inventory from an inventory file archive | ||
129 | /// </summary> | ||
130 | /// <param name="cmdparams"></param> | ||
131 | protected void HandleLoadInvConsoleCommand(string module, string[] cmdparams) | ||
132 | { | ||
133 | if (cmdparams.Length < 5) | ||
134 | { | ||
135 | m_log.Error( | ||
136 | "[INVENTORY ARCHIVER]: usage is load iar <first name> <last name> <inventory path> [<load file path>]"); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | string firstName = cmdparams[2]; | ||
141 | string lastName = cmdparams[3]; | ||
142 | string invPath = cmdparams[4]; | ||
143 | string loadPath = (cmdparams.Length > 5 ? cmdparams[5] : DEFAULT_INV_BACKUP_FILENAME); | ||
144 | |||
145 | DearchiveInventory(firstName, lastName, invPath, loadPath); | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Save inventory to a file archive | ||
150 | /// </summary> | ||
151 | /// <param name="cmdparams"></param> | ||
152 | protected void HandleSaveInvConsoleCommand(string module, string[] cmdparams) | ||
153 | { | ||
154 | if (cmdparams.Length < 5) | ||
155 | { | ||
156 | m_log.Error( | ||
157 | "[INVENTORY ARCHIVER]: usage is save iar <first name> <last name> <inventory path> [<save file path>]"); | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | string firstName = cmdparams[2]; | ||
162 | string lastName = cmdparams[3]; | ||
163 | string invPath = cmdparams[4]; | ||
164 | string savePath = (cmdparams.Length > 5 ? cmdparams[5] : DEFAULT_INV_BACKUP_FILENAME); | ||
165 | |||
166 | ArchiveInventory(firstName, lastName, invPath, savePath); | ||
167 | } | ||
168 | } | ||
169 | } | ||