Exemple #1
0
        private void NewChatLines(object sender, LogFile.EveChatEventArgs e)
        {
            LogFile curLog = (LogFile)sender;

            // check for channel ignore list
            if (IsIgnoredChannel(curLog))
            {
                return;
            }

            string logLines = e.NewLogLines;

            // check log lines - line for line
            StringReader sr = new StringReader(logLines);

            string curLine = null;

            while ((curLine = sr.ReadLine()) != null)
            {
                curLine = curLine.Trim();

                LogEntry le = LogReader.GetLogEntry(curLine);

                if (Properties.Settings.Default.LogAllMessages)
                {
                    Logging.WriteLine(string.Format("{3}: Message from '{0}' in '{1}': {2}", le.Sender, curLog.LogInfo.ChannelName, le.Text, curLog.LogInfo.PilotName));
                }

                // unable to read sender - but we need it so do nothing
                if (string.IsNullOrWhiteSpace(le.Sender))
                {
                    continue;
                }

                // check if sender is current user (ignore if user wants to ignore this messages)
                if (Properties.Settings.Default.IgnoreOwnMessages && le.Sender.Equals(curLog.LogInfo.PilotName, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                // check if sender is "EVE-System" to prevent MOTD notifications
                if (Properties.Settings.Default.IgnoreMotd && le.Sender.Equals(Properties.Settings.Default.MotdUsername.Trim(), StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                // check if the sender is on the ignore list
                if (IsIgnoredPilot(le))
                {
                    continue;
                }
                bool needsNotify = false;
                // check if sender or channel is in always list
                if (IsAlwaysPilot(le) || IsAlwaysChannel(curLog))
                {
                    needsNotify = true;
                }
                // check if notification is needed
                if (le.Text.ToLower().Contains(curLog.LogInfo.PilotName.ToLower()))
                {
                    needsNotify = true;
                }
                if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.NotifyKeywords))
                {
                    string[] alsoCheck = Properties.Settings.Default.NotifyKeywords.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string toCheck in alsoCheck)
                    {
                        if (le.Text.ToLower().Contains(toCheck.Trim().ToLower()))
                        {
                            needsNotify = true;
                            break;
                        }
                    }
                }

                // if notification is needed
                if (needsNotify) // isPlaying is managing the notification using sound (only one at a time)
                {
                    Logging.WriteLine(string.Format("{3}: Notify for chat message of '{0}' in '{1}': {2}", le.Sender, curLog.LogInfo.ChannelName, le.Text, curLog.LogInfo.PilotName));
                    Notifier.GetInstance().Notify(string.Format("{0} in '{1}'", le.Sender, curLog.LogInfo.ChannelName), le.Text, PathHelper.DecryptPath(Properties.Settings.Default.SoundFilePath));
                }
            }
        }
Exemple #2
0
        public FormMain()
        {
            // properties upgrade logic
            if (Properties.Settings.Default.NeedsUpgrade)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.NeedsUpgrade = false;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
            }

            // bugfix for empty paths
            bool pathFix = false;

            if (string.IsNullOrWhiteSpace(Properties.Settings.Default.MoveOldLogsPath))
            {
                Properties.Settings.Default.MoveOldLogsPath = "%DEFAULT_EVEOLDPATH%";
                pathFix = true;
            }
            if (string.IsNullOrWhiteSpace(Properties.Settings.Default.EveChatLogsPath))
            {
                Properties.Settings.Default.EveChatLogsPath = "%DEFAULT_EVELOGPATH%";
                pathFix = true;
            }
            if (pathFix)
            {
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
            }

            // first launch ask for move logs
            if (!Properties.Settings.Default.AskedToMoveLogs)
            {
                if (!Properties.Settings.Default.MoveOldLogs)
                {
                    if (MessageBox.Show(string.Format("Do you want to let the program move your old log files?{0}{0}Moving the log files is a huge performance boost and highly recommended! If you do not move the logs, this program could need a lot of cpu power.{0}{0}This can be enabled/disabled in the settings at any time.", Environment.NewLine), "Activate log moving", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        Properties.Settings.Default.MoveOldLogs = true;
                    }
                }

                Properties.Settings.Default.AskedToMoveLogs = true;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
            }

            // set real paths
            PathEveChatLogs = PathHelper.DecryptPath(Properties.Settings.Default.EveChatLogsPath);
            PathMoveOldLogs = PathHelper.DecryptPath(Properties.Settings.Default.MoveOldLogsPath);
            PathSoundFile   = PathHelper.DecryptPath(Properties.Settings.Default.SoundFilePath);

            // create old log folder if needed (and move logs)
            if (Properties.Settings.Default.MoveOldLogs)
            {
                if (!System.IO.Directory.Exists(PathMoveOldLogs))
                {
                    System.IO.Directory.CreateDirectory(PathMoveOldLogs);
                }

                // move old logs
                string[] logFiles = System.IO.Directory.GetFiles(PathEveChatLogs, "*.txt", SearchOption.TopDirectoryOnly);
                foreach (string logFile in logFiles)
                {
                    string moveDestination = System.IO.Path.Combine(PathMoveOldLogs, System.IO.Path.GetFileName(logFile));
                    try
                    {
                        System.IO.File.Move(logFile, moveDestination);
                        Logging.WriteLine(string.Format("Moved old log file '{0}' to '{1}'", logFile, moveDestination));
                    }
                    catch (Exception ex)
                    {
                        Logging.WriteLine(string.Format("Unable to move old log '{0}' to '{1}'", logFile, moveDestination));
                    }
                }
            }

            // delete old logs
            if (Properties.Settings.Default.DeleteLogs)
            {
                string[] logFIles = System.IO.Directory.GetFiles(PathEveChatLogs, "*.txt", SearchOption.TopDirectoryOnly);
                foreach (string logFIle in logFIles)
                {
                    try
                    {
                        System.IO.File.Delete(logFIle);
                        Logging.WriteLine(string.Format("Deleted old log file '{0}'", logFIle));
                    }
                    catch (Exception ex)
                    {
                        Logging.WriteLine(string.Format("Unablt to delete old log '{1}':{0}´{1}", Environment.NewLine, logFIle, ex.ToString()));
                    }
                }
            }

            Logging.WriteLine("Starting chat notifier.");

            this.StartPosition = FormStartPosition.Manual;
            this.Location      = new Point(int.MinValue, int.MinValue);
            InitializeComponent();

            // set version information
            notifyIcon.Text = string.Format("EveChatNotifier - v{0}", Application.ProductVersion);

            // initialize timer - this timer has to watch all folders for log files
            Logging.WriteLine("Starting log watcher timer");
            t.Tick    += T_Tick;
            t.Interval = Properties.Settings.Default.EveChatLogCheckInterval * 1000; // check all X seconds for new log files
            t.Start();
            T_Tick(null, null);

            // generate notify menu entries
            ContextMenu cm             = new ContextMenu();
            MenuItem    cmExit         = new MenuItem("Exit");
            MenuItem    cmSettings     = new MenuItem("Settings");
            MenuItem    cmHomepage     = new MenuItem("Homepage");
            MenuItem    cmVersion      = new MenuItem(string.Format("v{0}", Application.ProductVersion));
            MenuItem    cmCheckUpdate  = new MenuItem("Check for update");
            MenuItem    cmContributors = new MenuItem("Contributors");

            // version
            cmVersion.Enabled = false;
            cm.MenuItems.Add(cmVersion);

            // auto update check
            cmCheckUpdate.Click += CmCheckUpdate_Click;
            cm.MenuItems.Add(cmCheckUpdate);

            cm.MenuItems.Add("-");

            // settings
            cmSettings.Click += CmSettings_Click;
            cm.MenuItems.Add(cmSettings);

            cm.MenuItems.Add("-");

            // homepage
            cmHomepage.Click += CmHomepage_Click;
            cm.MenuItems.Add(cmHomepage);

            // made by / contributors
            cmContributors.Click += CmContributors_Click;
            cm.MenuItems.Add(cmContributors);

            cm.MenuItems.Add("-");

            // exit
            cmExit.Click += CmExit_Click;
            cm.MenuItems.Add(cmExit);

            notifyIcon.ContextMenu = cm;

            // autostart
            try
            {
                Autostart.ManageAutostart.Instance.CheckTask();
            }
            catch (Exception ex)
            {
                Logging.WriteLine(string.Format("Error checking for autostart:{0}{1}", Environment.NewLine, ex.ToString()));
            }
        }