{"repo_name": "CrapFixer", "file_name": "/CrapFixer/CFixer/MainForm.cs", "inference_info": {"prefix_code": "using CFixer;\nusing CFixer.Properties;\nusing CFixer.Views;\nusing System;\nusing System.Diagnostics;\nusing System.Drawing;\nusing System.Drawing.Drawing2D;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Windows.Forms;\n\nnamespace CrapFixer\n{\n public partial class MainForm : Form\n {\n private NavigationManager _navigationManager;\n private NavigationHandler _navigationHandler;\n private LogActions _logActions;\n private LogActionsController _logActionsController;\n private readonly AppManagerService _appManager = new AppManagerService();\n\n public MainForm()\n {\n InitializeComponent();\n IniStateManager.ApplyWindowState(this);\n\n // Set up the main navigation manager and logger\n _navigationManager = new NavigationManager(panelContainer);\n Logger.OutputBox = rtbLogger;\n\n // Set up log actions controller\n _logActions = new LogActions(rtbLogger);\n }\n\n private async void MainForm_Shown(object sender, EventArgs e)\n {\n await InitializeUI(); // _ = InitializeUI();\n InitializeAppState();\n }\n\n private void InitializeAppState()\n {\n // Load features and plugins into the tree view\n FeatureNodeManager.LoadFeatures(treeFeatures);\n PluginManager.LoadPlugins(treeFeatures);\n\n // Load settings from INI file if enabled\n IniStateManager.LoadFeaturesIfEnabled(treeFeatures);\n }\n\n private async Task InitializeUI()\n {\n // Initialize the navigation handler with buttons\n _navigationHandler = new NavigationHandler(btnFixer, btnRestore, btnTools, btnGitHub);\n\n // Load navigation icons\n await _navigationHandler.LoadNavigationIcons();\n\n // Register navigation handler\n _navigationHandler.NavigationButtonClicked += NavigationHandler_NavigationButtonClicked;\n\n // Register click handlers for GitHub links\n pictureHeader.Click += PictureHeader_Click;\n lblHeader.Click += PictureHeader_Click;\n\n // Re-initialize log actions controller (optional if not changed)\n _logActionsController = new LogActionsController(comboLogActions, _logActions);\n\n // Set version and OS info\n lblVersionInfo.Text = $\"v{Program.GetAppVersion()} \";\n lblOSInfo.Text = await OSHelper.OSHelper.GetWindowsVersion();\n }\n\n // Handles navigation button clicks and switches views accordingly\n ", "suffix_code": "\n\n private async void btnAnalyze_Click(object sender, EventArgs e)\n {\n // Analyze features\n await FeatureNodeManager.AnalyzeAll(treeFeatures.Nodes);\n\n // Analyze plugins\n await PluginManager.AnalyzeAllPlugins(treeFeatures.Nodes);\n\n // Analyze apps\n await AnalyzeApps();\n\n // Show log actions combo box\n comboLogActions.Visible = true;\n }\n\n /// \n /// Analyzes the apps and logs the results.\n /// \n private async Task AnalyzeApps()\n {\n checkedListBoxApps.Items.Clear();\n\n // Try loading patterns from CFEnhancer.txt (located in Plugins folder)\n var (bloatwarePatterns, whitelistPatterns, scanAll) = _appManager.LoadExternalBloatwarePatterns();\n\n if (bloatwarePatterns.Length == 0 && !scanAll)\n {\n // Fallback to internal resource if external file not found or empty and scanAll is not enabled\n bloatwarePatterns = Resources.PredefinedApps?\n .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(s => s.Trim().ToLower()).ToArray() ?? Array.Empty();\n\n whitelistPatterns = Array.Empty();\n Logger.Log(\"Using built-in bloatware list.\", LogLevel.Info);\n }\n else\n {\n Logger.Log(\"🔎 Plugin ready: CFEnhancer (external bloatware list)\", LogLevel.Info);\n }\n\n // Analyze installed apps based on patterns and whitelist, and optionally scan all\n var apps = await _appManager.AnalyzeAndLogAppsAsync(bloatwarePatterns, whitelistPatterns, scanAll);\n\n foreach (var app in apps)\n {\n checkedListBoxApps.Items.Add(app.FullName);\n }\n }\n\n private async void btnFix_Click(object sender, EventArgs e)\n {\n rtbLogger.Clear();\n\n // Fix all features\n foreach (TreeNode node in treeFeatures.Nodes)\n await FeatureNodeManager.FixChecked(node);\n\n // Fix all plugins\n foreach (TreeNode node in treeFeatures.Nodes)\n await PluginManager.FixChecked(node);\n\n // Fix selected Store apps\n var selectedApps = checkedListBoxApps.CheckedItems.Cast().ToList();\n if (selectedApps.Count == 0)\n return;\n\n var appService = new AppManagerService();\n var removedApps = await appService.UninstallSelectedAppsAsync(selectedApps);\n\n // Update UI after uninstall\n foreach (var app in removedApps)\n {\n checkedListBoxApps.Items.Remove(app);\n }\n }\n\n private void btnRestore_Click(object sender, EventArgs e)\n {\n var result = MessageBox.Show(\n \"⚠️ This will restore all selected features to their original state.\\n\" +\n \"Changes made by previous configurations may be reverted.\\n\\n\" +\n \"Are you sure you want to proceed?\",\n \"Restore Selected Features\",\n MessageBoxButtons.YesNo,\n MessageBoxIcon.Warning);\n\n if (result == DialogResult.Yes)\n {\n rtbLogger.Clear();\n foreach (TreeNode node in treeFeatures.Nodes)\n FeatureNodeManager.RestoreChecked(node);\n\n Logger.Log(\"↩️ All selected features have been restored.\", LogLevel.Info);\n }\n }\n\n /// \n /// Analyzes all plugins and features starting from the selected node from the context menu.\n /// \n private async void analyzeMarkedFeatureToolStripMenuItem_Click(object sender, EventArgs e)\n {\n if (treeFeatures.SelectedNode is TreeNode selectedNode)\n {\n Logger.Log($\"🔎 Analyzing Feature: {selectedNode.Text}\", LogLevel.Info);\n\n // If a single node is selected (leaf node with no children),\n // always analyze this node regardless of its Checked state.\n if (selectedNode.Nodes.Count == 0)\n {\n await PluginManager.AnalyzePlugin(selectedNode);\n }\n else\n {\n // If a parent node is selected (has children),\n // recursively analyze only the checked plugin nodes.\n await PluginManager.AnalyzeAll(selectedNode);\n }\n\n // Perform feature-specific analysis (non-plugin)\n FeatureNodeManager.AnalyzeFeature(selectedNode);\n }\n }\n\n /// \n /// Fixes all checked plugin and feature nodes starting from the selected node from the context menu.\n /// \n private async void fixMarkedFeatureToolStripMenuItem_Click(object sender, EventArgs e)\n {\n if (treeFeatures.SelectedNode is TreeNode selectedNode)\n {\n Logger.Log($\"🔧 Fixing Feature: {selectedNode.Text}\", LogLevel.Info);\n\n // Recursively fix all checked feature nodes (non-plugin)\n await FeatureNodeManager.FixFeature(selectedNode);\n\n // Recursively fix all checked plugin nodes starting from the selected node\n await PluginManager.FixPlugin(selectedNode);\n }\n }\n\n /// \n /// Restores the selected plugin or feature to its previous state from the context menu.\n /// \n private async void restoreMarkedFeatureToolStripMenuItem_Click(object sender, EventArgs e)\n {\n if (treeFeatures.SelectedNode is TreeNode selectedNode)\n {\n if (PluginManager.IsPluginNode(selectedNode))\n // Restore the plugin using its Undo command if available!\n await PluginManager.RestorePlugin(selectedNode);\n else\n Logger.Log($\"↩️ Restoring Feature: {selectedNode.Text}\", LogLevel.Info);\n\n // Perform feature-specific restore (non-plugin)\n FeatureNodeManager.RestoreFeature(selectedNode);\n }\n }\n\n private void helpMarkedFeatureToolStripMenuItem_Click(object sender, EventArgs e)\n {\n if (treeFeatures.SelectedNode is TreeNode selectedNode)\n {\n FeatureNodeManager.ShowHelp(selectedNode);\n }\n }\n\n /// \n /// Checks or unchecks all child nodes when a parent node is checked/unchecked.\n /// \n /// \n /// \n private void treeFeatures_AfterCheck(object sender, TreeViewEventArgs e)\n {\n if (e.Action != TreeViewAction.Unknown)\n {\n foreach (TreeNode child in e.Node.Nodes)\n child.Checked = e.Node.Checked;\n }\n }\n\n private void treeFeatures_MouseDown(object sender, MouseEventArgs e)\n {\n if (e.Button == MouseButtons.Right)\n {\n // Get the node under the mouse cursor\n TreeNode nodeUnderMouse = treeFeatures.GetNodeAt(e.X, e.Y);\n\n if (nodeUnderMouse != null)\n {\n treeFeatures.SelectedNode = nodeUnderMouse;\n\n // Show the context menu at the mouse position\n contextMenuStrip.Show(treeFeatures, e.Location);\n }\n }\n }\n\n /// \n /// Handles the link click event for selecting or deselecting all items in the list.\n /// \n /// \n /// \n private bool treeChecked = false;\n\n private void linkSelection_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\n {\n if (tabControl.SelectedTab == Windows)\n {\n foreach (TreeNode node in treeFeatures.Nodes)\n {\n node.Checked = treeChecked;\n foreach (TreeNode child in node.Nodes)\n {\n child.Checked = treeChecked;\n foreach (TreeNode grandChild in child.Nodes)\n grandChild.Checked = treeChecked;\n }\n }\n\n treeChecked = !treeChecked;\n }\n else if (tabControl.SelectedTab == Apps)\n {\n bool shouldCheck = checkedListBoxApps.Items.Cast