Monitors a log file for changes in the form of appended lines.
예제 #1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     NotificationIcon.Visible            = Settings.Default.TrayNotifications || Settings.Default.MinimizeToTray;
     NotificationIcon.BalloonTipClicked += NotificationIconClick;
     NotificationIcon.DoubleClick       += NotificationIconClick;
     txtLogPath.TextChanged             += txtLogPath_TextChanged;
     txtLogPath.Click += txtLogPath_Click;
     txtLogPath.Text   = Settings.Default.LogPath;
     // TODO: Most of these could be easily replaced with a method to map the toolstrip to the setting.
     tsmNotifyMinimizedOnly.Checked     = Settings.Default.NotifyMinimizedOnly;
     tsmEnableTrayNotifications.Checked = Settings.Default.TrayNotifications;
     tsmEnableSMTPNotifications.Checked = Settings.Default.EnableSmtpNotifications;
     tsmEnablePushBullet.Checked        = Settings.Default.EnablePushbullet;
     tsmEnableSound.Checked             = Settings.Default.EnableSound;
     tsmAutoStart.Checked        = Settings.Default.AutoStartWhenOpened;
     tsmMinimizeToTray.Checked   = Settings.Default.MinimizeToTray;
     tsmLogPartyMessages.Checked = Settings.Default.LogPartyMessages;
     this.Resize += Main_Resize;
     if (!LogMonitor.IsValidLogPath(txtLogPath.Text))
     {
         string DefaultLogPath;
         if (LogMonitor.TryGetDefaultLogPath(out DefaultLogPath))
         {
             txtLogPath.Text = DefaultLogPath;
         }
         else
         {
             AppendMessage("Unable to figure out client.txt location. You will have to manually set the path.");
         }
     }
     if (Settings.Default.AutoStartWhenOpened)
     {
         Start(true);
     }
 }
예제 #2
0
 private void StartMonitoring(bool AutoStarted)
 {
     if (!LogMonitor.IsValidLogPath(txtLogPath.Text))
     {
         string ErrMsg = "Failed to start " + (AutoStarted ? "automatically " : "") + "as the log path is invalid.";
         if (AutoStarted)
         {
             LogMessage(ErrMsg, null, LogMessageType.Status);
         }
         else
         {
             MessageBox.Show(ErrMsg);
         }
         return;
     }
     if (new FileInfo(txtLogPath.Text).IsReadOnly)
     {
         LogMessage("Warning: Your client.txt file appears to be readonly. This will likely prevent the program from working.", null, LogMessageType.Status);
     }
     cmdStop.Enabled  = true;
     cmdStart.Enabled = false;
     this.Monitor     = new LogMonitor(txtLogPath.Text);
     Monitor.BeginMonitoring();
     Monitor.MessageReceived += ProcessMessage;
     IdleManager.BeginMonitoring();
     LogMessage("Program started at " + DateTime.Now.ToShortTimeString() + ".", null, LogMessageType.Status);
 }
예제 #3
0
 void txtLogPath_TextChanged(object sender, EventArgs e)
 {
     if (LogMonitor.IsValidLogPath(txtLogPath.Text))
     {
         txtLogPath.BackColor     = Color.FromKnownColor(KnownColor.Window);
         Settings.Default.LogPath = txtLogPath.Text;
         Settings.Default.Save();
     }
     else
     {
         txtLogPath.BackColor = Color.DarkRed;
     }
 }
예제 #4
0
 void txtLogPath_Click(object sender, EventArgs e)
 {
     using (var OFD = new OpenFileDialog()) {
         string CurrPath = txtLogPath.Text ?? Settings.Default.LogPath;
         OFD.Filter = "Log File|Client.txt|All Files (*.*)|*.*";
         if (LogMonitor.IsValidLogPath(CurrPath))
         {
             OFD.InitialDirectory = CurrPath;
         }
         if (OFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             txtLogPath.Text = OFD.FileName;
         }
     }
 }
예제 #5
0
 private void Start(bool AutoStarted)
 {
     if (!LogMonitor.IsValidLogPath(txtLogPath.Text))
     {
         string ErrMsg = "Failed to start " + (AutoStarted ? "automatically " : "") + "as the log path is invalid.";
         if (AutoStarted)
         {
             AppendMessage(ErrMsg);
         }
         else
         {
             MessageBox.Show(ErrMsg);
         }
         return;
     }
     cmdStop.Enabled  = true;
     cmdStart.Enabled = false;
     this.Monitor     = new LogMonitor(txtLogPath.Text);
     Monitor.BeginMonitoring();
     Monitor.MessageReceived += ProcessMessage;
     IdleManager.BeginMonitoring();
     AppendMessage("Program started at " + DateTime.Now.ToShortTimeString() + ".");
 }
예제 #6
0
        public Main()
        {
            InitializeComponent();
            NotificationIcon.Icon = this.Icon;

            // Have to initialize in the ctor in order to handle Load with Minimize to Tray.
            this.MessageConfig                  = MessageSettings.LoadFromConfig();
            NotificationIcon.Visible            = Settings.Default.TrayNotifications || Settings.Default.MinimizeToTray;
            NotificationIcon.BalloonTipClicked += NotificationIconClick;
            NotificationIcon.DoubleClick       += NotificationIconClick;
            txtLogPath.TextChanged             += txtLogPath_TextChanged;
            txtLogPath.Click += txtLogPath_Click;
            txtLogPath.Text   = Settings.Default.LogPath;
            // TODO: Most of these could be easily replaced with a method to map the toolstrip to the setting.
            tsmNotifyMinimizedOnly.Checked     = Settings.Default.NotifyMinimizedOnly;
            tsmEnableTrayNotifications.Checked = Settings.Default.TrayNotifications;
            tsmEnableSMTPNotifications.Checked = Settings.Default.EnableSmtpNotifications;
            tsmEnablePushBullet.Checked        = Settings.Default.EnablePushbullet;
            tsmEnableSound.Checked             = Settings.Default.EnableSound;
            tsmMinimizeToTray.Checked          = Settings.Default.MinimizeToTray;
            tsmStartMinimized.Checked          = Settings.Default.StartMinimized;
            RestoreSize();
            this.Resize += Main_Resize;
            if (!LogMonitor.IsValidLogPath(txtLogPath.Text))
            {
                if (LogMonitor.TryGetDefaultLogPath(out string DefaultLogPath))
                {
                    txtLogPath.Text = DefaultLogPath;
                }
                else
                {
                    LogMessage("Unable to figure out client.txt location. You will have to manually set the path.", null, LogMessageType.Status);
                }
            }
            this.ResizeEnd += OnResizeEnd;
        }
예제 #7
0
 private void Start()
 {
     if(!LogMonitor.IsValidLogPath(txtLogPath.Text)) {
         MessageBox.Show("The log path you have entered is invalid. Please select the client.txt file located in the PoE folder.");
         return;
     }
     cmdStop.Enabled = true;
     cmdStart.Enabled = false;
     this.Monitor = new LogMonitor(txtLogPath.Text);
     Monitor.BeginMonitoring();
     Monitor.MessageReceived += ProcessMessage;
     IdleManager.BeginMonitoring();
 }
예제 #8
0
        void ProcessMessage(MessageData obj)
        {
            if (obj.MessageType == LogMessageType.Party && !Settings.Default.LogPartyMessages)
            {
                return;
            }
            if (Settings.Default.NotifyMinimizedOnly && IsPoeActive())
            {
                if (!IdleManager.IsUserIdle)
                {
                    // If the user isn't idle, replay the message if they do go idle.
                    IdleManager.AddIdleAction(() => ProcessMessage(obj));
                    return;
                }
                // Otherwise, they are idle, so process the message anyways.
            }
            string StampedMessage = "[" + obj.Date.ToShortTimeString() + "]" + (obj.Sender == null ? "" : (" " + LogMonitor.ChatSymbolForMessageType(obj.MessageType) + obj.Sender)) + ": " + obj.Message;
            string Title          = "Path of Exile " + obj.MessageType;

            Invoke(new Action(() => AppendMessage(StampedMessage)));
            if (Settings.Default.TrayNotifications)
            {
                Invoke(new Action(() => {
                    NotificationIcon.Visible = true;
                    NotificationIcon.ShowBalloonTip(5000, Title, (obj.Sender == null ? "" : (obj.Sender + ": ")) + obj.Message, ToolTipIcon.Info);
                }));
            }
            if (Settings.Default.EnableSound)
            {
                try {
                    this.SoundPlayer.Play();
                } catch (Exception ex) {
                    AppendMessage("<Error playing sound. This usually occurs due to the Content folder being missing.\r\n  Additional Info: " + ex.Message + ">");
                }
            }
            if (Settings.Default.EnableSmtpNotifications)
            {
                // Feels wasteful to always reload, but really it should only take a millisecond or less.
                var SmtpSettings = SmtpDetails.LoadFromSettings();
                var SmtpAct      = CheckedAction("SMTP", () => SendSmtpNotification(SmtpSettings, StampedMessage));
                if (!SmtpSettings.NotifyOnlyIfIdle)
                {
                    SmtpAct();
                }
                else
                {
                    IdleManager.AddIdleAction(SmtpAct);
                }
            }
            if (Settings.Default.EnablePushbullet)
            {
                var PbSettings = PushBulletDetails.LoadFromSettings();
                var PbAct      = CheckedAction("PushBullet", () => {
                    var Client = new PushBulletClient(PbSettings);
                    Client.SendPush(Title, StampedMessage);
                });
                if (!PbSettings.NotifyOnlyIfIdle)
                {
                    PbAct();
                }
                else
                {
                    IdleManager.AddIdleAction(PbAct);
                }
            }
        }
예제 #9
0
 private void Start(bool AutoStarted)
 {
     if(!LogMonitor.IsValidLogPath(txtLogPath.Text)) {
         string ErrMsg = "Failed to start " + (AutoStarted ? "automatically " : "") + "as the log path is invalid.";
         if (AutoStarted)
             AppendMessage(ErrMsg);
         else
             MessageBox.Show(ErrMsg);
         return;
     }
     cmdStop.Enabled = true;
     cmdStart.Enabled = false;
     this.Monitor = new LogMonitor(txtLogPath.Text);
     Monitor.BeginMonitoring();
     Monitor.MessageReceived += ProcessMessage;
     IdleManager.BeginMonitoring();
     AppendMessage("Program started at " + DateTime.Now.ToShortTimeString() + ".");
 }
예제 #10
0
        private void trimClienttxtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string LogPath = txtLogPath.Text;

            if (!LogMonitor.IsValidLogPath(LogPath))
            {
                MessageBox.Show("You must select a valid client.txt first.");
                return;
            }
            var  LogLength     = new FileInfo(LogPath).Length;
            long DesiredLength = 10 * 1024 * 1024;

            if (LogLength <= DesiredLength)
            {
                MessageBox.Show("Your client.txt is already below 10MB. No action has been taken.");
                return;
            }
            if (MessageBox.Show("This will remove old data from your client.txt (currently " + LogLength / (1024 * 1024) + "MB) to reduce it to 10MB. Are you sure you wish to do this? This process is NOT reversible.", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
            {
                return;
            }
            if (GetPoeProcess() != null)
            {
                MessageBox.Show("You must close Path of Exile for this operation to work.", "Failed to Trim Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            bool RestartLog = Monitor.IsMonitoring;

            if (Monitor.IsMonitoring)
            {
                StopMonitoring();
            }
            try {
                string CopyLocation   = LogPath + ".new";
                string BackupLocation = LogPath + ".old";
                if (File.Exists(BackupLocation))
                {
                    MessageBox.Show("A log file already appears to exist from before. Please delete it if it is not valid.");
                    Process.Start(new ProcessStartInfo()
                    {
                        UseShellExecute = true,
                        Verb            = "open",
                        FileName        = Path.GetDirectoryName(BackupLocation)
                    });
                    return;
                }
                using (var LogFile = File.Open(LogPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete)) {
                    LogFile.Seek(-DesiredLength, SeekOrigin.End);
                    if (File.Exists(CopyLocation))
                    {
                        File.Delete(CopyLocation);
                    }
                    using (var OutFile = File.CreateText(CopyLocation))
                        LogFile.CopyTo(OutFile.BaseStream);
                    File.Move(LogPath, BackupLocation);
                    File.Move(CopyLocation, LogPath);
                    File.Delete(BackupLocation);
                }
                LogMessage("Trimmed log file from " + (LogLength / (1024 * 1024)) + "MB to 10MB.", null, LogMessageType.Status);
                MessageBox.Show("Done. Your log file has been trimmed.");
            } catch (Exception ex) {
                MessageBox.Show("Failed to trim log file:\r\n\t" + ex.Message.Replace("\n", "\n\t") + "\r\nIf your client.txt was modified, you may find a backup at client.txt.old.");
            }
            if (RestartLog)
            {
                StartMonitoring(false);
            }
        }