-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUWFManager.cs
More file actions
4252 lines (3766 loc) · 177 KB
/
Copy pathUWFManager.cs
File metadata and controls
4252 lines (3766 loc) · 177 KB
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
namespace PortableUwfManager
{
internal static class Program
{
[STAThread]
private static int Main(string[] args)
{
if (args != null && args.Length > 0 && String.Equals(args[0], "--self-test", StringComparison.OrdinalIgnoreCase))
{
return SelfTest.Run();
}
if (!UwfController.IsAdministrator())
{
string error;
if (Elevation.TryRelaunchCurrentProcessAsAdministrator(args, out error))
{
return 0;
}
MessageBox.Show(
UiText.T("UWF 설정 변경은 상승된 관리자 권한이 필요합니다.\r\n\r\n" + error,
"Changing UWF settings requires elevated administrator rights.\r\n\r\n" + error),
UiText.T("관리자 권한 필요", "Administrator required"),
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return 1;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
return 0;
}
}
internal static class Elevation
{
public static bool TryRelaunchCurrentProcessAsAdministrator(string[] args, out string error)
{
error = String.Empty;
try
{
var exe = Process.GetCurrentProcess().MainModule.FileName;
var info = new ProcessStartInfo(exe);
info.UseShellExecute = true;
info.Verb = "runas";
info.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
info.Arguments = BuildArgumentString(args);
Process.Start(info);
return true;
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == 1223)
{
error = UiText.T("사용자가 UAC 승인을 취소했습니다.", "The UAC elevation prompt was canceled.");
}
else
{
error = ex.Message;
}
return false;
}
catch (Exception ex)
{
error = ex.Message;
return false;
}
}
public static string[] GetCurrentProcessArguments()
{
var all = Environment.GetCommandLineArgs();
if (all == null || all.Length <= 1)
{
return new string[0];
}
var args = new string[all.Length - 1];
Array.Copy(all, 1, args, 0, args.Length);
return args;
}
public static string BuildArgumentString(string[] args)
{
if (args == null || args.Length == 0)
{
return String.Empty;
}
var text = new StringBuilder();
for (int i = 0; i < args.Length; i++)
{
if (i > 0)
{
text.Append(' ');
}
text.Append(QuoteArgumentForCreateProcess(args[i]));
}
return text.ToString();
}
internal static string QuoteArgumentForCreateProcess(string argument)
{
if (String.IsNullOrEmpty(argument))
{
return "\"\"";
}
bool needsQuotes = false;
for (int i = 0; i < argument.Length; i++)
{
if (Char.IsWhiteSpace(argument[i]) || argument[i] == '"')
{
needsQuotes = true;
break;
}
}
if (!needsQuotes)
{
return argument;
}
var quoted = new StringBuilder();
quoted.Append('"');
int backslashCount = 0;
for (int i = 0; i < argument.Length; i++)
{
char c = argument[i];
if (c == '\\')
{
backslashCount++;
continue;
}
if (c == '"')
{
quoted.Append('\\', backslashCount * 2 + 1);
quoted.Append('"');
backslashCount = 0;
continue;
}
if (backslashCount > 0)
{
quoted.Append('\\', backslashCount);
backslashCount = 0;
}
quoted.Append(c);
}
if (backslashCount > 0)
{
quoted.Append('\\', backslashCount * 2);
}
quoted.Append('"');
return quoted.ToString();
}
}
internal enum UiLanguage
{
Korean,
English
}
internal static class UiText
{
public static UiLanguage Current = UiLanguage.Korean;
public static string T(string ko, string en)
{
return Current == UiLanguage.Korean ? ko : en;
}
}
internal sealed class MainForm : Form
{
private readonly UwfController controller;
private readonly ToolTip helpTip;
private TabControl mainTabs;
private readonly Dictionary<string, Label> dashboardLabels;
private readonly ProgressBar overlayProgress;
private readonly ComboBox languageBox;
private readonly TextBox statusBox;
private readonly TextBox logBox;
private readonly Label adminLabel;
private readonly Label uwfLabel;
private readonly Label osLabel;
private readonly ComboBox overlayTypeBox;
private readonly ComboBox volumeBox;
private readonly NumericUpDown overlaySizeBox;
private readonly NumericUpDown warningPercentBox;
private readonly NumericUpDown criticalPercentBox;
private readonly ComboBox workloadBox;
private readonly TextBox fileExclusionBox;
private readonly TextBox registryExclusionBox;
private readonly ListBox fileExclusionListBox;
private readonly ListBox registryExclusionListBox;
private readonly Label fileExclusionListLabel;
private readonly Label registryExclusionListLabel;
private readonly TextBox commitFileBox;
private readonly TextBox commitRegistryKeyBox;
private readonly TextBox commitRegistryValueBox;
public MainForm()
{
controller = new UwfController();
dashboardLabels = new Dictionary<string, Label>();
overlayProgress = new ProgressBar();
helpTip = new ToolTip();
helpTip.AutoPopDelay = 12000;
helpTip.InitialDelay = 500;
helpTip.ReshowDelay = 100;
Text = UiText.T("포터블 UWF 관리자", "Portable UWF Manager");
Width = 1120;
Height = 760;
MinimumSize = new Size(980, 640);
StartPosition = FormStartPosition.CenterScreen;
Font = new Font("Segoe UI", 9F);
languageBox = new ComboBox();
statusBox = CreateMultilineBox(true);
logBox = CreateMultilineBox(true);
adminLabel = CreateBadgeLabel();
uwfLabel = CreateBadgeLabel();
osLabel = CreateBadgeLabel();
overlayTypeBox = new ComboBox();
volumeBox = new ComboBox();
overlaySizeBox = new NumericUpDown();
warningPercentBox = new NumericUpDown();
criticalPercentBox = new NumericUpDown();
workloadBox = new ComboBox();
fileExclusionBox = new TextBox();
registryExclusionBox = new TextBox();
fileExclusionListBox = new ListBox();
registryExclusionListBox = new ListBox();
fileExclusionListLabel = new Label();
registryExclusionListLabel = new Label();
commitFileBox = new TextBox();
commitRegistryKeyBox = new TextBox();
commitRegistryValueBox = new TextBox();
fileExclusionListBox.DoubleClick += delegate { UseSelectedFileExclusion(); };
registryExclusionListBox.DoubleClick += delegate { UseSelectedRegistryExclusion(); };
BuildUi();
RefreshStatus();
}
private void BuildUi()
{
Text = UiText.T("포터블 UWF 관리자", "Portable UWF Manager");
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.ColumnCount = 1;
root.RowCount = 4;
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 68F));
root.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 150F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
Controls.Add(root);
var header = new TableLayoutPanel();
header.Dock = DockStyle.Fill;
header.Padding = new Padding(12, 8, 12, 4);
header.ColumnCount = 6;
header.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 220F));
header.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
header.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
header.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 34F));
header.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 120F));
header.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 160F));
root.Controls.Add(header, 0, 0);
var title = new Label();
title.Text = UiText.T("포터블 UWF 관리자", "Portable UWF Manager");
title.Dock = DockStyle.Fill;
title.Font = new Font(Font.FontFamily, 14F, FontStyle.Bold);
title.TextAlign = ContentAlignment.MiddleLeft;
header.Controls.Add(title, 0, 0);
header.Controls.Add(adminLabel, 1, 0);
header.Controls.Add(uwfLabel, 2, 0);
header.Controls.Add(osLabel, 3, 0);
ConfigureLanguageBox();
header.Controls.Add(languageBox, 4, 0);
header.Controls.Add(CreateButton(UiText.T("관리자 실행", "Run as admin"), RelaunchAsAdmin), 5, 0);
mainTabs = new TabControl();
mainTabs.Dock = DockStyle.Fill;
root.Controls.Add(mainTabs, 0, 1);
mainTabs.TabPages.Add(BuildQuickStartTab());
mainTabs.TabPages.Add(BuildDashboardTab());
mainTabs.TabPages.Add(BuildSetupTab());
mainTabs.TabPages.Add(BuildExclusionsTab());
mainTabs.TabPages.Add(BuildAdvancedTab());
var logPanel = new TableLayoutPanel();
logPanel.Dock = DockStyle.Fill;
logPanel.Padding = new Padding(12, 4, 12, 4);
logPanel.ColumnCount = 2;
logPanel.RowCount = 1;
logPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
logPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 170F));
root.Controls.Add(logPanel, 0, 2);
logPanel.Controls.Add(logBox, 0, 0);
var logButtons = new FlowLayoutPanel();
logButtons.Dock = DockStyle.Fill;
logButtons.FlowDirection = FlowDirection.TopDown;
logButtons.Controls.Add(CreateButton(UiText.T("로그 복사", "Copy log"), CopyLog));
logButtons.Controls.Add(CreateButton(UiText.T("로그 지우기", "Clear log"), ClearLog));
logPanel.Controls.Add(logButtons, 1, 0);
var footer = new Label();
footer.Text = UiText.T("상태 조회는 일반 권한으로 가능하지만, 설정 변경은 관리자 권한과 재부팅이 필요할 수 있습니다.",
"Read-only status works without elevation. Configuration changes require administrator rights and usually require a reboot.");
footer.Dock = DockStyle.Fill;
footer.TextAlign = ContentAlignment.MiddleLeft;
footer.Padding = new Padding(12, 0, 12, 0);
root.Controls.Add(footer, 0, 3);
}
private void ConfigureLanguageBox()
{
languageBox.DropDownStyle = ComboBoxStyle.DropDownList;
languageBox.Items.Clear();
languageBox.Items.Add("한국어");
languageBox.Items.Add("English");
languageBox.SelectedIndex = UiText.Current == UiLanguage.Korean ? 0 : 1;
languageBox.Dock = DockStyle.Fill;
languageBox.SelectedIndexChanged -= LanguageChanged;
languageBox.SelectedIndexChanged += LanguageChanged;
}
private void LanguageChanged(object sender, EventArgs e)
{
var next = languageBox.SelectedIndex == 1 ? UiLanguage.English : UiLanguage.Korean;
if (UiText.Current == next)
{
return;
}
UiText.Current = next;
Controls.Clear();
BuildUi();
RefreshStatus();
}
private TabPage BuildQuickStartTab()
{
var page = new TabPage(UiText.T("빠른 시작", "Quick start"));
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.Padding = new Padding(16);
root.ColumnCount = 2;
root.RowCount = 3;
root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
root.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 210F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 150F));
root.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 64F));
page.Controls.Add(root);
var guide = CreateGuideBox(
UiText.T(
"처음 쓰는 순서\r\n\r\n1. 상태 확인: UWF 기능과 관리자 권한 상태를 먼저 봅니다.\r\n2. UWF 기능이 없으면 설치 후 재부팅합니다.\r\n3. 잘 모르겠으면 RAM 추천값을 먼저 사용합니다. RAM은 가볍고 관리가 단순합니다.\r\n4. 게임/패치처럼 쓰기량이 크면 DISK 추천값을 검토합니다.\r\n5. 적용 전에는 항상 작업 계획을 확인하고, 적용 후 재부팅하세요.",
"First-use flow\r\n\r\n1. Check status first: verify UWF feature and administrator state.\r\n2. If UWF is missing, install the feature and reboot.\r\n3. If unsure, start with the RAM recommendation. RAM mode is lightweight and simpler.\r\n4. For heavy writes such as game patches, review the DISK recommendation.\r\n5. Always review the operation plan before applying, then reboot."));
root.Controls.Add(guide, 0, 0);
var buttons = new FlowLayoutPanel();
buttons.Dock = DockStyle.Fill;
buttons.FlowDirection = FlowDirection.TopDown;
buttons.WrapContents = false;
buttons.Controls.Add(CreateButton(UiText.T("1. 상태 확인", "1. Check status"), RefreshStatus));
buttons.Controls.Add(CreateButton(UiText.T("2. 관리자 실행", "2. Run as admin"), RelaunchAsAdmin));
buttons.Controls.Add(CreateButton(UiText.T("3. UWF 기능 설치", "3. Install UWF"), InstallFeature));
root.Controls.Add(buttons, 1, 0);
var beginner = CreateGuideBox(
UiText.T(
"추천 기준\r\n\r\nRAM 모드: 재부팅하면 변경이 사라지는 보호 환경에 적합합니다. 저장해야 하는 설정은 예외나 커밋으로 따로 관리하세요.\r\n\r\nDISK 모드: 쓰기량이 큰 환경에 맞지만 C: 여유 공간을 사용합니다. 여유 공간이 부족하면 큰 값을 피하세요.\r\n\r\n예외: overlay를 줄이는 기능이 아닙니다. 반드시 보존해야 하는 작은 설정/데이터에만 쓰세요.",
"Recommendation rules\r\n\r\nRAM mode: best for a protected environment where changes disappear after reboot. Persist needed settings through exclusions or commits.\r\n\r\nDISK mode: better for heavy writes, but it uses free space on C:. Avoid large values when free space is low.\r\n\r\nExclusions: they do not reduce overlay usage. Use them only for small settings/data that must persist."));
root.Controls.Add(beginner, 0, 1);
var recommendButtons = new FlowLayoutPanel();
recommendButtons.Dock = DockStyle.Fill;
recommendButtons.FlowDirection = FlowDirection.TopDown;
recommendButtons.WrapContents = false;
recommendButtons.Controls.Add(CreateButton(UiText.T("RAM 추천값 넣기", "Use RAM recommendation"), UseRecommendedRam));
recommendButtons.Controls.Add(CreateButton(UiText.T("DISK 추천값 넣기", "Use DISK recommendation"), UseRecommendedDisk));
recommendButtons.Controls.Add(CreateButton(UiText.T("설정 탭으로 이동", "Go to setup"), GoToSetup));
root.Controls.Add(recommendButtons, 1, 1);
var bottom = new Label();
bottom.Dock = DockStyle.Fill;
bottom.TextAlign = ContentAlignment.MiddleLeft;
bottom.Text = UiText.T("안전장치: 위험 예외 경로는 차단하고, 변경 작업은 먼저 계획을 보여준 뒤 실행합니다.",
"Safety: risky exclusion paths are blocked, and every change shows a plan before execution.");
root.Controls.Add(bottom, 0, 2);
root.SetColumnSpan(bottom, 2);
return page;
}
private TabPage BuildDashboardTab()
{
var page = new TabPage(UiText.T("대시보드", "Dashboard"));
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.Padding = new Padding(12);
root.ColumnCount = 2;
root.RowCount = 2;
root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
root.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 180F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 245F));
root.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
page.Controls.Add(root);
root.Controls.Add(BuildDashboardSummary(), 0, 0);
root.Controls.Add(statusBox, 0, 1);
var buttons = new FlowLayoutPanel();
buttons.Dock = DockStyle.Fill;
buttons.FlowDirection = FlowDirection.TopDown;
buttons.WrapContents = false;
buttons.Controls.Add(CreateButton(UiText.T("새로고침", "Refresh"), RefreshStatus));
buttons.Controls.Add(CreateButton(UiText.T("보고서 복사", "Copy report"), CopyStatus));
buttons.Controls.Add(CreateButton(UiText.T("보고서 내보내기", "Export report"), ExportStatus));
buttons.Controls.Add(CreateButton(UiText.T("UWF 기능 설치", "Install UWF feature"), InstallFeature));
root.Controls.Add(buttons, 1, 0);
root.SetRowSpan(buttons, 2);
return page;
}
private Control BuildDashboardSummary()
{
dashboardLabels.Clear();
var grid = new TableLayoutPanel();
grid.Dock = DockStyle.Fill;
grid.ColumnCount = 4;
grid.RowCount = 8;
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F));
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F));
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
for (int i = 0; i < 7; i++)
{
grid.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
}
grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 16F));
AddDashboardRow(grid, 0, UiText.T("필터 현재", "Filter current"), "FilterCurrent", UiText.T("필터 다음", "Filter next"), "FilterNext");
AddDashboardRow(grid, 1, UiText.T("오버레이 현재", "Overlay current"), "OverlayCurrent", UiText.T("오버레이 다음", "Overlay next"), "OverlayNext");
AddDashboardRow(grid, 2, UiText.T("최대 크기", "Maximum size"), "OverlayMax", UiText.T("사용량", "Consumption"), "OverlayUsage");
AddDashboardRow(grid, 3, UiText.T("남은 공간", "Available space"), "OverlayAvailable", UiText.T("임계값", "Thresholds"), "OverlayThresholds");
AddDashboardRow(grid, 4, UiText.T("보호 볼륨 현재", "Protected volumes now"), "VolumesCurrent", UiText.T("보호 볼륨 다음", "Protected volumes next"), "VolumesNext");
AddDashboardRow(grid, 5, UiText.T("서비스 현재", "Servicing current"), "ServicingCurrent", UiText.T("서비스 다음", "Servicing next"), "ServicingNext");
AddDashboardRow(grid, 6, UiText.T("재부팅 필요", "Reboot needed"), "RebootNeeded", UiText.T("추천 요약", "Recommendation"), "Recommendation");
overlayProgress.Dock = DockStyle.Bottom;
overlayProgress.Height = 12;
grid.Controls.Add(overlayProgress, 0, 7);
grid.SetColumnSpan(overlayProgress, 4);
return grid;
}
private void AddDashboardRow(TableLayoutPanel grid, int row, string leftName, string leftKey, string rightName, string rightKey)
{
AddDashboardCell(grid, row, 0, leftName, true);
AddDashboardCell(grid, row, 1, leftKey, false);
AddDashboardCell(grid, row, 2, rightName, true);
AddDashboardCell(grid, row, 3, rightKey, false);
}
private void AddDashboardCell(TableLayoutPanel grid, int row, int column, string textOrKey, bool header)
{
var label = new Label();
label.Dock = DockStyle.Fill;
label.TextAlign = ContentAlignment.MiddleLeft;
label.AutoEllipsis = true;
label.BorderStyle = BorderStyle.FixedSingle;
label.Padding = new Padding(6, 0, 6, 0);
if (header)
{
label.Text = textOrKey;
label.BackColor = Color.Gainsboro;
label.Font = new Font(Font.FontFamily, 9F, FontStyle.Bold);
}
else
{
label.Text = "-";
label.BackColor = Color.White;
dashboardLabels[textOrKey] = label;
}
grid.Controls.Add(label, column, row);
}
private TabPage BuildSetupTab()
{
var page = new TabPage(UiText.T("설정", "Setup"));
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.Padding = new Padding(16);
root.ColumnCount = 2;
root.RowCount = 8;
root.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 180F));
root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
page.Controls.Add(root);
overlayTypeBox.DropDownStyle = ComboBoxStyle.DropDownList;
overlayTypeBox.Items.Add("RAM");
overlayTypeBox.Items.Add("DISK");
overlayTypeBox.SelectedIndex = 0;
volumeBox.DropDownStyle = ComboBoxStyle.DropDown;
PopulateVolumeChoices();
overlaySizeBox.Minimum = 1024;
overlaySizeBox.Maximum = 1048576;
overlaySizeBox.Value = 4096;
overlaySizeBox.Increment = 1024;
overlaySizeBox.ThousandsSeparator = true;
warningPercentBox.Minimum = 1;
warningPercentBox.Maximum = 98;
warningPercentBox.Value = 80;
criticalPercentBox.Minimum = 2;
criticalPercentBox.Maximum = 99;
criticalPercentBox.Value = 95;
workloadBox.DropDownStyle = ComboBoxStyle.DropDownList;
workloadBox.Items.Clear();
workloadBox.Items.Add(UiText.T("가벼움 - 설정/작은 앱", "Light - settings/small apps"));
workloadBox.Items.Add(UiText.T("보통 - 일반 사용", "Normal - everyday use"));
workloadBox.Items.Add(UiText.T("무거움 - 게임/패치", "Heavy - games/patches"));
workloadBox.SelectedIndex = 1;
AddRow(root, 0, UiText.T("오버레이 유형", "Overlay type"), overlayTypeBox);
AddRow(root, 1, UiText.T("보호 볼륨(복수 선택)", "Protected volumes"), CreateVolumeSelectorControl());
AddRow(root, 2, UiText.T("오버레이 크기(MB)", "Overlay size (MB)"), overlaySizeBox);
AddRow(root, 3, UiText.T("경고 임계값(%)", "Warning threshold (%)"), warningPercentBox);
AddRow(root, 4, UiText.T("위험 임계값(%)", "Critical threshold (%)"), criticalPercentBox);
AddRow(root, 5, UiText.T("사용 강도", "Workload"), workloadBox);
var hint = new Label();
hint.Dock = DockStyle.Fill;
hint.Text = UiText.T("여러 볼륨은 C:,D:처럼 입력할 수 있고, 보호에는 all도 사용할 수 있습니다. 적용 전 변경 계획을 먼저 보여줍니다.",
"Enter multiple volumes like C:,D:. The protect action also supports all. The app will show the plan before applying changes.");
hint.TextAlign = ContentAlignment.MiddleLeft;
root.Controls.Add(hint, 0, 6);
root.SetColumnSpan(hint, 2);
var buttons = new FlowLayoutPanel();
buttons.Dock = DockStyle.Fill;
buttons.FlowDirection = FlowDirection.LeftToRight;
buttons.Controls.Add(CreateButton(UiText.T("RAM 추천값", "RAM recommendation"), UseRecommendedRam));
buttons.Controls.Add(CreateButton(UiText.T("DISK 추천값", "DISK recommendation"), UseRecommendedDisk));
buttons.Controls.Add(CreateButton(UiText.T("설정 계획 적용", "Apply setup plan"), ApplySetup));
buttons.Controls.Add(CreateButton(UiText.T("필터 켜기", "Enable filter"), EnableFilter));
buttons.Controls.Add(CreateButton(UiText.T("필터 끄기", "Disable filter"), DisableFilter));
buttons.Controls.Add(CreateButton(UiText.T("DISK 공간 정리", "Clean DISK space"), CleanupDiskOverlaySpace));
buttons.Controls.Add(CreateButton(UiText.T("완전 끄기", "Full off"), FullDisableUwf));
buttons.Controls.Add(CreateButton(UiText.T("볼륨 보호", "Protect volume"), ProtectVolume));
buttons.Controls.Add(CreateButton(UiText.T("볼륨 보호 해제", "Unprotect volume"), UnprotectVolume));
root.Controls.Add(buttons, 0, 7);
root.SetColumnSpan(buttons, 2);
return page;
}
private Control CreateVolumeSelectorControl()
{
var panel = new TableLayoutPanel();
panel.Width = 520;
panel.Height = 30;
panel.ColumnCount = 2;
panel.RowCount = 1;
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F));
panel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
panel.Margin = new Padding(0);
volumeBox.Dock = DockStyle.Fill;
panel.Controls.Add(volumeBox, 0, 0);
var selectButton = CreateButton(UiText.T("볼륨 선택", "Select volumes"), SelectVolumes);
selectButton.Dock = DockStyle.Fill;
selectButton.Margin = new Padding(6, 0, 0, 0);
panel.Controls.Add(selectButton, 1, 0);
return panel;
}
private void PopulateVolumeChoices()
{
volumeBox.Items.Clear();
AddVolumeChoice("C:");
try
{
var drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
{
if (drives[i].DriveType == DriveType.Fixed || drives[i].DriveType == DriveType.Removable)
{
AddVolumeChoice(drives[i].Name.TrimEnd('\\'));
}
}
}
catch
{
}
AddVolumeChoice("all");
volumeBox.Text = "C:";
}
private void AddVolumeChoice(string volume)
{
if (String.IsNullOrWhiteSpace(volume))
{
return;
}
for (int i = 0; i < volumeBox.Items.Count; i++)
{
if (String.Equals(Convert.ToString(volumeBox.Items[i]), volume, StringComparison.OrdinalIgnoreCase))
{
return;
}
}
volumeBox.Items.Add(volume);
}
private void SelectVolumes()
{
using (var dialog = new VolumeSelectionDialog(GetSelectableVolumes(), volumeBox.Text))
{
if (dialog.ShowDialog(this) == DialogResult.OK)
{
volumeBox.Text = dialog.SelectedText;
AppendLog(UiText.T("보호 볼륨 선택: ", "Selected protected volumes: ") + dialog.SelectedText);
}
}
}
private List<string> GetSelectableVolumes()
{
var volumes = new List<string>();
AddSelectableVolume(volumes, "C:");
try
{
var drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
{
if (drives[i].DriveType == DriveType.Fixed || drives[i].DriveType == DriveType.Removable)
{
AddSelectableVolume(volumes, drives[i].Name.TrimEnd('\\'));
}
}
}
catch
{
}
VolumeSelection current;
string error;
if (VolumeSelectionParser.TryParse(volumeBox.Text, true, out current, out error) && current != null && !current.IsAll)
{
for (int i = 0; i < current.Volumes.Count; i++)
{
AddSelectableVolume(volumes, current.Volumes[i]);
}
}
return volumes;
}
private static void AddSelectableVolume(List<string> volumes, string volume)
{
if (String.IsNullOrWhiteSpace(volume))
{
return;
}
for (int i = 0; i < volumes.Count; i++)
{
if (String.Equals(volumes[i], volume, StringComparison.OrdinalIgnoreCase))
{
return;
}
}
volumes.Add(volume);
}
private TabPage BuildExclusionsTab()
{
var page = new TabPage(UiText.T("예외", "Exclusions"));
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.Padding = new Padding(16);
root.ColumnCount = 2;
root.RowCount = 5;
root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 28F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 132F));
root.RowStyles.Add(new RowStyle(SizeType.Absolute, 28F));
root.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
page.Controls.Add(root);
root.Controls.Add(CreateSectionLabel(UiText.T("폴더/파일 예외", "Folder or file exclusion")), 0, 0);
fileExclusionBox.Dock = DockStyle.Fill;
fileExclusionBox.PlaceholderTextSafe(UiText.T("예: C:\\ProgramData\\Vendor\\Settings", "Example: C:\\ProgramData\\Vendor\\Settings"));
root.Controls.Add(fileExclusionBox, 0, 1);
var fileButtons = CreateExclusionButtonGrid();
AddExclusionButton(fileButtons, 0, 0, UiText.T("파일 선택", "Select file"), SelectFileExclusionFile);
AddExclusionButton(fileButtons, 1, 0, UiText.T("폴더 선택", "Select folder"), SelectFileExclusionFolder);
AddExclusionButton(fileButtons, 2, 0, UiText.T("폴더/파일 예외 추가", "Add folder/file exclusion"), AddFileExclusion);
AddExclusionButton(fileButtons, 0, 1, UiText.T("입력값 제거", "Remove typed"), RemoveFileExclusion);
AddExclusionButton(fileButtons, 1, 1, UiText.T("선택 사용", "Use selected"), UseSelectedFileExclusion);
AddExclusionButton(fileButtons, 2, 1, UiText.T("선택 제거", "Remove selected"), RemoveSelectedFileExclusion);
AddExclusionButton(fileButtons, 0, 2, UiText.T("목록 새로고침", "Refresh list"), RefreshExclusionsOnly);
root.Controls.Add(fileButtons, 0, 2);
ConfigureSectionLabel(fileExclusionListLabel, UiText.T("현재 폴더/파일 예외", "Current folder/file exclusions"));
root.Controls.Add(fileExclusionListLabel, 0, 3);
ConfigureExclusionListBox(fileExclusionListBox);
root.Controls.Add(fileExclusionListBox, 0, 4);
root.Controls.Add(CreateSectionLabel(UiText.T("레지스트리 예외", "Registry exclusion")), 1, 0);
registryExclusionBox.Dock = DockStyle.Fill;
registryExclusionBox.PlaceholderTextSafe(UiText.T("예: HKLM\\SOFTWARE\\Vendor\\Product", "Example: HKLM\\SOFTWARE\\Vendor\\Product"));
root.Controls.Add(registryExclusionBox, 1, 1);
var regButtons = CreateExclusionButtonGrid();
AddExclusionButton(regButtons, 0, 0, UiText.T("레지스트리 예외 추가", "Add registry exclusion"), AddRegistryExclusion);
AddExclusionButton(regButtons, 1, 0, UiText.T("입력값 제거", "Remove typed"), RemoveRegistryExclusion);
AddExclusionButton(regButtons, 2, 0, UiText.T("선택 사용", "Use selected"), UseSelectedRegistryExclusion);
AddExclusionButton(regButtons, 0, 1, UiText.T("선택 제거", "Remove selected"), RemoveSelectedRegistryExclusion);
AddExclusionButton(regButtons, 1, 1, UiText.T("목록 새로고침", "Refresh list"), RefreshExclusionsOnly);
AddExclusionButton(regButtons, 2, 1, UiText.T("예시 넣기", "Fill example"), FillRegistryExample);
root.Controls.Add(regButtons, 1, 2);
ConfigureSectionLabel(registryExclusionListLabel, UiText.T("현재 레지스트리 예외", "Current registry exclusions"));
root.Controls.Add(registryExclusionListLabel, 1, 3);
ConfigureExclusionListBox(registryExclusionListBox);
root.Controls.Add(registryExclusionListBox, 1, 4);
return page;
}
private TableLayoutPanel CreateExclusionButtonGrid()
{
var grid = new TableLayoutPanel();
grid.Dock = DockStyle.Fill;
grid.ColumnCount = 3;
grid.RowCount = 3;
grid.Margin = new Padding(0, 4, 0, 4);
for (int i = 0; i < 3; i++)
{
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F));
grid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.333F));
}
return grid;
}
private void AddExclusionButton(TableLayoutPanel grid, int column, int row, string text, Action action)
{
var button = CreateButton(text, action);
button.Dock = DockStyle.Fill;
button.AutoSize = false;
button.MinimumSize = Size.Empty;
button.Margin = new Padding(3);
grid.Controls.Add(button, column, row);
}
private TabPage BuildAdvancedTab()
{
var page = new TabPage(UiText.T("고급", "Advanced"));
var root = new TableLayoutPanel();
root.Dock = DockStyle.Fill;
root.Padding = new Padding(16);
root.ColumnCount = 1;
root.RowCount = 10;
page.Controls.Add(root);
root.Controls.Add(CreateSectionLabel(UiText.T("오버레이의 파일 변경을 보호 볼륨에 커밋", "Commit a file from overlay to the protected volume")), 0, 0);
commitFileBox.Dock = DockStyle.Fill;
commitFileBox.PlaceholderTextSafe(UiText.T("예: C:\\Path\\file.ini", "Example: C:\\Path\\file.ini"));
root.Controls.Add(commitFileBox, 0, 1);
var fileCommitButtons = new FlowLayoutPanel();
fileCommitButtons.Controls.Add(CreateButton(UiText.T("파일 커밋", "Commit file"), CommitFile));
fileCommitButtons.Controls.Add(CreateButton(UiText.T("파일 삭제 커밋", "Commit file deletion"), CommitFileDeletion));
root.Controls.Add(fileCommitButtons, 0, 2);
root.Controls.Add(CreateSectionLabel(UiText.T("레지스트리 키/값 커밋", "Commit a registry key/value")), 0, 3);
commitRegistryKeyBox.Dock = DockStyle.Fill;
commitRegistryKeyBox.PlaceholderTextSafe(UiText.T("예: HKLM\\SOFTWARE\\Vendor\\Product", "Example: HKLM\\SOFTWARE\\Vendor\\Product"));
root.Controls.Add(commitRegistryKeyBox, 0, 4);
commitRegistryValueBox.Dock = DockStyle.Fill;
commitRegistryValueBox.PlaceholderTextSafe(UiText.T("선택 값 이름. 비워두면 키를 커밋합니다.", "Optional value name. Leave blank to commit the key."));
root.Controls.Add(commitRegistryValueBox, 0, 5);
var regCommitButtons = new FlowLayoutPanel();
regCommitButtons.Controls.Add(CreateButton(UiText.T("레지스트리 커밋", "Commit registry"), CommitRegistry));
regCommitButtons.Controls.Add(CreateButton(UiText.T("레지스트리 삭제 커밋", "Commit registry deletion"), CommitRegistryDeletion));
root.Controls.Add(regCommitButtons, 0, 6);
root.Controls.Add(CreateSectionLabel(UiText.T("서비스 모드 및 복구", "Servicing and recovery")), 0, 7);
var recoveryButtons = new FlowLayoutPanel();
recoveryButtons.Dock = DockStyle.Fill;
recoveryButtons.Controls.Add(CreateButton(UiText.T("서비스 모드 켜기", "Enable servicing"), EnableServicing));
recoveryButtons.Controls.Add(CreateButton(UiText.T("서비스 모드 끄기", "Disable servicing"), DisableServicing));
recoveryButtons.Controls.Add(CreateButton(UiText.T("Windows 업데이트", "Update Windows"), UpdateWindows));
recoveryButtons.Controls.Add(CreateButton(UiText.T("UWF 설정 초기화", "Reset UWF settings"), ResetSettings));
recoveryButtons.Controls.Add(CreateButton(UiText.T("DISK 오버레이 공간 정리", "Clean DISK overlay space"), CleanupDiskOverlaySpace));
recoveryButtons.Controls.Add(CreateButton(UiText.T("UWF 완전 끄기", "UWF full off"), FullDisableUwf));
recoveryButtons.Controls.Add(CreateButton(UiText.T("UWF 완전 초기화", "UWF full reset"), FullResetUwf));
recoveryButtons.Controls.Add(CreateButton(UiText.T("안전 재시작", "Safe restart"), SafeRestart));
recoveryButtons.Controls.Add(CreateButton(UiText.T("안전 종료", "Safe shutdown"), SafeShutdown));
root.Controls.Add(recoveryButtons, 0, 8);
var note = new Label();
note.Dock = DockStyle.Fill;
note.Text = UiText.T("고급 작업은 변경을 영구 커밋하거나 장치를 재시작할 수 있습니다. 각 계획을 반드시 확인하세요.",
"Advanced operations can permanently commit changes or restart the device. Review each plan carefully.");
note.TextAlign = ContentAlignment.MiddleLeft;
root.Controls.Add(note, 0, 9);
return page;
}
private static Label CreateBadgeLabel()
{
var label = new Label();
label.Dock = DockStyle.Fill;
label.TextAlign = ContentAlignment.MiddleCenter;
label.BorderStyle = BorderStyle.FixedSingle;
label.AutoEllipsis = true;
return label;
}
private static Label CreateSectionLabel(string text)
{
var label = new Label();
ConfigureSectionLabel(label, text);
return label;
}
private static void ConfigureSectionLabel(Label label, string text)
{
label.Text = text;
label.Dock = DockStyle.Fill;
label.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, 9F, FontStyle.Bold);
label.TextAlign = ContentAlignment.MiddleLeft;
}
private static void ConfigureExclusionListBox(ListBox box)
{
box.Dock = DockStyle.Fill;
box.HorizontalScrollbar = true;
box.IntegralHeight = false;
box.Font = new Font("Consolas", 9F);
}
private static TextBox CreateMultilineBox(bool readOnly)
{
var box = new TextBox();
box.Dock = DockStyle.Fill;
box.Multiline = true;
box.ScrollBars = ScrollBars.Both;
box.WordWrap = false;
box.ReadOnly = readOnly;
box.Font = new Font("Consolas", 9F);
return box;
}
private static TextBox CreateGuideBox(string text)
{
var box = new TextBox();
box.Dock = DockStyle.Fill;
box.Multiline = true;
box.ScrollBars = ScrollBars.Vertical;
box.WordWrap = true;
box.ReadOnly = true;
box.BackColor = SystemColors.Window;
box.Font = new Font("Segoe UI", 10F);
box.Text = text;
return box;
}
private Button CreateButton(string text, Action action)
{
var button = new Button();
button.Text = text;
button.AutoSize = true;
button.AutoSizeMode = AutoSizeMode.GrowAndShrink;
button.MinimumSize = new Size(150, 30);
button.Margin = new Padding(4);
button.Click += delegate { action(); };
helpTip.SetToolTip(button, text);
return button;
}
private static void AddRow(TableLayoutPanel table, int row, string labelText, Control control)
{
var label = new Label();
label.Text = labelText;
label.Dock = DockStyle.Fill;
label.TextAlign = ContentAlignment.MiddleLeft;
table.Controls.Add(label, 0, row);
control.Dock = DockStyle.Left;
control.Width = Math.Max(control.Width, 320);
table.Controls.Add(control, 1, row);
}
private void RefreshStatus()
{
var status = controller.GetStatus();
adminLabel.Text = status.IsAdministrator ? UiText.T("관리자: 예", "Administrator: yes") : UiText.T("관리자: 아니오", "Administrator: no");
adminLabel.BackColor = status.IsAdministrator ? Color.Honeydew : Color.MistyRose;
uwfLabel.Text = status.UwfToolExists ? UiText.T("uwfmgr.exe: 있음", "uwfmgr.exe: found") : UiText.T("uwfmgr.exe: 없음", "uwfmgr.exe: missing");
uwfLabel.BackColor = status.UwfToolExists ? Color.Honeydew : Color.MistyRose;
osLabel.Text = status.OsCaption;
osLabel.BackColor = status.IsLikelySupportedEdition ? Color.Honeydew : Color.LemonChiffon;
UpdateDashboard(status);
UpdateExclusionLists(status == null ? null : status.Snapshot);
statusBox.Text = status.Report;
AppendLog(UiText.T("상태를 새로고침했습니다.", "Status refreshed."));
}
private void UpdateDashboard(UwfStatus status)
{
if (status == null || status.Snapshot == null)
{
SetDashboard("FilterCurrent", "-");
return;
}
var snapshot = status.Snapshot;
SetDashboard("FilterCurrent", FormatBool(snapshot.FilterCurrentEnabled));
SetDashboard("FilterNext", FormatBool(snapshot.FilterNextEnabled));
SetDashboard("OverlayCurrent", snapshot.CurrentOverlayType);
SetDashboard("OverlayNext", snapshot.NextOverlayType);
SetDashboard("OverlayMax", FormatPairMb(snapshot.CurrentMaximumSizeMb, snapshot.NextMaximumSizeMb));
SetDashboard("OverlayUsage", FormatMb(snapshot.OverlayConsumptionMb) + " (" + snapshot.GetOverlayUsagePercentText() + ")");
SetDashboard("OverlayAvailable", FormatMb(snapshot.AvailableSpaceMb));
SetDashboard("OverlayThresholds", UiText.T("경고 ", "Warn ") + FormatMb(snapshot.WarningThresholdMb) + " / " + UiText.T("위험 ", "Crit ") + FormatMb(snapshot.CriticalThresholdMb));
SetDashboard("VolumesCurrent", snapshot.CurrentProtectedVolumesText());
SetDashboard("VolumesNext", snapshot.NextProtectedVolumesText());
SetDashboard("ServicingCurrent", FormatBool(snapshot.ServicingCurrentEnabled));
SetDashboard("ServicingNext", FormatBool(snapshot.ServicingNextEnabled));
SetDashboard("RebootNeeded", snapshot.HasPendingChanges() ? UiText.T("예 - 다음 세션 변경 있음", "Yes - next-session changes") : UiText.T("아니오", "No"));
long ramMb = SystemSizing.GetTotalPhysicalMemoryMb();
long freeMb = SystemSizing.GetFreeSpaceMb(GetSizingVolume(volumeBox.Text));
var profile = GetSelectedWorkloadProfile();
int ramReco = SizingRules.RecommendRamOverlayMb(ramMb, profile);
int diskReco = SizingRules.RecommendDiskOverlayMb(freeMb, profile);
SetDashboard("Recommendation", "RAM " + ramReco.ToString() + " MB / DISK " + diskReco.ToString() + " MB");
int percent = snapshot.GetOverlayUsagePercent();
overlayProgress.Value = Math.Max(0, Math.Min(100, percent));
}
private void UpdateExclusionLists(UwfSnapshot snapshot)
{
var files = snapshot == null ? null : snapshot.FileExclusions;
var registryKeys = snapshot == null ? null : snapshot.RegistryExclusions;
FillListBox(fileExclusionListBox, files);
FillListBox(registryExclusionListBox, registryKeys);
ConfigureSectionLabel(fileExclusionListLabel,
UiText.T("현재 폴더/파일 예외", "Current folder/file exclusions") + " (" + CountItems(files).ToString() + ")");
ConfigureSectionLabel(registryExclusionListLabel,
UiText.T("현재 레지스트리 예외", "Current registry exclusions") + " (" + CountItems(registryKeys).ToString() + ")");
}
private static int CountItems(IList<string> values)
{
return values == null ? 0 : values.Count;
}
private static void FillListBox(ListBox box, IList<string> values)
{
if (box == null)
{
return;
}