diff options
author | Justin Clarke Casey | 2007-12-31 23:20:49 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2007-12-31 23:20:49 +0000 |
commit | b8975ecbd9510bd8e766cb4ca06c5a70110187cd (patch) | |
tree | 7489daa7abfb2709f89f519a14dd15ce6e10bb9a /OpenSim/Framework/Communications/Cache | |
parent | * Added database and UserManagerBase glue for FriendsList management (diff) | |
download | opensim-SC_OLD-b8975ecbd9510bd8e766cb4ca06c5a70110187cd.zip opensim-SC_OLD-b8975ecbd9510bd8e766cb4ca06c5a70110187cd.tar.gz opensim-SC_OLD-b8975ecbd9510bd8e766cb4ca06c5a70110187cd.tar.bz2 opensim-SC_OLD-b8975ecbd9510bd8e766cb4ca06c5a70110187cd.tar.xz |
Make it possible for new inventory 'libraries' to be added without changing the default OpenSimLibrary files. Additional library folders and items can be added in a separate
directory
and linked in by an entry to inventory/Libraries.xml
Diffstat (limited to 'OpenSim/Framework/Communications/Cache')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs | 200 |
1 files changed, 115 insertions, 85 deletions
diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs index cb122df..38cffeb 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs | |||
@@ -64,35 +64,9 @@ namespace OpenSim.Framework.Communications.Cache | |||
64 | 64 | ||
65 | libraryFolders.Add(folderID, this); | 65 | libraryFolders.Add(folderID, this); |
66 | 66 | ||
67 | string foldersPath = Path.Combine(Util.configDir(), "inventory/OpenSimLibrary/OpenSimLibraryFolders.xml"); | 67 | LoadLibraries(Path.Combine(Util.inventoryDir(), "Libraries.xml")); |
68 | if (File.Exists(foldersPath)) | ||
69 | { | ||
70 | try | ||
71 | { | ||
72 | XmlConfigSource source = new XmlConfigSource(foldersPath); | ||
73 | ReadFoldersFromFile(source); | ||
74 | } | ||
75 | catch (XmlException e) | ||
76 | { | ||
77 | MainLog.Instance.Error("AGENTINVENTORY", "Error loading " + foldersPath + ": " + e.ToString()); | ||
78 | } | ||
79 | } | ||
80 | 68 | ||
81 | CreateLibraryItems(); | 69 | CreateLibraryItems(); |
82 | |||
83 | string itemsPath = Path.Combine(Util.configDir(), "inventory/OpenSimLibrary/OpenSimLibrary.xml"); | ||
84 | if (File.Exists(itemsPath)) | ||
85 | { | ||
86 | try | ||
87 | { | ||
88 | XmlConfigSource source = new XmlConfigSource(itemsPath); | ||
89 | ReadItemsFromFile(source); | ||
90 | } | ||
91 | catch (XmlException e) | ||
92 | { | ||
93 | MainLog.Instance.Error("AGENTINVENTORY", "Error loading " + itemsPath + ": " + e.ToString()); | ||
94 | } | ||
95 | } | ||
96 | } | 70 | } |
97 | 71 | ||
98 | /// <summary> | 72 | /// <summary> |
@@ -155,84 +129,140 @@ namespace OpenSim.Framework.Communications.Cache | |||
155 | } | 129 | } |
156 | 130 | ||
157 | /// <summary> | 131 | /// <summary> |
158 | /// Read library inventory folders from an external source | 132 | /// Use the asset set information at path to load assets |
133 | /// </summary> | ||
134 | /// <param name="path"></param> | ||
135 | /// <param name="assets"></param> | ||
136 | protected void LoadLibraries(string librariesControlPath) | ||
137 | { | ||
138 | MainLog.Instance.Verbose( | ||
139 | "LIBRARYINVENTORY", "Loading libraries control file {0}", librariesControlPath); | ||
140 | |||
141 | LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig); | ||
142 | } | ||
143 | |||
144 | /// <summary> | ||
145 | /// Read a library set from config | ||
146 | /// </summary> | ||
147 | /// <param name="config"></param> | ||
148 | protected void ReadLibraryFromConfig(IConfig config) | ||
149 | { | ||
150 | string foldersPath | ||
151 | = Path.Combine( | ||
152 | Util.inventoryDir(), config.GetString("foldersFile", "")); | ||
153 | |||
154 | LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig); | ||
155 | |||
156 | string itemsPath | ||
157 | = Path.Combine( | ||
158 | Util.inventoryDir(), config.GetString("itemsFile", "")); | ||
159 | |||
160 | LoadFromFile(itemsPath, "Library items", ReadItemFromConfig); | ||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// Read a library inventory folder from a loaded configuration | ||
159 | /// </summary> | 165 | /// </summary> |
160 | /// <param name="source"></param> | 166 | /// <param name="source"></param> |
161 | private void ReadFoldersFromFile(IConfigSource source) | 167 | private void ReadFolderFromConfig(IConfig config) |
162 | { | 168 | { |
163 | for (int i = 0; i < source.Configs.Count; i++) | 169 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); |
164 | { | 170 | |
165 | IConfig config = source.Configs[i]; | 171 | folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); |
166 | 172 | folderInfo.name = config.GetString("name", "unknown"); | |
167 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); | 173 | folderInfo.parentID = new LLUUID(config.GetString("parentFolderID", folderID.ToString())); |
168 | 174 | folderInfo.type = (short)config.GetInt("type", 8); | |
169 | folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); | 175 | |
170 | folderInfo.name = config.GetString("name", "unknown"); | 176 | folderInfo.agentID = libOwner; |
171 | folderInfo.parentID = new LLUUID(config.GetString("parentFolderID", folderID.ToString())); | 177 | folderInfo.version = 1; |
172 | folderInfo.type = (short)config.GetInt("type", 8); | 178 | |
179 | if (libraryFolders.ContainsKey(folderInfo.parentID)) | ||
180 | { | ||
181 | InventoryFolderImpl parentFolder = libraryFolders[folderInfo.parentID]; | ||
173 | 182 | ||
174 | folderInfo.agentID = libOwner; | 183 | libraryFolders.Add(folderInfo.folderID, folderInfo); |
175 | folderInfo.version = 1; | 184 | parentFolder.SubFolders.Add(folderInfo.folderID, folderInfo); |
176 | 185 | ||
177 | if (libraryFolders.ContainsKey(folderInfo.parentID)) | ||
178 | { | ||
179 | InventoryFolderImpl parentFolder = libraryFolders[folderInfo.parentID]; | ||
180 | |||
181 | libraryFolders.Add(folderInfo.folderID, folderInfo); | ||
182 | parentFolder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||
183 | |||
184 | // MainLog.Instance.Verbose( | 186 | // MainLog.Instance.Verbose( |
185 | // "LIBRARYINVENTORY", "Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); | 187 | // "LIBRARYINVENTORY", "Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); |
186 | } | 188 | } |
187 | else | 189 | else |
188 | { | 190 | { |
189 | MainLog.Instance.Warn( | 191 | MainLog.Instance.Warn( |
190 | "LIBRARYINVENTORY", | 192 | "LIBRARYINVENTORY", |
191 | "Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", | 193 | "Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", |
192 | folderInfo.name, folderInfo.folderID, folderInfo.parentID); | 194 | folderInfo.name, folderInfo.folderID, folderInfo.parentID); |
193 | } | ||
194 | } | 195 | } |
195 | } | 196 | } |
196 | 197 | ||
197 | /// <summary> | 198 | /// <summary> |
198 | /// Read library inventory items metadata from an external source | 199 | /// Read a library inventory item metadata from a loaded configuration |
199 | /// </summary> | 200 | /// </summary> |
200 | /// <param name="source"></param> | 201 | /// <param name="source"></param> |
201 | private void ReadItemsFromFile(IConfigSource source) | 202 | private void ReadItemFromConfig(IConfig config) |
202 | { | 203 | { |
203 | for (int i = 0; i < source.Configs.Count; i++) | 204 | InventoryItemBase item = new InventoryItemBase(); |
205 | item.avatarID = libOwner; | ||
206 | item.creatorsID = libOwner; | ||
207 | item.inventoryID = new LLUUID(config.GetString("inventoryID", folderID.ToString())); | ||
208 | item.assetID = new LLUUID(config.GetString("assetID", LLUUID.Random().ToString())); | ||
209 | item.parentFolderID = new LLUUID(config.GetString("folderID", folderID.ToString())); | ||
210 | item.inventoryDescription = config.GetString("description", ""); | ||
211 | item.inventoryName = config.GetString("name", ""); | ||
212 | item.assetType = config.GetInt("assetType", 0); | ||
213 | item.invType = config.GetInt("inventoryType", 0); | ||
214 | item.inventoryCurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF); | ||
215 | item.inventoryNextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF); | ||
216 | item.inventoryEveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF); | ||
217 | item.inventoryBasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF); | ||
218 | |||
219 | if (libraryFolders.ContainsKey(item.parentFolderID)) | ||
204 | { | 220 | { |
205 | InventoryItemBase item = new InventoryItemBase(); | 221 | InventoryFolderImpl parentFolder = libraryFolders[item.parentFolderID]; |
206 | item.avatarID = libOwner; | ||
207 | item.creatorsID = libOwner; | ||
208 | item.inventoryID = | ||
209 | new LLUUID(source.Configs[i].GetString("inventoryID", folderID.ToString())); | ||
210 | item.assetID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToString())); | ||
211 | item.parentFolderID | ||
212 | = new LLUUID(source.Configs[i].GetString("folderID", folderID.ToString())); | ||
213 | item.inventoryDescription = source.Configs[i].GetString("description", ""); | ||
214 | item.inventoryName = source.Configs[i].GetString("name", ""); | ||
215 | item.assetType = source.Configs[i].GetInt("assetType", 0); | ||
216 | item.invType = source.Configs[i].GetInt("inventoryType", 0); | ||
217 | item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); | ||
218 | item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); | ||
219 | item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); | ||
220 | item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); | ||
221 | 222 | ||
222 | if (libraryFolders.ContainsKey(item.parentFolderID)) | 223 | parentFolder.Items.Add(item.inventoryID, item); |
224 | } | ||
225 | else | ||
226 | { | ||
227 | MainLog.Instance.Warn( | ||
228 | "LIBRARYINVENTORY", | ||
229 | "Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", | ||
230 | item.inventoryName, item.inventoryID, item.parentFolderID); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | private delegate void ConfigAction(IConfig config); | ||
235 | |||
236 | /// <summary> | ||
237 | /// Load the given configuration at a path and perform an action on each Config contained within it | ||
238 | /// </summary> | ||
239 | /// <param name="path"></param> | ||
240 | /// <param name="fileDescription"></param> | ||
241 | /// <param name="action"></param> | ||
242 | private void LoadFromFile(string path, string fileDescription, ConfigAction action) | ||
243 | { | ||
244 | if (File.Exists(path)) | ||
245 | { | ||
246 | try | ||
223 | { | 247 | { |
224 | InventoryFolderImpl parentFolder = libraryFolders[item.parentFolderID]; | 248 | XmlConfigSource source = new XmlConfigSource(path); |
225 | 249 | ||
226 | parentFolder.Items.Add(item.inventoryID, item); | 250 | for (int i = 0; i < source.Configs.Count; i++) |
251 | { | ||
252 | action(source.Configs[i]); | ||
253 | } | ||
227 | } | 254 | } |
228 | else | 255 | catch (XmlException e) |
229 | { | 256 | { |
230 | MainLog.Instance.Warn( | 257 | MainLog.Instance.Error( |
231 | "LIBRARYINVENTORY", | 258 | "LIBRARYINVENTORY", "Error loading {0} : {1}", path, e); |
232 | "Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", | ||
233 | item.inventoryName, item.inventoryID, item.parentFolderID); | ||
234 | } | 259 | } |
235 | } | 260 | } |
261 | else | ||
262 | { | ||
263 | MainLog.Instance.Error( | ||
264 | "LIBRARYINVENTORY", "{0} file {1} does not exist!", fileDescription, path); | ||
265 | } | ||
236 | } | 266 | } |
237 | 267 | ||
238 | /// <summary> | 268 | /// <summary> |