コード例 #1
0
        private void LoadAction()
        {
            if (!File.Exists(this.SkillFile))
            {
                return;
            }

            lock (this.actionList)
            {
                this.actionList.Clear();

                // UTF-8 BOMあり
                using (var sr = new StreamReader(this.SkillFile, new UTF8Encoding(true)))
                    using (var parser = new TextFieldParser(sr)
                    {
                        TextFieldType = FieldType.Delimited,
                        Delimiters = new[] { "," },
                        HasFieldsEnclosedInQuotes = true,
                        TrimWhiteSpace = true,
                        CommentTokens = new[] { "#" },
                    })
                    {
                        while (!parser.EndOfData)
                        {
                            var fields = parser.ReadFields();

                            if (fields == null ||
                                fields.Length < 2)
                            {
                                continue;
                            }

                            uint id;
                            if (!uint.TryParse(fields[0], out id) ||
                                string.IsNullOrEmpty(fields[1]))
                            {
                                continue;
                            }

                            var entry = new XIVApiAction()
                            {
                                ID             = id,
                                Name           = fields[1],
                                AttackTypeName = fields[XIVApiAction.AttackTypeIndex]
                            };

                            entry.SetAttackTypeEnum();

                            this.actionList[entry.ID] = entry;
                        }
                    }

                this.AppLogger.Trace($"xivapi action list loaded. {this.SkillFile}");

                // Userリストの方も読み込む
                this.LoadUserAction();
            }
        }
コード例 #2
0
ファイル: XIVApi.cs プロジェクト: qitana/ACT.Hojoring
        private void LoadAction()
        {
            if (!File.Exists(this.SkillFile))
            {
                return;
            }

            var sw = Stopwatch.StartNew();

            var userList = this.UserActionList;

            var obj = new object();

            lock (this.actionList)
            {
                this.actionList.Clear();

                var lines = CSVParser.LoadFromPath(this.SkillFile, encoding: new UTF8Encoding(true));

                Parallel.ForEach(lines, (fields) =>
                {
                    if (fields.Count < 2)
                    {
                        return;
                    }

                    if (!uint.TryParse(fields[0], out uint id) ||
                        string.IsNullOrEmpty(fields[1]))
                    {
                        return;
                    }

                    var entry = new XIVApiAction()
                    {
                        ID             = id,
                        Name           = fields[1],
                        AttackTypeName = fields[XIVApiAction.AttackTypeIndex]
                    };

                    entry.SetAttackTypeEnum();

                    if (userList.ContainsKey(entry.ID))
                    {
                        entry.Name = userList[entry.ID].Name;
                    }

                    lock (obj)
                    {
                        this.actionList[entry.ID] = entry;
                    }
                });
            }

            sw.Stop();
            this.AppLogger.Trace($"xivapi action list loaded. {sw.Elapsed.TotalSeconds:N0}s {this.SkillFile}");
        }
コード例 #3
0
        private void LoadAction()
        {
            if (!File.Exists(this.SkillFile))
            {
                return;
            }

            var sw = Stopwatch.StartNew();

            var userList = this.UserActionList;

            lock (this.actionList)
            {
                this.actionList.Clear();

                var lines = CSVParser.LoadFromPath(this.SkillFile, encoding: new UTF8Encoding(true));

                var lineNo          = 0;
                var indexAttackType = 0;

                foreach (var fields in lines)
                {
                    lineNo++;

                    if (fields.Count < 2)
                    {
                        continue;
                    }

                    // 2行目のヘッダを探す
                    if (lineNo == 2)
                    {
                        indexAttackType = fields.IndexOf("AttackType");
                    }

                    if (!uint.TryParse(fields[0], out uint id) ||
                        string.IsNullOrEmpty(fields[1]))
                    {
                        continue;
                    }

                    var entry = new XIVApiAction()
                    {
                        ID             = id,
                        Name           = fields[1],
                        AttackTypeName = indexAttackType < 0 ? string.Empty : fields[indexAttackType]
                    };

                    entry.SetAttackTypeEnum();

                    if (userList.ContainsKey(entry.ID))
                    {
                        entry.Name = userList[entry.ID].Name;
                    }

                    this.actionList[entry.ID] = entry;
                }
            }

            sw.Stop();
            this.AppLogger.Trace($"xivapi action list loaded. {sw.Elapsed.TotalSeconds:N0}s {this.SkillFile}");
        }