179 lines
6.9 KiB
C#
179 lines
6.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using LDUninstaller.Core.Junk;
|
||
using LDUninstaller.Core.Models;
|
||
using LDUninstaller.Core.Native;
|
||
using LDUninstaller.Core.Services;
|
||
|
||
namespace LDUninstaller.UI.Dialogs
|
||
{
|
||
public partial class ForceDeleteWindow : Window
|
||
{
|
||
private readonly string _rawInputPath;
|
||
private string _targetFolder = string.Empty;
|
||
private string? _primaryFile;
|
||
private string? _originalLnk;
|
||
private bool _isDangerous;
|
||
|
||
public ForceDeleteWindow(string rawPath)
|
||
{
|
||
InitializeComponent();
|
||
_rawInputPath = rawPath ?? string.Empty;
|
||
Loaded += ForceDeleteWindow_Loaded;
|
||
}
|
||
|
||
private async void ForceDeleteWindow_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
var (folder, file, lnk) = FileUnlockerService.ResolveTarget(_rawInputPath);
|
||
_targetFolder = folder;
|
||
_primaryFile = file;
|
||
_originalLnk = lnk;
|
||
|
||
txtTargetPath.Text = _targetFolder;
|
||
|
||
if (!string.IsNullOrEmpty(_originalLnk))
|
||
{
|
||
txtLnkNote.Text = $"🔗 Masaüstü/Başlat kısayolu çözümlendi: '{Path.GetFileName(_originalLnk)}' ve ana kurulum klasörü birlikte yok edilecek.";
|
||
txtLnkNote.Visibility = Visibility.Visible;
|
||
}
|
||
|
||
// Güvenlik Kara Liste Kontrolü
|
||
if (SafetyBlacklist.IsDangerousDirectory(_targetFolder))
|
||
{
|
||
_isDangerous = true;
|
||
btnDestroy.IsEnabled = false;
|
||
txtLockStatus.Text = "⛔ Kritik Sistem Klasörü";
|
||
txtLockStatus.Foreground = new SolidColorBrush(Color.FromRgb(248, 113, 113));
|
||
bdLockStatus.Background = new SolidColorBrush(Color.FromRgb(69, 10, 10));
|
||
|
||
MessageBox.Show(
|
||
$"GÜVENLİK ENGELİ:\n\n'{_targetFolder}'\n\nBu klasör Windows sistem dosyalarını, kullanıcı profil kökünü veya kritik bir sürücü kökünü içerdiğinden LD Uninstaller tarafından SİLİNEMEZ!",
|
||
"Kritik Sistem Koruması Devrede",
|
||
MessageBoxButton.OK,
|
||
MessageBoxImage.Hand);
|
||
|
||
return;
|
||
}
|
||
|
||
await RefreshLocksAsync();
|
||
}
|
||
|
||
private async Task RefreshLocksAsync()
|
||
{
|
||
txtLockStatus.Text = "Kilitler taranıyor...";
|
||
|
||
var locks = await Task.Run(() => FileUnlockerService.InspectLocks(_targetFolder));
|
||
|
||
if (locks.Count > 0)
|
||
{
|
||
dgLocks.ItemsSource = locks;
|
||
dgLocks.Visibility = Visibility.Visible;
|
||
pnlNoLocks.Visibility = Visibility.Collapsed;
|
||
|
||
txtLockStatus.Text = $"⚠️ {locks.Count} Kilitli Süreç / Servis";
|
||
txtLockStatus.Foreground = new SolidColorBrush(Color.FromRgb(248, 113, 113));
|
||
bdLockStatus.Background = new SolidColorBrush(Color.FromRgb(69, 10, 10));
|
||
}
|
||
else
|
||
{
|
||
dgLocks.Visibility = Visibility.Collapsed;
|
||
pnlNoLocks.Visibility = Visibility.Visible;
|
||
|
||
txtLockStatus.Text = "✓ Aktif Kilit Yok";
|
||
txtLockStatus.Foreground = new SolidColorBrush(Color.FromRgb(52, 211, 153));
|
||
bdLockStatus.Background = new SolidColorBrush(Color.FromRgb(6, 78, 59));
|
||
}
|
||
}
|
||
|
||
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
|
||
{
|
||
if (e.ChangedButton == MouseButton.Left)
|
||
DragMove();
|
||
}
|
||
|
||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
Close();
|
||
}
|
||
|
||
private async void BtnDestroy_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (_isDangerous) return;
|
||
|
||
var res = MessageBox.Show(
|
||
$"Hedef:\n{_targetFolder}\n\nBu klasörle ilişkili tüm çalışan süreçler ve servisler anında sonlandırılacak, klasör ve kalıntıları tamamen yok edilecektir.\n\nİşlemi onaylıyor musunuz?",
|
||
"💥 Güçlü Kaldırma Onayı",
|
||
MessageBoxButton.YesNo,
|
||
MessageBoxImage.Warning);
|
||
|
||
if (res != MessageBoxResult.Yes) return;
|
||
|
||
btnDestroy.IsEnabled = false;
|
||
btnCancel.IsEnabled = false;
|
||
chkRecycle.IsEnabled = false;
|
||
chkCleanJunk.IsEnabled = false;
|
||
pbProgress.Visibility = Visibility.Visible;
|
||
txtLog.Visibility = Visibility.Visible;
|
||
|
||
bool sendToRecycle = chkRecycle.IsChecked == true;
|
||
bool cleanJunk = chkCleanJunk.IsChecked == true;
|
||
|
||
var destroyResult = await Task.Run(() =>
|
||
{
|
||
return FileUnlockerService.UnlockAndDestroy(
|
||
_targetFolder,
|
||
sendToRecycle,
|
||
msg => Dispatcher.Invoke(() => txtLog.Text = msg));
|
||
});
|
||
|
||
// Kısayol dosyasını da temizle
|
||
if (!string.IsNullOrEmpty(_originalLnk) && File.Exists(_originalLnk))
|
||
{
|
||
try { Win32.SendToRecycleBin(_originalLnk); } catch { }
|
||
}
|
||
|
||
// Kalıntı temizleme (Junk Scan & Clean)
|
||
int leftoverCount = 0;
|
||
if (cleanJunk)
|
||
{
|
||
Dispatcher.Invoke(() => txtLog.Text = "Kayıt Defteri ve sistem kalıntıları temizleniyor...");
|
||
|
||
await Task.Run(() =>
|
||
{
|
||
string appName = Path.GetFileName(_targetFolder);
|
||
var entry = new ApplicationUninstallerEntry
|
||
{
|
||
DisplayName = appName,
|
||
InstallLocation = _targetFolder
|
||
};
|
||
|
||
var jm = new JunkManager();
|
||
var junks = jm.ScanJunk(entry);
|
||
var cleanable = junks.Where(j => j.Confidence >= ConfidenceLevel.Good).ToList();
|
||
leftoverCount = JunkManager.CleanJunk(cleanable, JunkManager.BackupDirectory);
|
||
});
|
||
}
|
||
|
||
pbProgress.Visibility = Visibility.Collapsed;
|
||
|
||
string summaryMsg = $"İşlem Başarıyla Tamamlandı!\n\n" +
|
||
$"• Sonlandırılan Süreç: {destroyResult.KilledProcessesCount}\n" +
|
||
$"• Durdurulan/Silinen Servis: {destroyResult.StoppedServicesCount}\n" +
|
||
$"• Temizlenen Kalıntı Kayıt/Dosya: {leftoverCount}\n";
|
||
|
||
if (destroyResult.ScheduledForReboot)
|
||
{
|
||
summaryMsg += "\nNOT: Bazı kilitli çekirdek dosyalar ilk sistem yeniden başlatmasında (MoveFileEx) silinmek üzere zamanlandı.";
|
||
}
|
||
|
||
MessageBox.Show(summaryMsg, "💥 Güçlü Kaldırma Tamamlandı", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
Close();
|
||
}
|
||
}
|
||
}
|