Beispiel #1
0
        /// <summary>
        /// フォルダスキャン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            try {
                if (Chat == null)
                    throw new NullReferenceException("スキャン先のパスが未指定です。");
                if (SelectedPatch == null) return;

                DirectoryInfo saveDir = new DirectoryInfo(Chat.FullName + "\\Save");
                if (!saveDir.Exists)
                    saveDir.Create();

                ConfigAccess config = new ConfigAccess();

                foreach (var file in Chat.EnumerateFiles().OrderBy(a => a.CreationTime)) {
                    var line = File.ReadAllLines(file.FullName, enc).LastOrDefault(a => new Regex("特別経験値").IsMatch(a));
                    if (line == null) continue;

                    var exp = Convert.ToInt32(new Regex("[0-9]+").Match(line).Value);
                    var unit = SelectedPatch.Units.FirstOrDefault(a => a.MExp == exp);
                    if (unit == null) continue;

                    var mob = SelectedPatch.Maps.SelectMany(a => a.Mobs).Where(
                        a => a.Id == unit.Id).OrderBy(a => a.Delay).FirstOrDefault();

                    // 次回時間設定
                    if (mob != null) {
                        var next = file.CreationTime.AddMinutes(mob.Delay * Properties.Settings.Default.RepopRate);
                        var random = next.AddMinutes(mob.Random * Properties.Settings.Default.RepopRate);

                        unit.Repop = (next == random)
                            ? next.ToString("HH:mm") : next.ToString("HH:mm") + "~" + random.ToString("HH:mm");
                    }

                    // カウンタ更新
                    if (config.Exists(unit.Id)) {
                        config.Increment(unit.Id);
                    } else {
                        config.Insert(unit.Id);
                    }

                    file.MoveTo(saveDir.FullName + "\\" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-" + file.Name);
                }

                // カウンタ再読込
                foreach (var counter in config.KillCounters) {
                    var unit = SelectedPatch.Units.FirstOrDefault(a => a.Id == counter.Id);
                    if (unit != null)
                        unit.Kill = counter.Count;
                }

                MessageBar.Show(MessageType.Info, "Scan : " + DateTime.Now.ToString("HH:mm:ss"));
            } catch (Exception ex) {
                MessageBar.Show(MessageType.Error, ex.Message);
            }
        }