private void LoadMatches()
        {
            string selection = $"{listBox1.SelectedItem}";

            if (string.IsNullOrEmpty(selection))
            {
                MessageBox.Show("No Selection!");
                return;
            }

            LogFileItem lfi = LogFileItem.List.Single(a => a.CombinedName == selection);


            if (lfi == null)
            {
                MessageBox.Show("lfi is null");;
                return;
            }


            this.Hide();
            frmShowMatches frm = new frmShowMatches(lfi);

            frm.Focus();
            frm.ShowDialog();
            this.Show();
        }
        private void ReadChatLogFile()
        {
            string selection = $"{listBox1.SelectedItem}";

            if (string.IsNullOrEmpty(selection))
            {
                MessageBox.Show("No Selection!");
                return;
            }

            LogFileItem lfi = LogFileItem.List.Single(a => a.CombinedName == selection);


            if (lfi == null)
            {
                MessageBox.Show("lfi is null");;
                return;
            }

            string path = lfi.File;

            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (StreamReader sr = new StreamReader(fs))
                {
                    string content = sr.ReadToEnd();

                    ProcessContent(content, lfi);
                }
        }
Ejemplo n.º 3
0
        private static string GetFileName(LogFileItem lfi)
        {
            string fileName      = $"{lfi.GlobalName}__{lfi.LocalName}.json";
            string directoryName = IOHelper.RootPath;

            return(Path.Combine(directoryName, fileName));
        }
Ejemplo n.º 4
0
 public static void Load(LogFileItem lfi)
 {
     _fileName = GetFileName(lfi);
     if (File.Exists(_fileName))
     {
         string jsonContent = File.ReadAllText(_fileName);
         BadgeManager.List = JsonConvert.DeserializeObject <List <BadgeItem> >(jsonContent);
     }
     else
     {
         BadgeManager.List = new List <BadgeItem>();
     }
 }
        private void LoadAccountsListing()
        {
            listBox1.Items.Clear();
            string rootPath = DetectConfig.Instance.FolderPath;

            if (string.IsNullOrEmpty(rootPath))
            {
                return;
            }
            if (!Directory.Exists(rootPath))
            {
                return;
            }

            string ymd = DateTime.Today.ToString("yyyy-MM-dd");

            string[] founds = Directory.GetFiles(rootPath, $"chatlog {ymd}.txt", SearchOption.AllDirectories);


            LogFileItem.List.Clear();

            foreach (string found in founds)
            {
                string   rightPart = found.Replace(rootPath, string.Empty);
                string[] parts     = rightPart.Split('\\');


                LogFileItem lfi = new LogFileItem {
                    File = found
                };
                lfi.GlobalName = parts.ToList().Where(a => !string.IsNullOrEmpty(a)).First();
                lfi.FetchData();

                if (string.IsNullOrEmpty(lfi.LocalName))
                {
                    continue;
                }

                listBox1.Items.Add(lfi.CombinedName);

                LogFileItem.List.Add(lfi);
            }


            if (listBox1.Items.Count > 0)
            {
                listBox1.SetSelected(0, true);
            }
        }
        private void ProcessContent(string content, LogFileItem lfi)
        {
            BadgeManager.Load(lfi);
            DateTime startDateTime = lfi.StartDate;

            string[] lines = content.Split('\r');


            var badgesEntries = lines.Where(a => a.EndsWith(BadgeLine) || a.Contains(BadgeLine2));

            foreach (string badgeEntry in badgesEntries)
            {
                //"2019-12-28 12:37:03 " -- cut first 20
                string   date     = badgeEntry.Substring(0, 20);
                DateTime lineDate = DateTime.Parse(date);
                if (lineDate > startDateTime)
                {
                    string line = badgeEntry.Substring(20, badgeEntry.Length - 20);
                    if (line.EndsWith(BadgeLine))
                    {
                        line = line.Replace(BadgeLine, string.Empty);
                        BadgeManager.Add(new BadgeItem {
                            Name = line, Selected = true
                        });
                    }
                    if (line.Contains(BadgeLine2))
                    {
                        line = line.Replace(BadgeLine2, string.Empty);
                        line = line.Replace("badge.", string.Empty);
                        line = line.Trim();
                        BadgeManager.Add(new BadgeItem {
                            Name = line, Selected = true
                        });
                    }
                }
            }



            BadgeManager.Save();

            MessageBox.Show("Chat log file detection completed!");


            //LoadUI();

            LoadMatches();
        }
 public frmShowMatches(LogFileItem lfi)
 {
     _lfi = lfi;
     InitializeComponent();
 }