Esempio n. 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);
        }
Esempio n. 2
0
        internal int LoadUsers0(string key, string from)
        {
            Regex  regex = new Regex(key, RegexOptions.IgnoreCase);
            int    users = 0;
            string k1    = key.Replace("_", " ");

            foreach (string fsn in HostSystem.GetDirectories(from))
            {
                var files = HostSystem.GetFiles(fsn, "*.xml");
                if (files == null || files.Length == 0)
                {
                    continue;
                }

                string s = fsn;
                if (fsn.StartsWith(from))
                {
                    s = s.Substring(from.Length);
                }
                if (s.StartsWith("/"))
                {
                    s = s.Substring(1);
                }
                if (s.StartsWith("\\"))
                {
                    s = s.Substring(1);
                }
                if (regex.IsMatch(s))
                {
                    string     name = s.Replace("_", " ").Replace("~", " ").Replace("  ", " ");
                    MasterUser user = (MasterUser)FindOrCreateUser(name);
                    user.UserDirectory = user.UserDirectory ?? fsn;
                    users++;
                }
            }
            return(users);
        }