Exemple #1
0
        private string GetUserDir0(string key)
        {
            string userDir  = HostSystem.Combine(PathToUsersDir, key);
            string luserDir = HostSystem.ToRelativePath(userDir, RuntimeDirectory);

            if (HostSystem.DirExists(luserDir))
            {
                return(luserDir);
            }
            string k1 = key.Replace("_", " ");

            foreach (string fsn in HostSystem.GetDirectories(PathToUsersDir))
            {
                string s = fsn;
                if (fsn.StartsWith(PathToUsersDir))
                {
                    s = s.Substring(PathToUsersDir.Length);
                }
                if (s.StartsWith("/"))
                {
                    s = s.Substring(1);
                }
                if (s.StartsWith("\\"))
                {
                    s = s.Substring(1);
                }
                string s1 = "^" + s.Replace(".", "\\.").Replace("~", ".*").
                            Replace("~", ".*").Replace("_", "\\b").
                            Replace("\\b\\b", "\\b") + "$";

                Regex regex;
                try
                {
                    regex = new Regex(s1);
                }
                catch (Exception e)
                {
                    writeToLog("new Regex '" + s1 + "' " + e);
                    continue;
                }
                if (regex.IsMatch(k1))
                {
                    luserDir = HostSystem.ToRelativePath(fsn, RuntimeDirectory);
                    if (HostSystem.DirExists(luserDir))
                    {
                        return(luserDir);
                    }
                    return(fsn);
                }
            }
            return(luserDir);
        }