aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/NewAssetServer/Extensions/SimpleUtils.cs
blob: 6642f9037371b8898543d670f99712b140678589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.IO;
using OpenMetaverse;

namespace AssetServer.Extensions
{
    public static class SimpleUtils
    {
        public static string ParseNameFromFilename(string filename)
        {
            filename = Path.GetFileName(filename);

            int dot = filename.LastIndexOf('.');
            int firstDash = filename.IndexOf('-');

            if (dot - 37 > 0 && firstDash > 0)
                return filename.Substring(0, firstDash);
            else
                return String.Empty;
        }

        public static UUID ParseUUIDFromFilename(string filename)
        {
            int dot = filename.LastIndexOf('.');

            if (dot > 35)
            {
                // Grab the last 36 characters of the filename
                string uuidString = filename.Substring(dot - 36, 36);
                UUID uuid;
                UUID.TryParse(uuidString, out uuid);
                return uuid;
            }
            else
            {
                UUID uuid;
                if (UUID.TryParse(Path.GetFileName(filename), out uuid))
                    return uuid;
                else
                    return UUID.Zero;
            }
        }
    }
}