-
Notifications
You must be signed in to change notification settings - Fork 164
/
MainWindow.cs
777 lines (657 loc) 路 28.8 KB
/
MainWindow.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
锘縰sing Privatezilla.ITreeNode;
using Privatezilla.Locales;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Privatezilla
{
public partial class MainWindow : Form
{
// Setting progress
private int _progress = 0;
private int _progressIncrement = 0;
// Update
private readonly string _releaseURL = "https://raw.githubusercontent.com/builtbybel/privatezilla/master/latest.txt";
public Version CurrentVersion = new Version(Application.ProductVersion);
public Version LatestVersion;
private void CheckRelease_Click(object sender, EventArgs e)
{
try
{
WebRequest hreq = WebRequest.Create(_releaseURL);
hreq.Timeout = 10000;
hreq.Headers.Set("Cache-Control", "no-cache, no-store, must-revalidate");
WebResponse hres = hreq.GetResponse();
StreamReader sr = new StreamReader(hres.GetResponseStream());
LatestVersion = new Version(sr.ReadToEnd().Trim());
// Done and dispose!
sr.Dispose();
hres.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); // Update check failed!
}
var equals = LatestVersion.CompareTo(CurrentVersion);
if (equals == 0)
{
MessageBox.Show(Locale.releaseUpToDate, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // Up-to-date
}
else if (equals < 0)
{
MessageBox.Show(Locale.releaseUnofficial, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); // Unofficial
}
else // New release available!
{
if (MessageBox.Show(Locale.releaseUpdateAvailable + LatestVersion + Locale.releaseUpdateYourVersion.Replace("\\r\\n", "\r\n") + CurrentVersion + Locale.releaseUpdateAvailableURL.Replace("\\r\\n", "\r\n\n"), this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // New release available!
{
Process.Start("https://github.com/builtbybel/privatezilla/releases/tag/" + LatestVersion);
}
}
}
public void Globalization()
{
BtnDoPS.Text = Locale.BtnDoPS;
BtnSettingsAnalyze.Text = Locale.BtnSettingsAnalyze;
BtnSettingsDo.Text = Locale.BtnSettingsDo;
BtnSettingsUndo.Text = Locale.BtnSettingsUndo;
ChkCodePS.Text = Locale.ChkCodePS;
LblPS.Text = Locale.LblPS;
LblPSHeader.Text = Locale.LblPSHeader;
LblSettings.Text = Locale.LblSettings;
LblStatus.Text = Locale.LblStatus;
TxtPSInfo.Text = Locale.TxtPSInfo;
CheckRelease.Text = Locale.CheckRelease;
CommunityPkg.Text = Locale.CommunityPkg;
Help.Text = Locale.Help;
Info.Text = Locale.Info;
PSImport.Text = Locale.PSImport;
PSMarketplace.Text = Locale.PSMarketplace;
PSSaveAs.Text = Locale.PSSaveAs;
Setting.Text = Locale.columnSetting; // Status column
State.Text = Locale.columnState; // State column
}
public MainWindow()
{
// Uncomment lower line and add lang code to run localization test
// Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
InitializeComponent();
// Initilize settings
InitializeSettings();
// Check if community package is installed
CommunityPackageAvailable();
// GUI options
LblMainMenu.Text = "\ue700"; // Hamburger menu
// GUI localization
Globalization();
}
public void InitializeSettings()
{
TvwSettings.Nodes.Clear();
// Root node
TreeNode root = new TreeNode("Windows 10 (" + WindowsHelper.GetOS() + ")")
{
Checked = false
};
// Settings > Privacy
TreeNode privacy = new TreeNode(Locale.rootSettingsPrivacy, new TreeNode[] {
new SettingNode(new Setting.Privacy.DisableTelemetry()),
new SettingNode(new Setting.Privacy.DisableCompTelemetry()),
new SettingNode(new Setting.Privacy.DisableAds()),
new SettingNode(new Setting.Privacy.DisableWiFi()),
new SettingNode(new Setting.Privacy.DiagnosticData()),
new SettingNode(new Setting.Privacy.HandwritingData()),
new SettingNode(new Setting.Privacy.DisableBiometrics()),
new SettingNode(new Setting.Privacy.DisableTimeline()),
new SettingNode(new Setting.Privacy.DisableLocation()),
new SettingNode(new Setting.Privacy.DisableFeedback()),
new SettingNode(new Setting.Privacy.DisableTips()),
new SettingNode(new Setting.Privacy.DisableTipsLockScreen()),
new SettingNode(new Setting.Privacy.InstalledApps()),
new SettingNode(new Setting.Privacy.SuggestedApps()),
new SettingNode(new Setting.Privacy.SuggestedContent()),
new SettingNode(new Setting.Privacy.DisableCEIP()),
new SettingNode(new Setting.Privacy.DisableHEIP()),
new SettingNode(new Setting.Privacy.DisableMSExperiments()),
new SettingNode(new Setting.Privacy.InventoryCollector()),
new SettingNode(new Setting.Privacy.GetMoreOutOfWindows()),
})
{
//Checked = true,
//ToolTipText = "Privacy settings"
};
// Policies > Cortana
TreeNode cortana = new TreeNode(Locale.rootSettingsCortana, new TreeNode[] {
new SettingNode(new Setting.Cortana.DisableCortana()),
new SettingNode(new Setting.Cortana.DisableBing()),
new SettingNode(new Setting.Cortana.UninstallCortana()),
});
// Settings > Bloatware
TreeNode bloatware = new TreeNode(Locale.rootSettingsBloatware, new TreeNode[] {
new SettingNode(new Setting.Bloatware.RemoveUWPAll()),
new SettingNode(new Setting.Bloatware.RemoveUWPDefaults()),
})
{
ToolTipText = Locale.rootSettingsBloatwareInfo
};
// Settings > App permissions
TreeNode apps = new TreeNode(Locale.rootSettingsApps, new TreeNode[] {
new SettingNode(new Setting.Apps.AppNotifications()),
new SettingNode(new Setting.Apps.Camera()),
new SettingNode(new Setting.Apps.Microphone()),
new SettingNode(new Setting.Apps.Call()),
new SettingNode(new Setting.Apps.Notifications()),
new SettingNode(new Setting.Apps.AccountInfo()),
new SettingNode(new Setting.Apps.Contacts()),
new SettingNode(new Setting.Apps.Calendar()),
new SettingNode(new Setting.Apps.CallHistory()),
new SettingNode(new Setting.Apps.Email()),
new SettingNode(new Setting.Apps.Tasks()),
new SettingNode(new Setting.Apps.Messaging()),
new SettingNode(new Setting.Apps.Motion()),
new SettingNode(new Setting.Apps.OtherDevices()),
new SettingNode(new Setting.Apps.BackgroundApps()),
new SettingNode(new Setting.Apps.TrackingApps()),
new SettingNode(new Setting.Apps.DiagnosticInformation()),
new SettingNode(new Setting.Apps.Documents()),
new SettingNode(new Setting.Apps.Pictures()),
new SettingNode(new Setting.Apps.Videos()),
new SettingNode(new Setting.Apps.Radios()),
new SettingNode(new Setting.Apps.FileSystem()),
new SettingNode(new Setting.Apps.EyeGaze()),
new SettingNode(new Setting.Apps.CellularData()),
});
// Settings > Updates
TreeNode updates = new TreeNode(Locale.rootSettingsUpdates, new TreeNode[] {
new SettingNode(new Setting.Updates.DisableUpdates()),
new SettingNode(new Setting.Updates.DisableUpdatesSharing()),
new SettingNode(new Setting.Updates.BlockMajorUpdates()),
new SettingNode(new Setting.Updates.DisableSafeguards()),
});
// Settings > Gaming
TreeNode gaming = new TreeNode(Locale.rootSettingsGaming, new TreeNode[] {
new SettingNode(new Setting.Gaming.DisableGameBar()),
});
// Settings > Windows Defender
TreeNode defender = new TreeNode(Locale.rootSettingsDefender, new TreeNode[] {
new SettingNode(new Setting.Defender.DisableSmartScreenStore()),
});
// Settings > Microsoft Edge
TreeNode edge = new TreeNode(Locale.rootSettingsEdge, new TreeNode[] {
new SettingNode(new Setting.Edge.DisableAutoFillCredits()),
new SettingNode(new Setting.Edge.EdgeBackground()),
new SettingNode(new Setting.Edge.DisableSync()),
new SettingNode(new Setting.Edge.BlockEdgeRollout()),
});
// Settings > Security
TreeNode security = new TreeNode(Locale.rootSettingsSecurity, new TreeNode[] {
new SettingNode(new Setting.Security.DisablePassword()),
new SettingNode(new Setting.Security.WindowsDRM()),
});
// Add root nodes
root.Nodes.AddRange(new TreeNode[]
{
privacy,
cortana,
bloatware,
apps,
updates,
gaming,
defender,
edge,
security,
});
TvwSettings.Nodes.Add(root);
TvwSettings.ExpandAll();
// Preselect nodes
CheckNodes(privacy);
// Set up ToolTip text for TvwSettings
ToolTip tooltip = new ToolTip();
tooltip.AutoPopDelay = 15000;
tooltip.IsBalloon = true;
tooltip.SetToolTip(this.TvwSettings, Locale.LblSettings);
}
private List<SettingNode> CollectSettingNodes()
{
List<SettingNode> selectedSettings = new List<SettingNode>();
foreach (TreeNode treeNode in TvwSettings.Nodes.All())
{
if (treeNode.Checked && treeNode.GetType() == typeof(SettingNode))
{
selectedSettings.Add((SettingNode)treeNode);
}
}
_progressIncrement = (int)Math.Floor(100.0f / selectedSettings.Count);
return selectedSettings;
}
private void Reset()
{
_progress = 0;
_progressIncrement = 0;
PBar.Visible = true;
PBar.Value = 0;
LvwStatus.HeaderStyle = ColumnHeaderStyle.Clickable; // Add Header to ListView
LvwStatus.Items.Clear();
LvwStatus.Refresh();
}
private void IncrementProgress()
{
_progress += _progressIncrement;
PBar.Value = _progress;
}
private void DoProgress(int value)
{
_progress = value;
PBar.Value = _progress;
}
// Check favored parent node including all child nodes
public void CheckNodes(TreeNode startNode)
{
startNode.Checked = true;
foreach (TreeNode node in startNode.Nodes)
CheckNodes(node);
}
/// <summary>
/// Auto check child nodes when parent node is checked
/// </summary>
private void TvwSetting_AfterCheck(object sender, TreeViewEventArgs e)
{
TvwSettings.BeginUpdate();
foreach (TreeNode child in e.Node.Nodes)
{
child.Checked = e.Node.Checked;
}
TvwSettings.EndUpdate();
}
/// <summary>
/// Method to auto. resize column and set the width to the width of the last item in ListView
/// </summary>
private void ResizeListViewColumns(ListView lv)
{
foreach (ColumnHeader column in lv.Columns)
{
column.Width = -2;
}
}
/// <summary>
/// Check system for configured settings
/// </summary>
private async void BtnSettingsAnalyze_Click(object sender, EventArgs e)
{
Reset();
int performSettingsCount = 0;
LblStatus.Text = Locale.statusDoWait;
BtnSettingsAnalyze.Enabled = false;
LvwStatus.BeginUpdate();
List<SettingNode> selectedSettings = CollectSettingNodes();
foreach (SettingNode node in selectedSettings)
{
var setting = node.Setting;
ListViewItem state = new ListViewItem(node.Parent.Text + ": " + setting.ID());
ConfiguredTaskAwaitable<bool> analyzeTask = Task<bool>.Factory.StartNew(() => setting.CheckSetting()).ConfigureAwait(true);
bool shouldPerform = await analyzeTask;
if (shouldPerform)
{
state.SubItems.Add(Locale.statusFailedConfigure); // Not configured
state.BackColor = Color.LavenderBlush;
performSettingsCount += 1;
}
else
{
state.SubItems.Add(Locale.statusSuccessConfigure); // Configured
state.BackColor = Color.Honeydew;
}
state.Tag = setting;
LvwStatus.Items.Add(state);
IncrementProgress();
}
DoProgress(100);
// Summary
var sum = (Locale.summarySelected + " " + $"{selectedSettings.Count}" + " - " + Locale.summaryConfigured + " " + $"{selectedSettings.Count - performSettingsCount}" + " - " + Locale.summaryNotConfigured + " " + $"{performSettingsCount}");
LblStatus.Text = Locale.statusFinishAnalyze + "\n" + sum;
BtnSettingsAnalyze.Enabled = true;
LvwStatus.EndUpdate();
ResizeListViewColumns(LvwStatus);
}
/// <summary>
/// Apply selected settings
/// </summary>
///
private async void ApplySettings(List<SettingNode> treeNodes)
{
BtnSettingsDo.Enabled = false;
LvwStatus.BeginUpdate();
foreach (SettingNode node in treeNodes)
{
// Add status info
LblStatus.Text = Locale.statusDoWait + " (" + node.Text + ")";
var setting = node.Setting;
ConfiguredTaskAwaitable<bool> performTask = Task<bool>.Factory.StartNew(() => setting.DoSetting()).ConfigureAwait(true);
var result = await performTask;
var listItem = new ListViewItem(setting.ID());
if (result)
{
listItem.SubItems.Add(Locale.statusSuccessApply); // Applied
listItem.BackColor = Color.Honeydew;
}
else
{
listItem.SubItems.Add(Locale.statusFailedApply); // Not applied
listItem.BackColor = Color.LavenderBlush;
}
LvwStatus.Items.Add(listItem);
IncrementProgress();
}
DoProgress(100);
LblStatus.Text = Locale.statusFinishApply;
BtnSettingsDo.Enabled = true;
LvwStatus.EndUpdate();
ResizeListViewColumns(LvwStatus);
}
/// <summary>
/// Revert selected settings
/// </summary>
private async void UndoSettings(List<SettingNode> treeNodes)
{
LblStatus.Text = Locale.statusDoWait;
BtnSettingsUndo.Enabled = false;
LvwStatus.BeginUpdate();
foreach (SettingNode node in treeNodes)
{
var setting = node.Setting;
ConfiguredTaskAwaitable<bool> performTask = Task<bool>.Factory.StartNew(() => setting.UndoSetting()).ConfigureAwait(true);
var result = await performTask;
var listItem = new ListViewItem(setting.ID());
if (result)
{
listItem.SubItems.Add(Locale.statusSuccessApply); // Applied
listItem.BackColor = Color.Honeydew;
}
else
{
listItem.SubItems.Add(Locale.statusFailedApply); // Not applied
listItem.BackColor = Color.LavenderBlush;
}
LvwStatus.Items.Add(listItem);
IncrementProgress();
}
DoProgress(100);
LblStatus.Text = Locale.statusFinishUndo;
BtnSettingsUndo.Enabled = true;
LvwStatus.EndUpdate();
ResizeListViewColumns(LvwStatus);
}
private void BtnSettingsDo_Click(object sender, EventArgs e)
{
Reset();
List<SettingNode> performNodes = CollectSettingNodes();
ApplySettings(performNodes);
}
private void BtnSettingsUndo_Click(object sender, EventArgs e)
{
if (MessageBox.Show(Locale.statusUndoSettings, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
Reset();
List<SettingNode> performNodes = CollectSettingNodes();
UndoSettings(performNodes);
}
}
private void Info_Click(object sender, EventArgs e)
{
MessageBox.Show("Privatezilla" + "\nVersion " + Program.GetCurrentVersionTostring() + " (Pollux)\r\n" +
Locale.infoApp.Replace("\\t", "\t"), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void LblMainMenu_Click(object sender, EventArgs e)
{
this.MainMenu.Show(Cursor.Position.X, Cursor.Position.Y);
}
private void Help_Click(object sender, EventArgs e)
{
MessageBox.Show(Locale.helpApp.Replace("\\r\\n", "\r\n"), Help.Text, MessageBoxButtons.OK, MessageBoxIcon.Question);
}
/// <summary>
/// Populate Setting files to Navigation > settings > LstPopulatePS
/// </summary>
private void PopulatePS()
{
// Switch to More
PnlPS.Visible = true;
BtnDoPS.Visible = true;
ChkCodePS.Visible = true;
LstPS.Visible = true;
PnlSettings.Visible = false;
BtnSettingsAnalyze.Visible = false;
BtnSettingsUndo.Visible = false;
BtnSettingsDo.Visible = false;
TvwSettings.Visible = false;
// Clear list
LstPS.Items.Clear();
DirectoryInfo dirs = new DirectoryInfo(@"scripts");
FileInfo[] listSettings = dirs.GetFiles("*.ps1");
foreach (FileInfo fi in listSettings)
{
LstPS.Items.Add(Path.GetFileNameWithoutExtension(fi.Name));
LstPS.Enabled = true;
}
}
private void LblPS_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Show Info about feature
try
{
StreamReader OpenFile = new StreamReader(@"scripts\" + "readme.txt");
MessageBox.Show(OpenFile.ReadToEnd(), "Info about this feature", MessageBoxButtons.OK);
OpenFile.Close();
}
catch
{ }
// Refresh
PopulatePS();
}
private void LblSettings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Switch to Setting
PnlSettings.Visible = true;
BtnSettingsAnalyze.Visible = true;
BtnSettingsUndo.Visible = true;
BtnSettingsDo.Visible = true;
TvwSettings.Visible = true;
PnlPS.Visible = false;
BtnDoPS.Visible = false;
ChkCodePS.Visible = false;
LstPS.Visible = false;
}
private void LstPS_SelectedIndexChanged(object sender, EventArgs e)
{
string psdir = @"scripts\" + LstPS.Text + ".ps1";
//Read PS content line by line
try
{
using (StreamReader sr = new StreamReader(@"scripts\" + LstPS.Text + ".ps1", Encoding.Default))
{
StringBuilder content = new StringBuilder();
// writes line by line to the StringBuilder until the end of the file is reached
while (!sr.EndOfStream)
content.AppendLine(sr.ReadLine());
// View Code
TxtConsolePS.Text = content.ToString();
// View Info
TxtPSInfo.Text = Locale.PSInfo.Replace("\\r\\n", "\r\n") + string.Join(Environment.NewLine, System.IO.File.ReadAllLines(psdir).Where(s => s.StartsWith("###")).Select(s => s.Substring(3).Replace("###", "\r\n\n")));
}
}
catch { }
}
/// <summary>
/// Run custom PowerShell scripts
/// </summary>
private async void BtnDoPS_Click(object sender, EventArgs e)
{
if (LstPS.CheckedItems.Count == 0)
{
MessageBox.Show(Locale.msgPSSelect, BtnDoPS.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
for (int i = 0; i < LstPS.Items.Count; i++)
{
if (LstPS.GetItemChecked(i))
{
LstPS.SelectedIndex = i;
string psdir = @"scripts\" + LstPS.SelectedItem.ToString() + ".ps1";
var ps1File = psdir;
var equals = new[] { "Silent" };
var str = TxtPSInfo.Text;
BtnDoPS.Text = Locale.statusDoPSProcessing;
PnlPS.Enabled = false;
// Silent
if (equals.Any(str.Contains))
{
var startInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-executionpolicy bypass -file \"{ps1File}\"",
UseShellExecute = false,
CreateNoWindow = true,
};
await Task.Run(() => { Process.Start(startInfo).WaitForExit(); });
}
else // Create ConsoleWindow
{
var startInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-executionpolicy bypass -file \"{ps1File}\"",
UseShellExecute = false,
};
await Task.Run(() => { Process.Start(startInfo).WaitForExit(); });
}
BtnDoPS.Text = Locale.statusDoPSApply;
PnlPS.Enabled = true;
// Done!
MessageBox.Show("Script " + "\"" + LstPS.Text + "\" " + Locale.msgPSSuccess, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
/// <summary>
/// Open PowerShell code view
/// </summary>
private void ChkCodePS_CheckedChanged(object sender, EventArgs e)
{
if (ChkCodePS.Checked == true)
{
ChkCodePS.Text = Locale.PSBack;
TxtConsolePS.Visible = true;
}
else
{
ChkCodePS.Text = Locale.ChkCodePS;
TxtConsolePS.Visible = false;
}
}
/// <summary>
/// Import PowerShell script files
/// </summary>
private void PSImport_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.txt|*.txt|*.ps1|*.ps1";
ofd.DefaultExt = ".ps1";
ofd.RestoreDirectory = true;
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
ofd.FilterIndex = 2;
string strDestPath = Application.StartupPath + @"\scripts";
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
foreach (string fileName in ofd.FileNames)
{
try
{
File.Copy(fileName, strDestPath + @"\" + Path.GetFileName(fileName));
}
catch (Exception ex)
{ MessageBox.Show(ex.Message, this.Text); }
}
}
// Refresh
PopulatePS();
}
/// <summary>
/// Save PowerShell script files as new preset script files
/// </summary>
private void PSSaveAs_Click(object sender, EventArgs e)
{
if (ChkCodePS.Checked == false)
{
MessageBox.Show(Locale.msgPSSave, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "*.txt|*.txt|*.ps1|*.ps1";
dlg.DefaultExt = ".ps1";
dlg.RestoreDirectory = true;
dlg.InitialDirectory = Application.StartupPath + @"\scripts";
dlg.FilterIndex = 2;
try
{
if (dlg.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(dlg.FileName, TxtConsolePS.Text, Encoding.UTF8);
//Refresh
PopulatePS();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void PSMarketplace_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/builtbybel/privatezilla/tree/master/scripts");
}
private void CommunityPkg_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/builtbybel/privatezilla#community-package");
}
// Check if community package installed
private void CommunityPackageAvailable()
{
string path = @"scripts";
if (Directory.Exists(path))
{
LblPS.Visible = true;
CommunityPkg.Visible = false;
}
}
private bool sortAscending = false;
private void LvwStatus_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (!sortAscending)
{
sortAscending = true;
}
else
{
sortAscending = false;
}
this.LvwStatus.ListViewItemSorter = new ListViewItemComparer(e.Column, sortAscending);
}
private void BtnMenuPS_Click(object sender, EventArgs e)
{
this.PSMenu.Show(Cursor.Position.X, Cursor.Position.Y);
}
private void assetOpenGitHubPage_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/builtbybel/privatezilla");
}
}
}