public static PropertyManager getManager()
        {
            if (singleton == null) {
                singleton = new PropertyManager();
            }

            return singleton;
        }
Example #2
0
        private void logReaderEvent(object sender, LogEventArgs e)
        {
            logger.Debug("logReaderEvent " + e.line);
            RichTextBox textBox  = null;
            CheckBox    checkBox = null;

            switch (e.type)
            {
            case LogReader.logTypes.OFFICER_CHAT:
                textBox  = txtOfficerChat;
                checkBox = chkOfficerScroll;
                break;

            case LogReader.logTypes.GUILD_CHAT:
                textBox  = txtGuildChat;
                checkBox = chkGuildScroll;
                break;

            case LogReader.logTypes.TELLS:
                textBox  = txtTells;
                checkBox = chkTellsScroll;
                break;
            }

            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (textBox != null)
            {
                if (textBox.InvokeRequired)
                {
                    logger.Debug("Invoking for thread saftey...");
                    LogReaderEvent d = new LogReaderEvent(logReaderEvent);
                    this.Invoke(d, new object[] { sender, e });
                }
                else
                {
                    logger.Debug("Setting the text...");
                    // Save the starting positions of the current cursor and selected text
                    int start = textBox.SelectionStart;
                    int len   = textBox.SelectionLength;
                    textBox.SelectionColor = Color.Black;

                    // remove initial timestamp
                    int    firstChat = e.line.IndexOf(']') + 2;
                    string theLine   = e.line.Substring(firstChat, e.line.Length - firstChat);

                    if (textBox == txtGuildChat)
                    {
                        bool isLootChat = guildLootChat.IsMatch(e.line) || (e.line.Split(new string[] { " // " }, StringSplitOptions.None).Length > 1);

                        if (!isLootChat)
                        {
                            if (chkGuildLootOnly.Checked)
                            {
                                guildChatBuffer.Add(theLine);
                            }
                            else
                            {
                                if (textBox.Lines.Length > 0)
                                {
                                    textBox.AppendText(Environment.NewLine);
                                }

                                textBox.AppendText(theLine);
                            }
                        }
                        else
                        {
                            guildChatBuffer.Add(theLine);

                            if (textBox.Lines.Length > 0)
                            {
                                textBox.AppendText(Environment.NewLine);
                            }

                            textBox.AppendText(theLine);
                        }

                        if (checkBox.Checked)
                        {
                            textBox.SelectionStart = textBox.Text.Length;
                        }
                        else
                        {
                            textBox.SelectionStart  = start;
                            textBox.SelectionLength = len;
                        }
                    }
                    else
                    {
                        if (textBox.Lines.Length > 0)
                        {
                            textBox.AppendText(Environment.NewLine);
                        }

                        textBox.AppendText(theLine);
                    }

                    textBox.ScrollToCaret();
                }
            }
            else if (e.type == LogReader.logTypes.LOOT)
            {
                // Group 0 is everything       Group 1     Group 2     Group 3
                //[Sun May 13 20:20:29 2018] --(You) have (looted) a (Enchanted Runestone).--
                if (e.matches[0].Groups.Count == 4)
                {
                    string userName = e.matches[0].Groups[1].Value;
                    if ("You".Equals(userName))
                    {
                        userName = PropertyManager.getManager().getProperty("UserName");
                        if (userName == null)
                        {
                            userName = "******";
                        }
                    }

                    string[] row = { userName, e.matches[0].Groups[3].Value };

                    this.Invoke(new MethodInvoker(delegate()
                    {
                        lootLogView.Items.Add(new ListViewItem(row));
                    }
                                                  ));
                }
            }
        }
Example #3
0
        public frmMain()
        {
            InitializeComponent();
            Refresh();
            logger.Info("Main form initialized.");

            try
            {
                roster              = new Roster();
                lootLog             = new LootLog();
                logReader           = new LogReader();
                logReader.logEvent += new LogReaderEvent(logReaderEvent);
                itemListing         = new ItemListing();

                string savedFile = PropertyManager.getManager().getProperty("EQlogFile");
                if (savedFile != null)
                {
                    if (logReader.setLogFile(savedFile))
                    {
                        logReader.start();
                        grpChatLogs.Text = String.Format("Chat Logs ({0})", savedFile);
                    }
                }

                logRefresher = new Thread(updateLootLog);
                logRefresher.Start();

                this.Text = "ROI Loot Manager - v" + Constants.PROGRAM_VERSION;

                Form mainFrm = this;
                timer.Elapsed += new System.Timers.ElapsedEventHandler(
                    (object timerSender, ElapsedEventArgs timerEvent) =>
                {
                    mainFrm.Invoke(new MethodInvoker(delegate()
                    {
                        lblStatus.Text = "";
                        timer.Enabled  = false;
                    }));
                }
                    );

                timer.Interval = 2000;
                timer.Enabled  = false;
            }
            catch (Exception e)
            {
                string message = "Could not get one of the worksheets used. A severe error occured or you may not have access. The program will close.";
                logger.Error(message, e);
                MessageBox.Show(message);
                System.Environment.Exit(-1);
            }

            cmbName.DataSource    = roster.getActiveNames();
            cmbName.DisplayMember = Roster.NAME_COL;
            cmbName.ValueMember   = Roster.NAME_COL;
            cmbName.SelectedIndex = -1;

            cmbEvent.DataSource    = lootLog.getEvents();
            cmbEvent.DisplayMember = "shortName";
            cmbEvent.ValueMember   = "shortName";
            cmbEvent.SelectedIndex = -1;

            cmbSlot.DataSource    = lootLog.getArmorTypes();
            cmbSlot.DisplayMember = "armorType";
            cmbSlot.ValueMember   = "armorType";
            cmbSlot.SelectedIndex = -1;

            dteRaidDate.Value = DateTime.Today;

            loadRosterNames();

            List <String> savedTierList = new List <String>();
            string        prop          = PropertyManager.getManager().getProperty(PropertyManager.LAST_TIER_SELECTED);

            if (prop != null)
            {
                savedTierList.AddRange(prop.Split());
            }

            List <String> tierList = lootLog.getTiers();

            foreach (String t in tierList)
            {
                ListViewItem item = new ListViewItem(t);
                item.Text = t;
                item.Name = t;

                if (savedTierList.Contains(t))
                {
                    item.Checked = true;
                }

                lvTierSelection.Items.Add(item);
            }

            includeRots = false;

            chkIncludeRots.Checked = includeRots;

            dgvLootSummary.SortCompare       += new DataGridViewSortCompareEventHandler(lootSummarySorter);
            dgvVisibleSummary.SortCompare    += new DataGridViewSortCompareEventHandler(lootSummarySorter);
            dgvNonVisibleSummary.SortCompare += new DataGridViewSortCompareEventHandler(lootSummarySorter);
            dgvWeaponSummary.SortCompare     += new DataGridViewSortCompareEventHandler(lootSummarySorter);
            lvRosterNames.ItemChecked        += new ItemCheckedEventHandler(lvRosterNames_ItemChecked);
            lvTierSelection.ItemChecked      += new ItemCheckedEventHandler(lvTierSelection_ItemChecked);
            lootLogView.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(selectLoot);
        }