94 lines
5.1 KiB
C#
94 lines
5.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using LDUninstaller.Core.Models;
|
||
|
||
namespace LDUninstaller.Core.Services
|
||
{
|
||
public static class ReportService
|
||
{
|
||
public static string ReportsDirectory => Path.Combine(
|
||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||
"LDUninstaller",
|
||
"Reports");
|
||
|
||
public static string GenerateHtmlReport(
|
||
IEnumerable<ApplicationUninstallerEntry> uninstalledApps,
|
||
IEnumerable<IJunkResult> cleanedJunks,
|
||
string backupFolder)
|
||
{
|
||
try
|
||
{
|
||
if (!Directory.Exists(ReportsDirectory))
|
||
Directory.CreateDirectory(ReportsDirectory);
|
||
|
||
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||
string filename = Path.Combine(ReportsDirectory, $"CleanupReport_{timestamp}.html");
|
||
|
||
var sb = new StringBuilder();
|
||
sb.AppendLine("<!DOCTYPE html>");
|
||
sb.AppendLine("<html lang=\"tr\">");
|
||
sb.AppendLine("<head>");
|
||
sb.AppendLine("<meta charset=\"UTF-8\" />");
|
||
sb.AppendLine("<title>LD Uninstaller - Kaldırma ve Temizlik Raporu</title>");
|
||
sb.AppendLine("<style>");
|
||
sb.AppendLine("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background-color: #0F172A; color: #E2E8F0; padding: 30px; margin: 0; }");
|
||
sb.AppendLine(".container { max-width: 900px; margin: 0 auto; background: #1E293B; border-radius: 12px; padding: 25px; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }");
|
||
sb.AppendLine("h1 { color: #38BDF8; margin-top: 0; font-size: 22px; display: flex; align-items: center; gap: 10px; }");
|
||
sb.AppendLine(".meta { color: #94A3B8; font-size: 13px; margin-bottom: 20px; border-bottom: 1px solid #334155; padding-bottom: 12px; }");
|
||
sb.AppendLine(".badge { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: bold; background: #064E3B; color: #34D399; }");
|
||
sb.AppendLine("table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 13px; }");
|
||
sb.AppendLine("th { background-color: #0F172A; color: #94A3B8; text-align: left; padding: 10px; border-bottom: 2px solid #334155; }");
|
||
sb.AppendLine("td { padding: 9px 10px; border-bottom: 1px solid #334155; word-break: break-all; }");
|
||
sb.AppendLine("tr:hover { background-color: #273549; }");
|
||
sb.AppendLine(".footer { margin-top: 25px; font-size: 12px; color: #64748B; text-align: center; }");
|
||
sb.AppendLine("</style>");
|
||
sb.AppendLine("</head>");
|
||
sb.AppendLine("<body>");
|
||
sb.AppendLine("<div class=\"container\">");
|
||
sb.AppendLine("<h1>🛡️ LD Uninstaller - Kaldırma ve Temizlik Raporu</h1>");
|
||
sb.AppendLine($"<div class=\"meta\">İşlem Tarihi: {DateTime.Now:yyyy-MM-dd HH:mm:ss} | Kayıt Defteri Yedek Dizini: <code>{backupFolder}</code></div>");
|
||
|
||
sb.AppendLine("<h3>📦 Kaldırılan Yazılımlar</h3>");
|
||
sb.AppendLine("<table>");
|
||
sb.AppendLine("<tr><th>Yazılım Adı</th><th>Yayıncı</th><th>Sürüm</th><th>Kaldırıcı Türü</th></tr>");
|
||
foreach (var app in uninstalledApps)
|
||
{
|
||
sb.AppendLine($"<tr><td><strong>{app.DisplayName}</strong></td><td>{app.Publisher}</td><td>{app.DisplayVersion}</td><td>{app.UninstallerKind}</td></tr>");
|
||
}
|
||
sb.AppendLine("</table>");
|
||
|
||
var junkList = cleanedJunks.ToList();
|
||
sb.AppendLine($"<h3 style=\"margin-top: 30px;\">🧹 Temizlenen Kalıntılar ve Artıklar ({junkList.Count} Öğe)</h3>");
|
||
if (junkList.Count > 0)
|
||
{
|
||
sb.AppendLine("<table>");
|
||
sb.AppendLine("<tr><th>Tür</th><th>Güven</th><th>Açıklama</th><th>Yol</th></tr>");
|
||
foreach (var junk in junkList)
|
||
{
|
||
sb.AppendLine($"<tr><td>{junk.TypeDisplay}</td><td><span class=\"badge\">{junk.ConfidenceDisplay}</span></td><td>{junk.Reason}</td><td><code>{junk.Path}</code></td></tr>");
|
||
}
|
||
sb.AppendLine("</table>");
|
||
}
|
||
else
|
||
{
|
||
sb.AppendLine("<p style=\"color: #10B981;\">Kalıntı veya artık bulunamadı, sistem temiz.</p>");
|
||
}
|
||
|
||
sb.AppendLine("<div class=\"footer\">LD Uninstaller 2.8.0 • Güvenli ve Derinlemesine Sistem Temizliği</div>");
|
||
sb.AppendLine("</div>");
|
||
sb.AppendLine("</body>");
|
||
sb.AppendLine("</html>");
|
||
|
||
File.WriteAllText(filename, sb.ToString(), Encoding.UTF8);
|
||
return filename;
|
||
}
|
||
catch
|
||
{
|
||
return string.Empty;
|
||
}
|
||
}
|
||
}
|
||
}
|