public FtpUserInfo(string MatchIniStr) { Match m_username = Regex.Match(MatchIniStr, @"\[USER=(.*?)\|", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); _UserName = m_username.Groups[1].Value; MatchCollection mc_DomainUser = Regex.Matches(MatchIniStr, @"^([^\[].*?)=(.*)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled); _Password = mc_DomainUser[0].Groups[2].Value; for (int i = 1; i < mc_DomainUser.Count; i++) { Match m = mc_DomainUser[i]; _PropertyList.Add(m.Groups[1].Value, m.Groups[2].Value); } }
public iniControl(string iniPath, string MainDomainName = "windpro") { this.MainDomainName = MainDomainName; DomainArr = new Dictionary <string, string>(); //读入文件 this.iniPath = iniPath; if (!File.Exists(iniPath)) { throw new Exception("不存在文件"); } StreamReader sr = new StreamReader(iniPath, System.Text.Encoding.Default); iniContent = sr.ReadToEnd(); sr.Close(); //得到配置文件头 Match m_header = Regex.Match(iniContent, @"\[GLOBAL\].*?(?=\[Domain[0-9]+\])", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); _header = m_header.Value; //得到域名列表 MatchCollection mc_DomainList = Regex.Matches(iniContent, @"\[(Domain[0-9]+)\].*?((?=\[Domain[0-9]+\])|$)", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); foreach (Match m in mc_DomainList) { Match m_key = Regex.Match(_header, @"Domain1=.*?\|\|.*?\|(.*?)\|", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); string key = m_key.Groups[1].Value; string value = m.Groups[0].Value; DomainArr.Add(key, value); } string MainDomainStr = DomainArr[MainDomainName]; if (MainDomainStr == null) { throw new Exception("需要处理域错误"); } //得到域名除用户以外的配置信息 Match m_DomainConfig = Regex.Match(MainDomainStr, @"\[Domain[0-9]+\].?\n(.*?)\n\[USER="******"^(?!User[0-9]+)((.*?)=(.*?))\r?$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled); MainDomainConfigWithoutUserConfig = new PropertyControl();; foreach (Match m in mc_DomainConfigWithoutUserConfig) { string key = m.Groups[2].Value; string value = m.Groups[3].Value; MainDomainConfigWithoutUserConfig.Add(key, value); } ////得到域名用户配置信息 //MatchCollection mc_DomainConfigInUserConfig = Regex.Matches(DomainConfigStr, @"^(?=User[0-9])+.*$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled); //得到用户信息 Match m_DomainUserList = Regex.Match(MainDomainStr, @"\[USER=.*", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); string UserListStr = m_DomainUserList.Value; //得到用户列表 MatchCollection mc_DomainUserStr = Regex.Matches(UserListStr, @"\[USER=(.*?)\|.*?((?=\n\[USER=)|$)", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled); FtpUserList = new Dictionary <string, FtpUserInfo>(); foreach (Match m in mc_DomainUserStr) { try { FtpUserInfo userinfo = new FtpUserInfo(m.Value); FtpUserList.Add(m.Groups[1].Value, userinfo); } catch { } } }