-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.axaml.cs
195 lines (173 loc) · 7.54 KB
/
MainWindow.axaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AndroidDebloater.Components;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.TextFormatting.Unicode;
using MsBox.Avalonia;
namespace AndroidDebloater
{
public partial class MainWindow : Window
{
private ObservableCollection<AndroidPackage> _items;
public MainWindow()
{
InitializeComponent();
DebloatBtn.IsEnabled = false;
CDebloatBtn.IsEnabled = false;
mSelector.IsEnabled = false;
sSelector.IsEnabled = false;
ScriptPanel.IsVisible = false;
CustomPanel.IsVisible = false;
cSelector.IsEnabled = false;
clOutput.Text = BuildHelp();
}
public void ShowHelp(object sender, RoutedEventArgs args)
{
var helpBox = MessageBoxManager.GetMessageBoxStandard("Help", "Welcome to AndroidDebloater!\n\n"
+ "To get started, please enable USB-Debugging on your Phone.\n"
+ "To do this, go to the about page in your settings and click the 'Build number' 7 times.\n"
+ "Next, go to Developer Settings and Enable USB-Debugging.\n\n"
+ "Now connect your phone, allow Debugging for your PC on your Phone and Click the 'List ADB Devices' button.\n\n"
+ "If there are any problems when using this App, feel free to open an Issue on GitHub.", MsBox.Avalonia.Enums.ButtonEnum.Ok);
var result = helpBox.ShowAsPopupAsync(this);
}
public void ListDevices(object sender, RoutedEventArgs args)
{
clOutput.Text = ShellExecutor.ListADB();
// Regular expression to match the exact word "device"
string pattern = @"\bdevice\b";
// Match only lines with the exact word "device"
foreach (string line in clOutput.Text.Split('\n'))
{
if (Regex.IsMatch(line.Trim(), pattern))
{
Console.WriteLine($"Matched: {line.Trim()}");
DebloatBtn.IsEnabled = true;
CDebloatBtn.IsEnabled = true;
cSelector.IsEnabled = true;
sSelector.IsEnabled = true;
ScriptPanel.IsVisible = true;
}
}
}
public void StartDebloater(object sender, RoutedEventArgs args)
{
if ((bool)gDebloat.IsChecked)
{
clOutput.Text = ShellExecutor.StartDebloat(1);
}else if ((bool)aDebloat.IsChecked)
{
clOutput.Text = ShellExecutor.StartDebloat(2);
}else if ((bool)tpDebloat.IsChecked)
{
clOutput.Text = ShellExecutor.StartDebloat(3);
}
else
{
//Manufacturer Debloat
int selectedIndex = mSelector.SelectedIndex;
switch (selectedIndex)
{
case 0:
//Google
clOutput.Text = ShellExecutor.StartDebloat(4);
break;
case 1:
//Huawei
clOutput.Text = ShellExecutor.StartDebloat(5);
break;
case 2:
//Oneplus
clOutput.Text = ShellExecutor.StartDebloat(6);
break;
case 3:
//Oppo
clOutput.Text = ShellExecutor.StartDebloat(7);
break;
case 4:
//Realme
clOutput.Text = ShellExecutor.StartDebloat(8);
break;
case 5:
//Samsung
clOutput.Text = ShellExecutor.StartDebloat(9);
break;
case 6:
//Vivo
clOutput.Text = ShellExecutor.StartDebloat(10);
break;
case 7:
//Xiaomi
clOutput.Text = ShellExecutor.StartDebloat(11);
break;
}
}
}
public void EnableSelector(object sender, RoutedEventArgs args)
{
mSelector.IsEnabled = true;
}
public void DisableSelector(object sender, RoutedEventArgs args)
{
mSelector.IsEnabled = false;
}
public void ShowScripts(object sender, RoutedEventArgs args)
{
ScriptPanel.IsVisible = true;
CustomPanel.IsVisible = false;
}
public void ShowCustomSelector(object sender, RoutedEventArgs args)
{
CustomPanel.IsVisible = true;
ScriptPanel.IsVisible = false;
_items = new ObservableCollection<AndroidPackage>(CreateObservableCollection(ShellExecutor.GetPackages()));
// Get the ItemsControl by name and set its ItemsSource
var packageControl = this.FindControl<ItemsControl>("PackageList");
packageControl.ItemsSource = _items;
}
private void RemoveSelected(object sender, RoutedEventArgs e)
{
var selectedItems = new List<string>();
foreach (var item in _items)
{
if (item.IsChecked)
{
selectedItems.Add(item.Text);
}
}
clOutput.Text = "Uninstalling " + selectedItems.Count + " packages... \n";
foreach (var item in selectedItems)
{
clOutput.Text += item + ": " +ShellExecutor.RemovePackage(item);
}
}
public ObservableCollection<AndroidPackage> CreateObservableCollection(string input)
{
var collection = new ObservableCollection<AndroidPackage>();
// Split the input into lines
var lines = input.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
// Remove the "package:" prefix and add to the collection
var cleanedLine = line.Replace("package:", "").Trim();
collection.Add(new AndroidPackage { Text = cleanedLine, IsChecked = false });
}
return collection;
}
public string BuildHelp()
{
string help = "Welcome to AndroidDebloater!\n\n"
+ "To get started, please enable USB-Debugging on your Phone.\n"
+ "To do this, go to the about page in your settings and click the 'Build number' 7 times.\n"
+ "Next, go to Developer Settings and Enable USB-Debugging.\n\n"
+ "Now connect your phone, allow Debugging for your PC on your Phone and Click the 'List ADB Devices' button.\n\n"
+ "If there are any problems when using this App, feel free to open an Issue on GitHub.";
return help;
}
}
}