using System; using System.Diagnostics; using System.Drawing; using System.IO; using System.Windows.Forms; using StarfaceOutlookSync.Models; using StarfaceOutlookSync.Services; namespace StarfaceOutlookSync.UI { /// Zeigt das Sync-Protokoll an (read-only) mit Aktualisieren/Leeren. public class LogViewerForm : Form { private TextBox _txt; private Button _btnClose; private Panel _panel; public LogViewerForm() { Text = "Protokoll"; Size = new Size(720, 500); StartPosition = FormStartPosition.CenterParent; Font = new Font("Segoe UI", 9); _txt = new TextBox { Multiline = true, ReadOnly = true, ScrollBars = ScrollBars.Both, WordWrap = false, Dock = DockStyle.Fill, BackColor = Color.White, Font = new Font("Consolas", 9) }; _panel = new Panel { Dock = DockStyle.Bottom, Height = 44 }; var btnRefresh = new Button { Text = "Aktualisieren", Left = 10, Top = 8, Width = 100, Height = 28 }; btnRefresh.Click += (s, e) => LoadLog(); var btnClear = new Button { Text = "Leeren", Left = 118, Top = 8, Width = 80, Height = 28 }; btnClear.Click += (s, e) => { if (MessageBox.Show("Protokoll wirklich leeren?", "Protokoll", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Logger.Clear(); LoadLog(); } }; var btnFolder = new Button { Text = "Ordner oeffnen", Left = 206, Top = 8, Width = 120, Height = 28 }; btnFolder.Click += (s, e) => OpenFolder(); _btnClose = new Button { Text = "Schliessen", Top = 8, Width = 100, Height = 28, Anchor = AnchorStyles.Top | AnchorStyles.Right }; _btnClose.Click += (s, e) => Close(); _panel.Controls.AddRange(new Control[] { btnRefresh, btnClear, btnFolder, _btnClose }); Controls.Add(_txt); Controls.Add(_panel); Load += (s, e) => { _btnClose.Left = _panel.ClientSize.Width - _btnClose.Width - 10; LoadLog(); }; } private void LoadLog() { Logger.PruneOlderThan(UserSettings.Load().LogRetentionDays); _txt.Text = Logger.ReadAll(); _txt.SelectionStart = _txt.TextLength; _txt.ScrollToCaret(); } private void OpenFolder() { try { var dir = Path.GetDirectoryName(Logger.LogFilePath); Process.Start(new ProcessStartInfo { FileName = dir, UseShellExecute = true }); } catch { } } } }