Пример #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
        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 LoadUserAction()
        {
            var isLoaded = false;

            if (!File.Exists(this.UserSkillFile))
            {
                return;
            }

            using (var sr = new StreamReader(this.UserSkillFile, new UTF8Encoding(false)))
                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;
                        }

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

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

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

            if (isLoaded)
            {
                this.AppLogger.Trace($"user action list loaded.");
            }
        }
Пример #4
0
        private Dictionary <uint, XIVApiAction> LoadUserAction()
        {
            var list = new Dictionary <uint, XIVApiAction>(256);

            if (!File.Exists(this.UserSkillFile))
            {
                return(list);
            }

            var lines = CSVParser.LoadFromPath(this.UserSkillFile, encoding: new UTF8Encoding(false));

            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],
                };

                lock (list)
                {
                    list[entry.ID] = entry;
                }
            });

            this.AppLogger.Trace($"user action list loaded.");

            return(list);
        }
Пример #5
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}");
        }