838 lines
34 KiB
C#
838 lines
34 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text.Json;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Interop;
|
||
using LDUninstaller.Core.Bulk;
|
||
using LDUninstaller.Core.Discovery;
|
||
using LDUninstaller.Core.InfoAdders;
|
||
using LDUninstaller.Core.Junk;
|
||
using LDUninstaller.Core.Models;
|
||
using LDUninstaller.Core.Services;
|
||
using LDUninstaller.Core.Startup;
|
||
using LDUninstaller.Core.Tweaks;
|
||
using LDUninstaller.UI.Dialogs;
|
||
using Microsoft.Win32;
|
||
|
||
namespace LDUninstaller.UI
|
||
{
|
||
public partial class MainWindow : Window
|
||
{
|
||
private List<ApplicationUninstallerEntry> _allEntries = new();
|
||
private List<ApplicationUninstallerEntry> _filteredEntries = new();
|
||
private List<StartupEntry> _allStartupEntries = new();
|
||
private List<DrivePartitionInfo> _allDrives = new();
|
||
private string? _selectedDriveFilter = null;
|
||
|
||
private readonly System.Windows.Threading.DispatcherTimer _searchDebounceTimer = new()
|
||
{
|
||
Interval = TimeSpan.FromMilliseconds(160)
|
||
};
|
||
|
||
public MainWindow()
|
||
{
|
||
App.Log("MainWindow ctor initialized.");
|
||
InitializeComponent();
|
||
|
||
var ver = typeof(MainWindow).Assembly.GetName().Version;
|
||
if (ver != null && txtAppVersion != null)
|
||
txtAppVersion.Text = $"v{ver.Major}.{ver.Minor}.{ver.Build}";
|
||
|
||
Loaded += MainWindow_Loaded;
|
||
|
||
_searchDebounceTimer.Tick += (s, e) =>
|
||
{
|
||
_searchDebounceTimer.Stop();
|
||
ApplyFilter();
|
||
};
|
||
|
||
miniTreeMap.OnItemSelected += SelectAppFromTreemap;
|
||
fullTreeMap.OnItemSelected += SelectAppFromTreemap;
|
||
|
||
UpdateShellButtonText();
|
||
}
|
||
|
||
protected override void OnSourceInitialized(EventArgs e)
|
||
{
|
||
base.OnSourceInitialized(e);
|
||
SetNativeWindowIcon();
|
||
}
|
||
|
||
private void SetNativeWindowIcon()
|
||
{
|
||
try
|
||
{
|
||
var helper = new WindowInteropHelper(this);
|
||
IntPtr hwnd = helper.Handle;
|
||
if (hwnd == IntPtr.Zero) return;
|
||
|
||
try
|
||
{
|
||
var uri = new Uri("pack://application:,,,/LDUninstaller.UI;component/Resources/app.ico", UriKind.Absolute);
|
||
this.Icon = System.Windows.Media.Imaging.BitmapFrame.Create(uri);
|
||
}
|
||
catch { }
|
||
|
||
string icoPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "app.ico");
|
||
IntPtr hIconBig = IntPtr.Zero;
|
||
IntPtr hIconSmall = IntPtr.Zero;
|
||
|
||
if (File.Exists(icoPath))
|
||
{
|
||
hIconBig = LoadImage(IntPtr.Zero, icoPath, 1, 32, 32, 0x00000010);
|
||
hIconSmall = LoadImage(IntPtr.Zero, icoPath, 1, 16, 16, 0x00000010);
|
||
}
|
||
|
||
if (hIconBig == IntPtr.Zero || hIconSmall == IntPtr.Zero)
|
||
{
|
||
string exe = Process.GetCurrentProcess().MainModule?.FileName ?? "";
|
||
ExtractIconEx(exe, 0, out IntPtr hL, out IntPtr hS, 1);
|
||
if (hIconBig == IntPtr.Zero) hIconBig = hL;
|
||
if (hIconSmall == IntPtr.Zero) hIconSmall = hS;
|
||
}
|
||
|
||
if (hIconBig != IntPtr.Zero)
|
||
SendMessage(hwnd, 0x0080, (IntPtr)1, hIconBig);
|
||
|
||
if (hIconSmall != IntPtr.Zero)
|
||
SendMessage(hwnd, 0x0080, (IntPtr)0, hIconSmall);
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||
private static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad);
|
||
|
||
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
|
||
private static extern int ExtractIconEx(string lpszFile, int nIconIndex, out IntPtr phiconLarge, out IntPtr phiconSmall, int nIcons);
|
||
|
||
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
App.Log("MainWindow_Loaded started.");
|
||
try
|
||
{
|
||
await RefreshDataAsync();
|
||
_ = LoadStartupEntriesAsync();
|
||
_ = LoadDebloatTweaksAsync();
|
||
_ = SilentUpdateCheckAsync();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
App.Log($"LOADED EXCEPTION: {ex}");
|
||
}
|
||
}
|
||
|
||
private async Task SilentUpdateCheckAsync()
|
||
{
|
||
try
|
||
{
|
||
var currentVer = typeof(MainWindow).Assembly.GetName().Version ?? new Version(2, 8, 0);
|
||
var update = await UpdateChecker.CheckForUpdatesAsync(currentVer);
|
||
if (update != null && update.HasUpdate)
|
||
{
|
||
txtUpdateStatus.Text = $"Yeni LD Uninstaller sürümü mevcut: v{update.LatestVersion}";
|
||
btnCheckUpdate.Content = "🔥 Şimdi İndir";
|
||
}
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
private async Task RefreshDataAsync()
|
||
{
|
||
App.Log("RefreshDataAsync starting.");
|
||
txtFooterStatus.Text = "Sistemdeki tüm yazılımlar taranıyor...";
|
||
txtFooterStats.Text = "Yükleniyor...";
|
||
|
||
var pipeline = new DiscoveryPipeline();
|
||
pipeline.OnProgress += (msg, pct) =>
|
||
{
|
||
Dispatcher.Invoke(() => txtFooterStatus.Text = $"{msg} (%{pct})");
|
||
};
|
||
|
||
var list = await pipeline.DiscoverAllAsync();
|
||
App.Log($"DiscoverAllAsync found {list.Count} items.");
|
||
|
||
txtFooterStatus.Text = "Eksik bilgiler, boyutlar ve sertifikalar tamamlanıyor...";
|
||
await Task.Run(() =>
|
||
{
|
||
var adder = new InfoAdderManager();
|
||
adder.ProcessAll(list);
|
||
});
|
||
|
||
_allEntries = list;
|
||
_allDrives = DriveAnalyzer.AnalyzeDrives(_allEntries);
|
||
UpdateDriveTabs();
|
||
ApplyFilter();
|
||
|
||
txtFooterStatus.Text = "Tarama tamamlandı. Sistem hazır.";
|
||
App.Log("RefreshDataAsync completed.");
|
||
}
|
||
|
||
private void UpdateDriveTabs()
|
||
{
|
||
if (wpDriveTabs == null || pnlDriveTabs == null) return;
|
||
|
||
if (_allDrives.Count <= 1)
|
||
{
|
||
pnlDriveTabs.Visibility = Visibility.Collapsed;
|
||
_selectedDriveFilter = null;
|
||
return;
|
||
}
|
||
|
||
pnlDriveTabs.Visibility = Visibility.Visible;
|
||
wpDriveTabs.Children.Clear();
|
||
|
||
var rbAll = new RadioButton
|
||
{
|
||
Content = $"🌐 Tüm Diskler ({_allDrives.Count} Sürücü)",
|
||
IsChecked = string.IsNullOrEmpty(_selectedDriveFilter),
|
||
Style = (Style)FindResource("SidebarNavBtn"),
|
||
Padding = new Thickness(12, 6, 12, 6),
|
||
Margin = new Thickness(0, 0, 8, 0),
|
||
FontSize = 12
|
||
};
|
||
rbAll.Checked += (s, e) =>
|
||
{
|
||
_selectedDriveFilter = null;
|
||
ApplyFilter();
|
||
};
|
||
wpDriveTabs.Children.Add(rbAll);
|
||
|
||
foreach (var drive in _allDrives)
|
||
{
|
||
var rb = new RadioButton
|
||
{
|
||
Content = $"{drive.DisplayTitle} • {drive.DisplayStats}",
|
||
IsChecked = string.Equals(_selectedDriveFilter, drive.DriveLetter, StringComparison.OrdinalIgnoreCase),
|
||
Style = (Style)FindResource("SidebarNavBtn"),
|
||
Padding = new Thickness(12, 6, 12, 6),
|
||
Margin = new Thickness(0, 0, 8, 0),
|
||
FontSize = 12,
|
||
Tag = drive.DriveLetter
|
||
};
|
||
rb.Checked += (s, e) =>
|
||
{
|
||
_selectedDriveFilter = drive.DriveLetter;
|
||
ApplyFilter();
|
||
};
|
||
wpDriveTabs.Children.Add(rb);
|
||
}
|
||
}
|
||
|
||
private void ApplyFilter()
|
||
{
|
||
if (dgApps == null || miniTreeMap == null || fullTreeMap == null || txtFooterStats == null)
|
||
return;
|
||
|
||
string query = txtSearch?.Text?.Trim().ToLowerInvariant() ?? "";
|
||
|
||
bool onlyDesktop = chipDesktop?.IsChecked == true;
|
||
bool onlyStore = chipStore?.IsChecked == true;
|
||
bool onlySteam = chipSteam?.IsChecked == true;
|
||
bool onlyOrphan = chipOrphan?.IsChecked == true;
|
||
bool onlySystem = chipSystem?.IsChecked == true;
|
||
bool onlyOld = chipOld?.IsChecked == true;
|
||
bool onlyBroken = chipBroken?.IsChecked == true;
|
||
|
||
var ninetyDaysAgo = DateTime.Now.AddDays(-90);
|
||
|
||
_filteredEntries = _allEntries.Where(app =>
|
||
{
|
||
if (!string.IsNullOrEmpty(_selectedDriveFilter))
|
||
{
|
||
if (string.IsNullOrWhiteSpace(app.InstallLocation)) return false;
|
||
try
|
||
{
|
||
string? root = Path.GetPathRoot(app.InstallLocation)?.TrimEnd('\\');
|
||
if (!string.Equals(root, _selectedDriveFilter, StringComparison.OrdinalIgnoreCase))
|
||
return false;
|
||
}
|
||
catch { return false; }
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(query))
|
||
{
|
||
bool matchName = app.DisplayName != null && app.DisplayName.Contains(query, StringComparison.OrdinalIgnoreCase);
|
||
bool matchPub = app.Publisher != null && app.Publisher.Contains(query, StringComparison.OrdinalIgnoreCase);
|
||
if (!matchName && !matchPub) return false;
|
||
}
|
||
|
||
if (onlyDesktop && (app.UninstallerKind == UninstallerType.StoreApp || app.SystemComponent || app.IsOrphaned)) return false;
|
||
if (onlyStore && app.UninstallerKind != UninstallerType.StoreApp) return false;
|
||
if (onlySteam && app.UninstallerKind != UninstallerType.Steam) return false;
|
||
if (onlyOrphan && !app.IsOrphaned) return false;
|
||
if (onlySystem && !app.SystemComponent && !app.IsUpdate) return false;
|
||
|
||
// F9: 90+ gün kullanılmayanlar
|
||
if (onlyOld)
|
||
{
|
||
bool isOldDate = app.InstallDate > DateTime.MinValue.AddYears(1) && app.InstallDate < ninetyDaysAgo;
|
||
bool isOldDir = false;
|
||
if (!string.IsNullOrEmpty(app.InstallLocation) && Directory.Exists(app.InstallLocation))
|
||
{
|
||
try { isOldDir = Directory.GetLastWriteTime(app.InstallLocation) < ninetyDaysAgo; } catch { }
|
||
}
|
||
if (!isOldDate && !isOldDir) return false;
|
||
}
|
||
|
||
// F11: Bozuk girdiler
|
||
if (onlyBroken)
|
||
{
|
||
if (!IsBrokenEntry(app)) return false;
|
||
}
|
||
|
||
return true;
|
||
}).ToList();
|
||
|
||
dgApps.ItemsSource = _filteredEntries;
|
||
miniTreeMap.SetData(_filteredEntries);
|
||
fullTreeMap.SetData(_filteredEntries);
|
||
|
||
long totalBytes = _filteredEntries.Sum(x => x.EstimatedSize.Bytes);
|
||
int selectedCount = _filteredEntries.Count(x => x.IsSelected);
|
||
long selectedBytes = _filteredEntries.Where(x => x.IsSelected).Sum(x => x.EstimatedSize.Bytes);
|
||
|
||
string statsPrefix = selectedCount > 0
|
||
? $"{selectedCount} Seçildi ({FileSize.FromBytes(selectedBytes)}) | "
|
||
: "";
|
||
|
||
if (!string.IsNullOrEmpty(_selectedDriveFilter))
|
||
{
|
||
var drive = _allDrives.FirstOrDefault(d => string.Equals(d.DriveLetter, _selectedDriveFilter, StringComparison.OrdinalIgnoreCase));
|
||
if (drive != null)
|
||
{
|
||
txtFooterStats.Text = $"{statsPrefix}{drive.DisplayTitle} | {_filteredEntries.Count} Uygulama ({FileSize.FromBytes(totalBytes)}) | {FileSize.FromBytes(drive.FreeBytes)} Boş Alan";
|
||
if (txtDriveSelectedInfo != null)
|
||
txtDriveSelectedInfo.Text = $"{drive.DisplayTitle}: {drive.DisplayStats}";
|
||
}
|
||
else
|
||
{
|
||
txtFooterStats.Text = $"{statsPrefix}{_filteredEntries.Count} Uygulama | {FileSize.FromBytes(totalBytes)} Toplam Boyut";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
txtFooterStats.Text = $"{statsPrefix}{_filteredEntries.Count} Uygulama | {FileSize.FromBytes(totalBytes)} Toplam Boyut";
|
||
}
|
||
}
|
||
|
||
private static bool IsBrokenEntry(ApplicationUninstallerEntry app)
|
||
{
|
||
if (app.UninstallerKind == UninstallerType.StoreApp) return false;
|
||
|
||
bool uninstallStringMissing = string.IsNullOrWhiteSpace(app.UninstallString);
|
||
bool exeMissing = false;
|
||
|
||
if (!uninstallStringMissing)
|
||
{
|
||
string cmd = app.UninstallString.Trim();
|
||
if (cmd.StartsWith("\""))
|
||
{
|
||
int endQuote = cmd.IndexOf('\"', 1);
|
||
if (endQuote > 0)
|
||
{
|
||
string exe = cmd.Substring(1, endQuote - 1);
|
||
if (!File.Exists(exe) && !exe.Contains("msiexec", StringComparison.OrdinalIgnoreCase))
|
||
exeMissing = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
bool folderMissing = string.IsNullOrWhiteSpace(app.InstallLocation) || !Directory.Exists(app.InstallLocation);
|
||
return (uninstallStringMissing || exeMissing) && folderMissing && !string.IsNullOrWhiteSpace(app.RegistryPath);
|
||
}
|
||
|
||
private void SelectAppFromTreemap(ApplicationUninstallerEntry app)
|
||
{
|
||
navApps.IsChecked = true;
|
||
dgApps.SelectedItem = app;
|
||
dgApps.ScrollIntoView(app);
|
||
}
|
||
|
||
private void TxtSearch_TextChanged(object sender, TextChangedEventArgs e)
|
||
{
|
||
_searchDebounceTimer.Stop();
|
||
_searchDebounceTimer.Start();
|
||
}
|
||
|
||
private void FilterChip_Checked(object sender, RoutedEventArgs e) => ApplyFilter();
|
||
|
||
private void Nav_Checked(object sender, RoutedEventArgs e)
|
||
{
|
||
if (viewApps == null) return;
|
||
|
||
if (navBackups?.IsChecked == true)
|
||
{
|
||
navApps.IsChecked = true;
|
||
BtnOpenBackups_Click(sender, e);
|
||
return;
|
||
}
|
||
|
||
viewApps.Visibility = navApps.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
||
viewTreemap.Visibility = navTreemap.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
||
viewStartup.Visibility = navStartup.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
||
viewDebloat.Visibility = navDebloat.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
||
viewTools.Visibility = navTools?.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
||
}
|
||
|
||
private List<ApplicationUninstallerEntry> GetSelectedOrCurrentApps()
|
||
{
|
||
var checkedItems = _filteredEntries.Where(x => x.IsSelected).ToList();
|
||
if (checkedItems.Count > 0) return checkedItems;
|
||
|
||
var list = dgApps.SelectedItems.OfType<ApplicationUninstallerEntry>().ToList();
|
||
if (list.Count > 0) return list;
|
||
|
||
if (dgApps.SelectedItem is ApplicationUninstallerEntry single)
|
||
return new List<ApplicationUninstallerEntry> { single };
|
||
|
||
return new List<ApplicationUninstallerEntry>();
|
||
}
|
||
|
||
private async void BtnUninstall_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var targets = GetSelectedOrCurrentApps();
|
||
if (targets.Count == 0)
|
||
{
|
||
MessageBox.Show("Lütfen listeden kaldırmak istediğiniz yazılımı seçin.", "Yazılım Seçilmedi", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
return;
|
||
}
|
||
|
||
var dlg = new BulkWizardWindow(targets) { Owner = this };
|
||
bool? result = dlg.ShowDialog();
|
||
|
||
if (result == true && dlg.UninstalledApps.Count > 0)
|
||
{
|
||
txtFooterStatus.Text = "Kaldırma tamamlandı. Kalıntılar taranıyor...";
|
||
|
||
var jm = new JunkManager();
|
||
var junks = await Task.Run(() => jm.ScanMultiple(dlg.UninstalledApps));
|
||
|
||
var titleEntry = dlg.UninstalledApps.Count == 1
|
||
? dlg.UninstalledApps[0]
|
||
: new ApplicationUninstallerEntry { DisplayName = $"{dlg.UninstalledApps.Count} Kaldırılan Yazılım" };
|
||
|
||
var cleanWin = new LeftoverCleanWindow(titleEntry, junks)
|
||
{
|
||
Owner = this,
|
||
WindowStartupLocation = WindowStartupLocation.CenterOwner
|
||
};
|
||
|
||
cleanWin.ShowDialog();
|
||
|
||
// F12: Rapor oluştur
|
||
ReportService.GenerateHtmlReport(dlg.UninstalledApps, junks, JunkManager.BackupDirectory);
|
||
|
||
// P6: Hızlı bellek içi güncelleme
|
||
foreach (var uninstalled in dlg.UninstalledApps)
|
||
{
|
||
_allEntries.Remove(uninstalled);
|
||
}
|
||
|
||
ApplyFilter();
|
||
txtFooterStatus.Text = $"{dlg.UninstalledApps.Count} yazılım başarıyla kaldırıldı ve kalıntılar temizlendi.";
|
||
}
|
||
}
|
||
|
||
// F3: Zorla Kaldır (Force Uninstall)
|
||
private async void BtnForceUninstall_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var targets = GetSelectedOrCurrentApps();
|
||
if (targets.Count == 0)
|
||
{
|
||
MessageBox.Show("Lütfen zorla kaldırmak istediğiniz yazılımı seçin.", "Yazılım Seçilmedi", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
return;
|
||
}
|
||
|
||
var confirm = MessageBox.Show(
|
||
$"Seçilen {targets.Count} uygulama için orijinal kaldırıcı çalıştırılmayacak;\ndoğrudan tüm disk ve kayıt defteri kalıntıları taranıp temizlenecektir.\n\nDevam edilsin mi?",
|
||
"Zorla Kaldırma Onayı",
|
||
MessageBoxButton.YesNo,
|
||
MessageBoxImage.Warning);
|
||
|
||
if (confirm != MessageBoxResult.Yes) return;
|
||
|
||
txtFooterStatus.Text = "Kalıntılar taranıyor...";
|
||
var jm = new JunkManager();
|
||
var junks = await Task.Run(() => jm.ScanMultiple(targets));
|
||
|
||
var titleEntry = targets.Count == 1 ? targets[0] : new ApplicationUninstallerEntry { DisplayName = $"{targets.Count} Uygulama" };
|
||
var cleanWin = new LeftoverCleanWindow(titleEntry, junks) { Owner = this };
|
||
cleanWin.ShowDialog();
|
||
|
||
// Kayıt defteri anahtarını temizle
|
||
foreach (var app in targets)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(app.RegistryPath))
|
||
{
|
||
try
|
||
{
|
||
var (hive, subKey, view) = RegistryJunkResult.ParseRegistryPath(app.RegistryPath);
|
||
using var baseKey = RegistryKey.OpenBaseKey(hive, view);
|
||
baseKey.DeleteSubKeyTree(subKey, false);
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
_allEntries.Remove(app);
|
||
}
|
||
|
||
ReportService.GenerateHtmlReport(targets, junks, JunkManager.BackupDirectory);
|
||
ApplyFilter();
|
||
txtFooterStatus.Text = $"{targets.Count} uygulama zorla temizlendi.";
|
||
}
|
||
|
||
// F5: Winget Entegrasyonu
|
||
private void BtnWinget_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var sfd = new SaveFileDialog
|
||
{
|
||
Filter = "Batch Dosyası (*.bat)|*.bat|JSON Paketi (*.json)|*.json",
|
||
FileName = $"winget_install_bundle_{DateTime.Now:yyyyMMdd}"
|
||
};
|
||
|
||
if (sfd.ShowDialog() == true)
|
||
{
|
||
try
|
||
{
|
||
string content = WingetService.GenerateWingetExportScript(_allEntries);
|
||
File.WriteAllText(sfd.FileName, content);
|
||
MessageBox.Show(
|
||
$"Winget toplu kurulum scripti oluşturuldu:\n{sfd.FileName}\n\nYeni bir bilgisayarda bu scripti çalıştırarak yüklü yazılımlarınızı otomatik kurabilirsiniz.",
|
||
"Winget Scripti Hazır",
|
||
MessageBoxButton.OK,
|
||
MessageBoxImage.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show($"Script oluşturulamadı: {ex.Message}", "Hata", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
// B28: Escaped RFC 4180 CSV export
|
||
private void BtnExport_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var sfd = new SaveFileDialog
|
||
{
|
||
Filter = "CSV Dosyası (*.csv)|*.csv|JSON Dosyası (*.json)|*.json",
|
||
FileName = $"installed_apps_{DateTime.Now:yyyyMMdd}"
|
||
};
|
||
|
||
if (sfd.ShowDialog() == true)
|
||
{
|
||
try
|
||
{
|
||
string ext = Path.GetExtension(sfd.FileName).ToLowerInvariant();
|
||
if (ext == ".json")
|
||
{
|
||
File.WriteAllText(sfd.FileName, JsonSerializer.Serialize(_allEntries, new JsonSerializerOptions { WriteIndented = true }));
|
||
}
|
||
else
|
||
{
|
||
using var sw = new StreamWriter(sfd.FileName, false, System.Text.Encoding.UTF8);
|
||
sw.WriteLine("DisplayName,Publisher,DisplayVersion,EstimatedSizeBytes,InstallDate,UninstallerKind");
|
||
foreach (var a in _allEntries)
|
||
{
|
||
string name = EscapeCsv(a.DisplayName);
|
||
string pub = EscapeCsv(a.Publisher);
|
||
string ver = EscapeCsv(a.DisplayVersion);
|
||
string kind = EscapeCsv(a.UninstallerKind.ToString());
|
||
sw.WriteLine($"\"{name}\",\"{pub}\",\"{ver}\",{a.EstimatedSize.Bytes},\"{a.InstallDateDisplay}\",\"{kind}\"");
|
||
}
|
||
}
|
||
MessageBox.Show("Yazılım listesi başarıyla kaydedildi.", "Dışa Aktarma Başarılı", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show($"Hata: {ex.Message}", "Dışa Aktarılamadı", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private static string EscapeCsv(string? val) =>
|
||
(val ?? "").Replace("\"", "\"\"");
|
||
|
||
private async void BtnRefresh_Click(object sender, RoutedEventArgs e) => await RefreshDataAsync();
|
||
|
||
private void BtnToggleMiniTreemap_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
pnlMiniTreemap.Visibility = pnlMiniTreemap.Visibility == Visibility.Visible
|
||
? Visibility.Collapsed
|
||
: Visibility.Visible;
|
||
}
|
||
|
||
private void BtnHideMiniTreemap_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
pnlMiniTreemap.Visibility = Visibility.Collapsed;
|
||
}
|
||
|
||
private void MenuOpenFolder_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var targets = GetSelectedOrCurrentApps();
|
||
if (targets.Count > 0 && !string.IsNullOrWhiteSpace(targets[0].InstallLocation) && Directory.Exists(targets[0].InstallLocation))
|
||
{
|
||
Process.Start("explorer.exe", targets[0].InstallLocation);
|
||
}
|
||
}
|
||
|
||
// U11: Kayıt defterinde tam anahtarı aç
|
||
private void MenuOpenReg_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var targets = GetSelectedOrCurrentApps();
|
||
if (targets.Count > 0 && !string.IsNullOrWhiteSpace(targets[0].RegistryPath))
|
||
{
|
||
try
|
||
{
|
||
string targetKey = targets[0].RegistryPath.Replace("HKLM_32", "HKEY_LOCAL_MACHINE").Replace("HKLM", "HKEY_LOCAL_MACHINE").Replace("HKCU", "HKEY_CURRENT_USER");
|
||
using var regKey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Applets\Regedit");
|
||
regKey?.SetValue("LastKey", $"Computer\\{targetKey}");
|
||
}
|
||
catch { }
|
||
}
|
||
Process.Start("regedit.exe");
|
||
}
|
||
|
||
private void MenuSearchWeb_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var targets = GetSelectedOrCurrentApps();
|
||
if (targets.Count > 0)
|
||
{
|
||
string q = Uri.EscapeDataString(targets[0].DisplayName);
|
||
Process.Start(new ProcessStartInfo($"https://www.google.com/search?q={q}") { UseShellExecute = true });
|
||
}
|
||
}
|
||
|
||
// U14: Klavye kısayolları ve çift tıklama
|
||
private void Window_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.Key == Key.Delete && viewApps.Visibility == Visibility.Visible)
|
||
{
|
||
BtnUninstall_Click(sender, e);
|
||
e.Handled = true;
|
||
}
|
||
else if (e.Key == Key.F5)
|
||
{
|
||
_ = RefreshDataAsync();
|
||
e.Handled = true;
|
||
}
|
||
else if (e.Key == Key.F && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
|
||
{
|
||
txtSearch?.Focus();
|
||
txtSearch?.SelectAll();
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
|
||
private void DgApps_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||
{
|
||
if (dgApps.SelectedItem is ApplicationUninstallerEntry)
|
||
{
|
||
BtnUninstall_Click(sender, e);
|
||
}
|
||
}
|
||
|
||
// Startup Tab Handlers
|
||
private async Task LoadStartupEntriesAsync()
|
||
{
|
||
_allStartupEntries = await Task.Run(() => StartupManager.GetAllStartupEntries());
|
||
FilterStartupEntries();
|
||
}
|
||
|
||
private void TxtStartupSearch_TextChanged(object sender, TextChangedEventArgs e)
|
||
{
|
||
FilterStartupEntries();
|
||
}
|
||
|
||
private void FilterStartupEntries()
|
||
{
|
||
if (dgStartup == null) return;
|
||
string q = txtStartupSearch?.Text?.Trim().ToLowerInvariant() ?? "";
|
||
|
||
if (string.IsNullOrEmpty(q))
|
||
{
|
||
dgStartup.ItemsSource = _allStartupEntries;
|
||
}
|
||
else
|
||
{
|
||
dgStartup.ItemsSource = _allStartupEntries.Where(x =>
|
||
(x.Name != null && x.Name.Contains(q, StringComparison.OrdinalIgnoreCase)) ||
|
||
(x.Command != null && x.Command.Contains(q, StringComparison.OrdinalIgnoreCase))
|
||
).ToList();
|
||
}
|
||
}
|
||
|
||
private async void BtnToggleStartup_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (dgStartup.SelectedItem is StartupEntry entry)
|
||
{
|
||
bool newState = !entry.IsEnabled;
|
||
bool ok = await Task.Run(() => StartupManager.ToggleStartupEntry(entry, newState));
|
||
if (ok)
|
||
{
|
||
await LoadStartupEntriesAsync();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Başlangıç girdisi durumu değiştirilemedi. Yönetici yetkisi gerekebilir.", "Uyarı", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
}
|
||
}
|
||
}
|
||
|
||
// Debloat Tab Handlers
|
||
private async Task LoadDebloatTweaksAsync()
|
||
{
|
||
var tweaks = await Task.Run(() => WindowsTweaks.GetDefaultTweaks());
|
||
icDebloat.ItemsSource = tweaks;
|
||
}
|
||
|
||
private async void BtnToggleDebloatItem_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (sender is Button btn && btn.Tag is DebloatTweak tweak)
|
||
{
|
||
string action = tweak.IsApplied ? "varsayılana geri döndürülecek" : "uygulanacak";
|
||
var res = MessageBox.Show(
|
||
$"'{tweak.Title}' ayarı {action}.\n\nDevam edilsin mi?",
|
||
"İnce Ayar Onayı",
|
||
MessageBoxButton.YesNo,
|
||
MessageBoxImage.Question);
|
||
|
||
if (res != MessageBoxResult.Yes) return;
|
||
|
||
bool apply = !tweak.IsApplied;
|
||
bool ok = await Task.Run(() => apply ? tweak.Apply() : tweak.Revert());
|
||
if (ok)
|
||
{
|
||
await LoadDebloatTweaksAsync();
|
||
}
|
||
}
|
||
}
|
||
|
||
private async void BtnApplyAllDebloat_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var res = MessageBox.Show(
|
||
"Tüm telemetri, Cortana ve sponsorlu arka plan uygulama engellemeleri uygulanacaktır.\n\nDevam edilsin mi?",
|
||
"Toplu Ayar Onayı",
|
||
MessageBoxButton.YesNo,
|
||
MessageBoxImage.Question);
|
||
|
||
if (res != MessageBoxResult.Yes) return;
|
||
|
||
await Task.Run(() =>
|
||
{
|
||
var list = WindowsTweaks.GetDefaultTweaks();
|
||
foreach (var t in list) t.Apply();
|
||
});
|
||
|
||
await LoadDebloatTweaksAsync();
|
||
MessageBox.Show("Tüm önerilen Windows ince ayarları ve telemetri kapatmaları uygulandı!", "Başarılı", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
|
||
// Tools View Handlers
|
||
private void UpdateShellButtonText()
|
||
{
|
||
if (btnToggleShell != null)
|
||
btnToggleShell.Content = ShellIntegrationManager.IsRegistered() ? "Devre Dışı Bırak" : "Aktif Et";
|
||
}
|
||
|
||
private void BtnToggleShell_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (ShellIntegrationManager.IsRegistered())
|
||
{
|
||
ShellIntegrationManager.Unregister();
|
||
MessageBox.Show("Explorer sağ tık '💥 LD ile Güçlü Kaldır' menüsü kaldırıldı.", "Bilgi", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
else
|
||
{
|
||
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||
string launcherExe = Path.Combine(baseDir, "LDUninstaller.Launcher.exe");
|
||
string targetExe = File.Exists(launcherExe) ? launcherExe : (Process.GetCurrentProcess().MainModule?.FileName ?? "");
|
||
|
||
if (ShellIntegrationManager.Register(targetExe))
|
||
{
|
||
MessageBox.Show(
|
||
"Explorer sağ tık menüsü başarıyla eklendi!\n\nArtık masaüstünde veya Gezgin'de herhangi bir klasöre, uygulamaya (.exe) veya kısayola (.lnk) sağ tıklayarak '💥 LD ile Güçlü Kaldır' seçeneğini kullanabilirsiniz.",
|
||
"Başarılı",
|
||
MessageBoxButton.OK,
|
||
MessageBoxImage.Information);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Sağ tık menüsü kaydedilemedi. Yönetici yetkisi gerekebilir.", "Hata", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
}
|
||
}
|
||
UpdateShellButtonText();
|
||
}
|
||
|
||
private void BtnOpenBackups_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var win = new BackupRestoreWindow { Owner = this };
|
||
win.ShowDialog();
|
||
}
|
||
|
||
private void BtnCleanBrokenEntries_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
navApps.IsChecked = true;
|
||
chipBroken.IsChecked = true;
|
||
ApplyFilter();
|
||
}
|
||
|
||
private void BtnOpenLogs_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var win = new LogViewerWindow { Owner = this };
|
||
win.ShowDialog();
|
||
}
|
||
|
||
private async void BtnCheckUpdate_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
btnCheckUpdate.IsEnabled = false;
|
||
txtUpdateStatus.Text = "Sunucu sorgulanıyor...";
|
||
|
||
var currentVer = typeof(MainWindow).Assembly.GetName().Version ?? new Version(2, 8, 0);
|
||
var update = await UpdateChecker.CheckForUpdatesAsync(currentVer);
|
||
|
||
btnCheckUpdate.IsEnabled = true;
|
||
|
||
if (update != null && update.HasUpdate)
|
||
{
|
||
txtUpdateStatus.Text = $"Yeni sürüm mevcut: v{update.LatestVersion}";
|
||
var res = MessageBox.Show(
|
||
$"Yeni bir LD Uninstaller sürümü yayında!\n\nMevcut: v{currentVer}\nYeni: v{update.LatestVersion}\n\nİndirme sayfasına gitmek istiyor musunuz?",
|
||
"Güncelleme Mevcut",
|
||
MessageBoxButton.YesNo,
|
||
MessageBoxImage.Information);
|
||
|
||
if (res == MessageBoxResult.Yes)
|
||
{
|
||
Process.Start(new ProcessStartInfo(update.DownloadUrl) { UseShellExecute = true });
|
||
}
|
||
}
|
||
else
|
||
{
|
||
txtUpdateStatus.Text = $"En güncel sürümü kullanıyorsunuz (v{currentVer}).";
|
||
MessageBox.Show($"LD Uninstaller güncel! (v{currentVer})", "Güncel", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
}
|
||
|
||
// Window TitleBar Chrome Handlers
|
||
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
|
||
{
|
||
if (e.ChangedButton == MouseButton.Left)
|
||
DragMove();
|
||
}
|
||
|
||
private void BtnMinimize_Click(object sender, RoutedEventArgs e) => WindowState = WindowState.Minimized;
|
||
private void BtnMaximize_Click(object sender, RoutedEventArgs e) => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
|
||
private void BtnClose_Click(object sender, RoutedEventArgs e) => Close();
|
||
}
|
||
}
|