diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs index a822d10..e297c37 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs | |||
@@ -27,6 +27,9 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
30 | using OpenMetaverse; | 33 | using OpenMetaverse; |
31 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
32 | using OpenSim.Services.Interfaces; | 35 | using OpenSim.Services.Interfaces; |
@@ -38,6 +41,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
38 | /// </summary> | 41 | /// </summary> |
39 | public static class InventoryArchiveUtils | 42 | public static class InventoryArchiveUtils |
40 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
41 | public static readonly string PATH_DELIMITER = "/"; | 46 | public static readonly string PATH_DELIMITER = "/"; |
42 | 47 | ||
43 | /// <summary> | 48 | /// <summary> |
@@ -181,10 +186,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
181 | public static InventoryItemBase FindItemByPath( | 186 | public static InventoryItemBase FindItemByPath( |
182 | IInventoryService inventoryService, InventoryFolderBase startFolder, string path) | 187 | IInventoryService inventoryService, InventoryFolderBase startFolder, string path) |
183 | { | 188 | { |
184 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | 189 | string[] components = SplitEscapedPath(path); |
190 | components[0] = UnescapePath(components[0]); | ||
191 | |||
192 | //string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | ||
185 | 193 | ||
186 | if (components.Length == 1) | 194 | if (components.Length == 1) |
187 | { | 195 | { |
196 | // m_log.DebugFormat("FOUND SINGLE COMPONENT [{0}]", components[0]); | ||
197 | |||
188 | List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID); | 198 | List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID); |
189 | foreach (InventoryItemBase item in items) | 199 | foreach (InventoryItemBase item in items) |
190 | { | 200 | { |
@@ -194,6 +204,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
194 | } | 204 | } |
195 | else | 205 | else |
196 | { | 206 | { |
207 | // m_log.DebugFormat("FOUND COMPONENTS [{0}] and [{1}]", components[0], components[1]); | ||
208 | |||
197 | InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID); | 209 | InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID); |
198 | 210 | ||
199 | foreach (InventoryFolderBase folder in contents.Folders) | 211 | foreach (InventoryFolderBase folder in contents.Folders) |
@@ -206,5 +218,74 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
206 | // We didn't find an item or intermediate folder with the given name | 218 | // We didn't find an item or intermediate folder with the given name |
207 | return null; | 219 | return null; |
208 | } | 220 | } |
221 | |||
222 | /// <summary> | ||
223 | /// Split a human escaped path into two components if it contains an unescaped path delimiter, or one component | ||
224 | /// if no delimiter is present | ||
225 | /// </summary> | ||
226 | /// <param name="path"></param> | ||
227 | /// <returns> | ||
228 | /// The split path. We leave the components in their originally unescaped state (though we remove the delimiter | ||
229 | /// which originally split them if applicable). | ||
230 | /// </returns> | ||
231 | public static string[] SplitEscapedPath(string path) | ||
232 | { | ||
233 | // m_log.DebugFormat("SPLITTING PATH {0}", path); | ||
234 | |||
235 | bool singleEscapeChar = false; | ||
236 | |||
237 | for (int i = 0; i < path.Length; i++) | ||
238 | { | ||
239 | if (path[i] == '\\' && !singleEscapeChar) | ||
240 | { | ||
241 | singleEscapeChar = true; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | if (PATH_DELIMITER == path[i].ToString() && !singleEscapeChar) | ||
246 | return new string[2] { path.Remove(i), path.Substring(i + 1) }; | ||
247 | else | ||
248 | singleEscapeChar = false; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | // We didn't find a delimiter | ||
253 | return new string[1] { path }; | ||
254 | } | ||
255 | |||
256 | /// <summary> | ||
257 | /// Unescapes a human escaped path. This means that "\\" goes to "\", and "\/" goes to "/" | ||
258 | /// </summary> | ||
259 | /// <param name="path"></param> | ||
260 | /// <returns></returns> | ||
261 | public static string UnescapePath(string path) | ||
262 | { | ||
263 | // m_log.DebugFormat("ESCAPING PATH {0}", path); | ||
264 | |||
265 | StringBuilder sb = new StringBuilder(); | ||
266 | |||
267 | bool singleEscapeChar = false; | ||
268 | for (int i = 0; i < path.Length; i++) | ||
269 | { | ||
270 | if (path[i] == '\\' && !singleEscapeChar) | ||
271 | singleEscapeChar = true; | ||
272 | else | ||
273 | singleEscapeChar = false; | ||
274 | |||
275 | if (singleEscapeChar) | ||
276 | { | ||
277 | if (PATH_DELIMITER == path[i].ToString()) | ||
278 | sb.Append(PATH_DELIMITER); | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | sb.Append(path[i]); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | // m_log.DebugFormat("ESCAPED PATH TO {0}", sb); | ||
287 | |||
288 | return sb.ToString(); | ||
289 | } | ||
209 | } | 290 | } |
210 | } \ No newline at end of file | 291 | } \ No newline at end of file |