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); } }
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); }
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; } }
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; } } }
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() + "."); }
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; }
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); } }