mirror of
https://github.com/theitaliandeveloper/Perfect11.git
synced 2025-12-06 09:02:03 +00:00
Making big changes
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
using Microsoft.VisualBasic.ApplicationServices;
|
||||
using Perfect11.Library;
|
||||
using Perfect11.Library;
|
||||
using Perfect11.Properties;
|
||||
using Perfect11.TweaksInterface;
|
||||
using ReaLTaiizor.Enum.Poison;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -18,12 +15,15 @@ namespace Perfect11
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private List<string> _listSystemApps = new List<string>();
|
||||
private List<IPlugin> _tweaks = new List<IPlugin>();
|
||||
private static string AppEdition = "Perfect11 Community Edition";
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
DarkMode(true);
|
||||
InitializeDarkMode();
|
||||
GetUWPSystem();
|
||||
GetUWP();
|
||||
InitializeTweaks();
|
||||
}
|
||||
public void DarkMode(bool status)
|
||||
{
|
||||
@@ -44,28 +44,47 @@ namespace Perfect11
|
||||
addButton.Theme = ThemeStyle.Dark;
|
||||
removeAllButton.Theme = ThemeStyle.Dark;
|
||||
removeButton.Theme = ThemeStyle.Dark;
|
||||
welcomePage.BackgroundImage = Resources.win11wallpaperdark;
|
||||
tweaksPage.Theme = ThemeStyle.Dark;
|
||||
tweaksList.Theme = ThemeStyle.Dark;
|
||||
runTweaks.Theme = ThemeStyle.Dark;
|
||||
editionLabel.Theme = ThemeStyle.Dark;
|
||||
}
|
||||
else
|
||||
{
|
||||
pages.Theme = ThemeStyle.Light;
|
||||
welcomePage.Theme = ThemeStyle.Light;
|
||||
debloatPage.Theme = ThemeStyle.Light;
|
||||
poisonLabel1.Theme = ThemeStyle.Light;
|
||||
poisonLabel2.Theme = ThemeStyle.Light;
|
||||
LblInstalledCount.Theme = ThemeStyle.Light;
|
||||
LblRemoveCount.Theme = ThemeStyle.Light;
|
||||
LstUWP.Theme = ThemeStyle.Light;
|
||||
LstUWPRemove.Theme = ThemeStyle.Light;
|
||||
ChkShowUWPSystem.Theme = ThemeStyle.Light;
|
||||
BtnRunUninstaller.Theme = ThemeStyle.Light;
|
||||
addAllButton.Theme = ThemeStyle.Light;
|
||||
addButton.Theme = ThemeStyle.Light;
|
||||
removeAllButton.Theme = ThemeStyle.Light;
|
||||
removeButton.Theme = ThemeStyle.Light;
|
||||
welcomePage.BackgroundImage = Resources.win11wallpaperlight;
|
||||
tweaksPage.Theme = ThemeStyle.Light;
|
||||
tweaksList.Theme = ThemeStyle.Light;
|
||||
runTweaks.Theme = ThemeStyle.Light;
|
||||
editionLabel.Theme = ThemeStyle.Light;
|
||||
}
|
||||
}
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
pages.SelectedTab = welcomePage; // Always start from the first tab
|
||||
editionLabel.Text = AppEdition;
|
||||
theme.Text = AppEdition;
|
||||
}
|
||||
private void GetUWP()
|
||||
{
|
||||
LstUWP.Items.Clear();
|
||||
|
||||
// Run PowerShell to get UWP app names
|
||||
string output = PowerShell.Execute("Get-AppxPackage -allusers | Select-Object -ExpandProperty Name");
|
||||
|
||||
// Split output into lines
|
||||
string[] lines = output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string current = line.Trim();
|
||||
@@ -122,7 +141,7 @@ namespace Perfect11
|
||||
}
|
||||
private void GetUWPSystem()
|
||||
{
|
||||
_listSystemApps.Clear(); // Optional: clear old entries
|
||||
_listSystemApps.Clear();
|
||||
|
||||
using (StringReader reader = new StringReader(Resources.UWPSystemAppList))
|
||||
{
|
||||
@@ -139,19 +158,20 @@ namespace Perfect11
|
||||
string success = "Successfully removed:" + "\n";
|
||||
string failed = "Failed to remove:" + "\n";
|
||||
|
||||
foreach (var item in LstUWPRemove.Items)
|
||||
foreach (ListViewItem item in LstUWPRemove.Items)
|
||||
{
|
||||
string appName = item.ToString();
|
||||
|
||||
// Build the command
|
||||
string appName = item.Text;
|
||||
string command = $"Get-AppxPackage -allusers -Name \"{appName}\" | Remove-AppxPackage -allusers";
|
||||
|
||||
string command2 = $"Get-AppxProvisionedPackage -online | Where PackageName -like *\"{appName}\"* | Remove-AppxProvisionedPackage -online";
|
||||
try
|
||||
{
|
||||
string output2 = PowerShell.Execute(command2);
|
||||
string output = PowerShell.Execute(command);
|
||||
|
||||
// Basic success/failure logic (you can enhance this)
|
||||
if (!string.IsNullOrWhiteSpace(output) && !output.ToLower().Contains("error"))
|
||||
#if DEBUG
|
||||
MessageBox.Show(output2);
|
||||
MessageBox.Show(output);
|
||||
#endif
|
||||
if (!output.ToLower().Contains("error") && !output2.ToLower().Contains("error"))
|
||||
{
|
||||
success += "\t" + appName + "\n";
|
||||
}
|
||||
@@ -165,8 +185,6 @@ namespace Perfect11
|
||||
failed += $"\t{appName} ({ex.Message})\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Return status summary
|
||||
return success + (failed != "Failed to remove:" + "\n" ? "\n" + failed : "");
|
||||
}
|
||||
|
||||
@@ -181,7 +199,7 @@ namespace Perfect11
|
||||
var itemsToMove = LstUWP.Items.Cast<ListViewItem>().ToList();
|
||||
foreach (var item in itemsToMove)
|
||||
{
|
||||
LstUWPRemove.Items.Add((ListViewItem)item.Clone()); // Clone to avoid reference issues
|
||||
LstUWPRemove.Items.Add((ListViewItem)item.Clone());
|
||||
}
|
||||
LstUWP.Items.Clear();
|
||||
RefreshUWP();
|
||||
@@ -202,7 +220,6 @@ namespace Perfect11
|
||||
{
|
||||
if (LstUWPRemove.SelectedItems.Count > 0)
|
||||
{
|
||||
// Create a temporary list to avoid modifying collection during iteration
|
||||
List<ListViewItem> selectedItems = new List<ListViewItem>();
|
||||
|
||||
foreach (ListViewItem selectedItem in LstUWPRemove.SelectedItems)
|
||||
@@ -223,21 +240,13 @@ namespace Perfect11
|
||||
|
||||
private void removeAllButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Create a temporary list to hold items to move
|
||||
List<ListViewItem> itemsToMove = new List<ListViewItem>();
|
||||
|
||||
foreach (ListViewItem item in LstUWPRemove.Items)
|
||||
{
|
||||
// Clone the item to add to the other ListView
|
||||
itemsToMove.Add((ListViewItem)item.Clone());
|
||||
}
|
||||
|
||||
// Add to destination ListView
|
||||
LstUWP.Items.AddRange(itemsToMove.ToArray());
|
||||
|
||||
// Clear source ListView
|
||||
LstUWPRemove.Items.Clear();
|
||||
|
||||
RefreshUWP();
|
||||
}
|
||||
|
||||
@@ -247,13 +256,89 @@ namespace Perfect11
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
|
||||
MessageBox.Show(RemoveUWP());
|
||||
|
||||
MessageBox.Show(RemoveUWP(),"Perfect11",MessageBoxButtons.OK,MessageBoxIcon.Information);
|
||||
LstUWPRemove.Items.Clear();
|
||||
GetUWP();
|
||||
Enabled = true;
|
||||
}
|
||||
}
|
||||
private void InitializeTweaks()
|
||||
{
|
||||
if (!Directory.Exists("Tweaks"))
|
||||
{
|
||||
Directory.CreateDirectory("Tweaks");
|
||||
}
|
||||
if (File.Exists("Tweaks\\Perfect11.TweaksInterface.dll"))
|
||||
{
|
||||
File.Delete("Tweaks\\Perfect11.TweaksInterface.dll");
|
||||
}
|
||||
tweaksList.View = View.Details;
|
||||
tweaksList.Columns.Add("Name", 150);
|
||||
tweaksList.Columns.Add("Description", 300);
|
||||
tweaksList.FullRowSelect = true;
|
||||
int totalWidth = tweaksList.ClientSize.Width;
|
||||
tweaksList.Columns[0].Width = (int)(totalWidth * 0.4);
|
||||
tweaksList.Columns[1].Width = (int)(totalWidth * 0.6);
|
||||
|
||||
// Load plugins
|
||||
_tweaks = Utilities.LoadTweaks("Tweaks");
|
||||
|
||||
// Populate ListView
|
||||
foreach (var plugin in _tweaks)
|
||||
{
|
||||
var item = new ListViewItem(plugin.Name);
|
||||
item.SubItems.Add(plugin.Description);
|
||||
item.Tag = plugin; // store the plugin object for later
|
||||
tweaksList.Items.Add(item);
|
||||
}
|
||||
if (tweaksList.Items.Count == 0) runTweaks.Enabled = false;
|
||||
}
|
||||
private void InitializeDarkMode()
|
||||
{
|
||||
if (Utilities.IsAppsDarkMode())
|
||||
{
|
||||
DarkMode(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DarkMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async void runTweaks_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (tweaksList.SelectedItems.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Select one or more plugins to run.","Perfect11",MessageBoxButtons.OK,MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Enabled = false; // prevent multiple clicks
|
||||
try
|
||||
{
|
||||
foreach (ListViewItem item in tweaksList.SelectedItems)
|
||||
{
|
||||
if (item.Tag is IPlugin plugin)
|
||||
{
|
||||
await Task.Run(() => plugin.Execute()); // run in background thread
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error running plugin: {ex.Message}", "Perfect11", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void tweaksList_Resize(object sender, EventArgs e)
|
||||
{
|
||||
int totalWidth = tweaksList.ClientSize.Width;
|
||||
tweaksList.Columns[0].Width = (int)(totalWidth * 0.4);
|
||||
tweaksList.Columns[1].Width = (int)(totalWidth * 0.6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user