diff options
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Extensions/SimpleUtils.cs')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Extensions/SimpleUtils.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Extensions/SimpleUtils.cs b/OpenSim/Grid/AssetInventoryServer/Extensions/SimpleUtils.cs new file mode 100644 index 0000000..fe6491e --- /dev/null +++ b/OpenSim/Grid/AssetInventoryServer/Extensions/SimpleUtils.cs | |||
@@ -0,0 +1,44 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using OpenMetaverse; | ||
4 | |||
5 | namespace OpenSim.Grid.AssetInventoryServer.Extensions | ||
6 | { | ||
7 | public static class SimpleUtils | ||
8 | { | ||
9 | public static string ParseNameFromFilename(string filename) | ||
10 | { | ||
11 | filename = Path.GetFileName(filename); | ||
12 | |||
13 | int dot = filename.LastIndexOf('.'); | ||
14 | int firstDash = filename.IndexOf('-'); | ||
15 | |||
16 | if (dot - 37 > 0 && firstDash > 0) | ||
17 | return filename.Substring(0, firstDash); | ||
18 | else | ||
19 | return String.Empty; | ||
20 | } | ||
21 | |||
22 | public static UUID ParseUUIDFromFilename(string filename) | ||
23 | { | ||
24 | int dot = filename.LastIndexOf('.'); | ||
25 | |||
26 | if (dot > 35) | ||
27 | { | ||
28 | // Grab the last 36 characters of the filename | ||
29 | string uuidString = filename.Substring(dot - 36, 36); | ||
30 | UUID uuid; | ||
31 | UUID.TryParse(uuidString, out uuid); | ||
32 | return uuid; | ||
33 | } | ||
34 | else | ||
35 | { | ||
36 | UUID uuid; | ||
37 | if (UUID.TryParse(Path.GetFileName(filename), out uuid)) | ||
38 | return uuid; | ||
39 | else | ||
40 | return UUID.Zero; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | } | ||