LD-Uninstaller/src-csharp/LDUninstaller.UI/Dialogs/LogViewerWindow.xaml.cs

82 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
namespace LDUninstaller.UI.Dialogs
{
public partial class LogViewerWindow : Window
{
public LogViewerWindow()
{
InitializeComponent();
Loaded += (s, e) => LoadLog();
}
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void LoadLog()
{
try
{
if (File.Exists(App.LogFilePath))
{
using var fs = new FileStream(App.LogFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var reader = new StreamReader(fs);
txtLog.Text = reader.ReadToEnd();
txtLog.ScrollToEnd();
}
else
{
txtLog.Text = "Henüz bir log kaydı oluşturulmadı.";
}
}
catch (Exception ex)
{
txtLog.Text = $"Log dosyası okunamadı: {ex.Message}";
}
}
private void BtnRefresh_Click(object sender, RoutedEventArgs e) => LoadLog();
private void BtnCopy_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(txtLog.Text))
{
Clipboard.SetText(txtLog.Text);
MessageBox.Show("Log metni panoya kopyalandı.", "Kopyalandı", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void BtnOpenExternal_Click(object sender, RoutedEventArgs e)
{
try
{
if (File.Exists(App.LogFilePath))
Process.Start(new ProcessStartInfo("notepad.exe", App.LogFilePath) { UseShellExecute = true });
}
catch { }
}
private void BtnClear_Click(object sender, RoutedEventArgs e)
{
try
{
if (File.Exists(App.LogFilePath))
File.WriteAllText(App.LogFilePath, string.Empty);
LoadLog();
}
catch { }
}
}
}