aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-11 18:46:51 +0000
committerJustin Clarke Casey2009-02-11 18:46:51 +0000
commit162a59ba17af6c1fe16036ae3d1510d5c895b914 (patch)
tree610429265416a6c6ac13500795d049eac324a9da /OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
parent* More inventory archive invocation to a proper region module (diff)
downloadopensim-SC_OLD-162a59ba17af6c1fe16036ae3d1510d5c895b914.zip
opensim-SC_OLD-162a59ba17af6c1fe16036ae3d1510d5c895b914.tar.gz
opensim-SC_OLD-162a59ba17af6c1fe16036ae3d1510d5c895b914.tar.bz2
opensim-SC_OLD-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/Avatar/Inventory/Archiver/InventoryArchiverModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs169
1 files changed, 169 insertions, 0 deletions
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
28using System.Collections.Generic;
29using System.IO;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework.Communications;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38namespace 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}