Exemple #1
0
        internal static async Task load()
        {
            if (!IsEnabled)
            {
                return;
            }

            await Task.Run(() =>
            {
                string[] lines       = FileHelper.ReadAll(FilePath).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                HistoryItem[] _items = new HistoryItem[lines.Length];

                Regex regex           = new Regex(@"\{([^\}]+)\}", RegexOptions.Compiled);
                MatchCollection match = null;

                for (int i = 0; i < lines.Length; i++)
                {
                    try
                    {
                        match = regex.Matches(lines[i]);
                        if (match.Count == 7)
                        {
                            DateTime dateTime = new DateTime(match[6].Groups[1].Value.Long());
                            _items[i]         = new HistoryItem(match[0].Groups[1].Value, match[1].Groups[1].Value, match[2].Groups[1].Value, match[3].Groups[1].Value, match[4].Groups[1].Value, match[5].Groups[1].Value, dateTime);
                        }
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                }

                items = new ObservableCollection <HistoryItem>(_items);
            });
        }
Exemple #2
0
        internal static async Task Load()
        {
            if (isLoaded)
            {
                return;
            }

            await Task.Run(() =>
            {
                string[] lines = FileHelper.ReadAll(FilePath).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                Items          = new List <UserInfo>(lines.Length);

                Regex regex = new Regex(@"(?<Variable>[^""]+)""(?<Value>[^""]*)""\s*", RegexOptions.Compiled);

                for (int i = 0; i < lines.Length; i++)
                {
                    UserInfo user = new UserInfo();
                    try
                    {
                        MatchCollection matches = regex.Matches(lines[i]);
                        for (int j = 0; j < matches.Count; j++)
                        {
                            switch (matches[j].Groups["Variable"].Value)
                            {
                            case "Host": user.Host = matches[j].Groups["Value"].Value; break;

                            case "UserName": user.UserName = matches[j].Groups["Value"].Value; break;

                            case "Password": user.Password = matches[j].Groups["Value"].Value; break;

                            case "Port": user.Port = matches[j].Groups["Value"].Value.Int(); break;

                            case "Encryption": user.Encryption = matches[j].Groups["Value"].Value.Int(); break;

                            case "Protocol": user.Protocol = matches[j].Groups["Value"].Value.Int(); break;

                            case "UTF8": user.UTF8 = matches[j].Groups["Value"].Value.Int(); break;

                            case "MODEZ": user.MODEZ = matches[j].Groups["Value"].Value.Int(); break;

                            case "Proxy": user.Proxy = matches[j].Groups["Value"].Value.Int(); break;

                            case "Cache": user.Cache = matches[j].Groups["Value"].Value.Int(); break;

                            case "Selected": user.Selected = matches[j].Groups["Value"].Value.True(); break;
                            }
                        }
                        Items.Add(user);
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                }
            });

            isLoaded = true;
        }
Exemple #3
0
        private static void loadConf(string path)
        {
            Match match = (new Regex(@"(?<Key>[^:\s]+)\s*:\s*\{\s*?(?<Array>[^}]+)\s*\}", RegexOptions.Compiled)).Match(FileHelper.ReadAll(path));

            while (match.Success)
            {
                settings.Add(match.Groups["Key"].Value, new Setting(match.Groups["Array"].Value));
                match = match.NextMatch();
            }
        }