LD-Uninstaller/src/pages/ShredderView.tsx

204 lines
8.3 KiB
TypeScript
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.

import React, { useState } from 'react';
import { useAppStore } from '../store/useAppStore';
import { ShieldAlert, Unlock, Trash2, RefreshCw, AlertTriangle, CheckCircle2, FolderOpen, FileSearch } from 'lucide-react';
import { api } from '../lib/tauri';
export const ShredderView: React.FC = () => {
const { addToast } = useAppStore();
const [targetPath, setTargetPath] = useState('');
const [isProcessing, setIsProcessing] = useState(false);
const [detectedPids, setDetectedPids] = useState<number[] | null>(null);
const handleDetectLocks = async () => {
if (!targetPath.trim()) {
addToast('Uyarı', 'Lütfen geçerli bir dosya veya klasör yolu girin.', 'warning');
return;
}
setIsProcessing(true);
try {
const pids = await api.getLockingProcesses(targetPath.trim());
setDetectedPids(pids);
if (pids.length > 0) {
addToast('Kilitler Bulundu', `${pids.length} adet işlem dosyayı kilitli tutuyor.`, 'warning');
} else {
addToast('Kilit Yok', 'Dosyayı kilitleyen aktif bir süreç bulunamadı.', 'info');
}
} catch (e: any) {
addToast('Hata', String(e), 'error');
} finally {
setIsProcessing(false);
}
};
const handleBrowseFolder = async () => {
try {
const selected = await api.browseTargetPath(true);
if (selected) {
setTargetPath(selected);
setDetectedPids(null);
}
} catch (e: any) {
addToast('Gözat Hatası', String(e), 'error');
}
};
const handleBrowseFile = async () => {
try {
const selected = await api.browseTargetPath(false);
if (selected) {
setTargetPath(selected);
setDetectedPids(null);
}
} catch (e: any) {
addToast('Gözat Hatası', String(e), 'error');
}
};
const handleForceShred = async () => {
if (!targetPath.trim()) {
addToast('Uyarı', 'Lütfen geçerli bir dosya veya klasör yolu girin.', 'warning');
return;
}
const confirm = window.confirm(
`DİKKAT: "${targetPath}" yolu zorla silinecek ve kilitleyen süreçler kapatılacaktır. Onaylıyor musunuz?`
);
if (!confirm) return;
setIsProcessing(true);
try {
const success = await api.forceUnlockAndShred(targetPath.trim());
if (success) {
addToast('Başarıyla Silindi', 'Dosya/klasör zorla parçalandı ve temizlendi.', 'success');
setTargetPath('');
setDetectedPids(null);
} else {
addToast(
'Yeniden Başlatmada Silinecek',
'Dosya çekirdek tarafından tutulduğu için bir sonraki Windows açılışında silinmek üzere sıraya alındı.',
'info'
);
}
} catch (e: any) {
addToast('Zorla Silme Hatası', String(e), 'error');
} finally {
setIsProcessing(false);
}
};
return (
<div className="flex-1 flex flex-col h-full overflow-hidden bg-ld-bg pt-10">
<div className="p-4 border-b border-ld-border bg-ld-surface/80 flex items-center justify-between">
<div>
<h2 className="text-xs font-semibold text-slate-100 flex items-center gap-2">
<ShieldAlert className="w-4 h-4 text-rose-500" />
Dosya Kilit Açıcı & Zorla Parçalayıcı (File Shredder)
</h2>
<p className="text-[11px] text-slate-500">
Windows Restart Manager API ile silinemeyen kilitli dosyaları zorla sonlandırın ve silin.
</p>
</div>
</div>
<div className="p-6 max-w-2xl mx-auto w-full space-y-5 flex-1 overflow-y-auto">
{/* Güvenlik Uyarısı */}
<div className="p-4 rounded-xl bg-amber-500/10 border border-amber-500/20 text-xs text-amber-200 flex items-start gap-3">
<AlertTriangle className="w-5 h-5 text-amber-400 shrink-0 mt-0.5" />
<div className="leading-relaxed">
<p className="font-semibold">Windows Restart Manager Entegrasyonu</p>
<p className="text-[11px] text-amber-300/90 mt-0.5">
"Bu dosya başka bir programda açık" uyarısı veren tüm kilitli dosyalar, onları tutan süreçler otomatik tespit edilip sonlandırılarak silinir. Kritik sistem klasörleri (C:\Windows, System32 vb.) güvenlik kalkanı tarafından otomatik olarak korunur.
</p>
</div>
</div>
{/* Hedef Yol Girişi */}
<div className="p-5 rounded-xl bg-ld-surface border border-ld-border space-y-4">
<label className="text-xs font-semibold text-slate-200 block">
Silinecek Dosya veya Klasör Yolu:
</label>
<div className="flex items-center gap-2">
<input
type="text"
placeholder="Örn: C:\Program Files\BozukUygulama veya C:\Games\OyunKlasoru"
value={targetPath}
onChange={(e) => setTargetPath(e.target.value)}
className="flex-1 bg-ld-card border border-ld-border rounded-lg px-3 py-2 text-xs text-slate-200 font-mono focus:outline-none focus:border-sky-500/50"
/>
<button
onClick={handleBrowseFolder}
type="button"
className="flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-300 hover:text-white hover:bg-white/5 transition-colors cursor-pointer shrink-0"
title="Klasör Seç"
>
<FolderOpen className="w-3.5 h-3.5 text-amber-400" />
<span>Klasör Seç</span>
</button>
<button
onClick={handleBrowseFile}
type="button"
className="flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-300 hover:text-white hover:bg-white/5 transition-colors cursor-pointer shrink-0"
title="Dosya Seç"
>
<FileSearch className="w-3.5 h-3.5 text-sky-400" />
<span>Dosya Seç</span>
</button>
</div>
{/* Kilitli Süreçler Bildirimi */}
{detectedPids !== null && (
<div className="p-3 rounded-lg bg-ld-card border border-ld-border text-xs">
<span className="font-semibold text-slate-300 block mb-1">Tespit Edilen Kilitli İşlemler:</span>
{detectedPids.length > 0 ? (
<div className="flex flex-wrap gap-1.5 mt-1">
{detectedPids.map((pid) => (
<span
key={pid}
className="px-2 py-0.5 rounded bg-rose-500/20 text-rose-300 border border-rose-500/30 font-mono text-[11px]"
>
PID: {pid}
</span>
))}
</div>
) : (
<div className="flex items-center gap-1.5 text-emerald-400 text-[11px]">
<CheckCircle2 className="w-3.5 h-3.5" />
<span>Dosyayı kilitleyen açık bir süreç bulunmuyor.</span>
</div>
)}
</div>
)}
{/* Aksiyon Butonları */}
<div className="flex items-center justify-end gap-3 pt-2">
<button
disabled={isProcessing}
onClick={handleDetectLocks}
className="flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-300 hover:text-white hover:bg-white/5 transition-colors disabled:opacity-50 cursor-pointer"
>
<Unlock className="w-3.5 h-3.5 text-sky-400" />
Kilitli Süreçleri Tara
</button>
<button
disabled={isProcessing}
onClick={handleForceShred}
className="flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold bg-rose-600 text-white hover:bg-rose-500 shadow-md shadow-rose-600/20 transition-all disabled:opacity-50 cursor-pointer"
>
{isProcessing ? (
<>
<RefreshCw className="w-3.5 h-3.5 animate-spin" />
İşleniyor...
</>
) : (
<>
<Trash2 className="w-3.5 h-3.5" />
Kilidi Aç ve Zorla Parçala
</>
)}
</button>
</div>
</div>
</div>
</div>
);
};