Skip to content

Commit 603e6cd

Browse files
committed
Added duplicate policy option for policies library
You can now duplicate a policy in the library by right-clicking on it and selecting "Duplicate Policy". AppControl Manager
1 parent 74aa9b6 commit 603e6cd

6 files changed

Lines changed: 59 additions & 8 deletions

File tree

AppControl Manager/MainWindow.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,12 @@
607607
</MenuFlyoutItem.Icon>
608608
</MenuFlyoutItem>
609609

610+
<MenuFlyoutItem x:Uid="DuplicatePolicyMenuFlyoutItem" Click="OnDuplicatePolicy" DataContext="{x:Bind}">
611+
<MenuFlyoutItem.Icon>
612+
<FontIcon Glyph="&#xF584;" />
613+
</MenuFlyoutItem.Icon>
614+
</MenuFlyoutItem>
615+
610616
<MenuFlyoutSubItem x:Uid="SetColorMenuFlyoutSubItem">
611617
<MenuFlyoutSubItem.Icon>
612618
<FontIcon Glyph="&#xE8EC;" />

AppControl Manager/MainWindow.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,6 @@ private async void OnSetPolicyColorClicked(object sender, RoutedEventArgs e)
16761676
if (string.Equals(colorTag, "Transparent", StringComparison.OrdinalIgnoreCase))
16771677
{
16781678
policyContext.TagColorBrush = new SolidColorBrush(Colors.Transparent);
1679-
policyContext.IsTagVisible = Visibility.Collapsed;
16801679
await ViewModel.UpdatePolicyColorAsync(policyContext.UniqueObjID, "Transparent");
16811680
}
16821681
// For Custom colors from the picker
@@ -1717,7 +1716,6 @@ private async void OnSetPolicyColorClicked(object sender, RoutedEventArgs e)
17171716
{
17181717
Windows.UI.Color selectedColor = picker.Color;
17191718
policyContext.TagColorBrush = new SolidColorBrush(selectedColor);
1720-
policyContext.IsTagVisible = Visibility.Visible;
17211719

17221720
string hexColor = $"#{selectedColor.A:X2}{selectedColor.R:X2}{selectedColor.G:X2}{selectedColor.B:X2}";
17231721
await ViewModel.UpdatePolicyColorAsync(policyContext.UniqueObjID, hexColor);
@@ -1728,7 +1726,6 @@ private async void OnSetPolicyColorClicked(object sender, RoutedEventArgs e)
17281726
{
17291727
Windows.UI.Color parsedColor = MainWindowVM.ParseColor(colorTag);
17301728
policyContext.TagColorBrush = new SolidColorBrush(parsedColor);
1731-
policyContext.IsTagVisible = Visibility.Visible;
17321729
await ViewModel.UpdatePolicyColorAsync(policyContext.UniqueObjID, colorTag);
17331730
}
17341731
}
@@ -1875,6 +1872,17 @@ private async void ManageCustomPoliciesLibraryCacheLocation_Click()
18751872
_ = await customDialog.ShowAsync();
18761873
}
18771874

1875+
/// <summary>
1876+
/// Event handler for right-click context menu option for each policy in the library to duplicate it.
1877+
/// </summary>
1878+
private async void OnDuplicatePolicy(object sender, RoutedEventArgs e)
1879+
{
1880+
if (sender is FrameworkElement { DataContext: PolicyFileRepresent policyContext })
1881+
{
1882+
await ViewModel.AssignToSidebar(policyContext.CreateCopy());
1883+
}
1884+
}
1885+
18781886
#endregion
18791887

18801888
#endif

AppControl Manager/ReleaseNotes.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
* Added toggle buttons to the Policies Library on the Sidebar so you can choose to show/hide policies based on their types.
66

7-
* Added a new option in the Policies Library: Contextual Search. You can now click/tap on the magnifier icon in the Policies Library on the Sidebar to enable contextual search which allows you to not only search among the policies based on their names, types or IDs but also search through every detail that exists in them. This is quite useful when, for instance, you want to find out which policy in the Sidebar contains the hash of a particular file or which policy allows or blocks a particular app and other such scenarios.
8-
97
* Improves policy creation and fixes the following issue: https://github.com/HotCakeX/Harden-Windows-Security/issues/1093
108

119
* You can now view the size of each policy in the Policies Library on the Sidebar.
@@ -15,3 +13,5 @@
1513
* You can now cancel the simulation process that you start in the Simulation page. The button has been changed to a cancellable version.
1614

1715
* You can now cancel the event log scan that you start in the event logs page. The button has been changed to a cancellable version.
16+
17+
* You can now duplicate a policy in the library by right-clicking on it and selecting "Duplicate Policy".

AppControl Manager/SiPolicy/PolicyFileRepresent.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
using System.Text.Json.Serialization;
2222
using System.Threading.Tasks;
2323
using AppControlManager.XMLOps;
24+
using Microsoft.UI;
2425
using Microsoft.UI.Xaml;
2526
using Microsoft.UI.Xaml.Media;
2627
using Windows.System;
28+
using Windows.UI;
2729

2830
namespace AppControlManager.SiPolicy;
2931

@@ -68,12 +70,28 @@ internal SiPolicy PolicyObj
6870
/// <summary>
6971
/// The brush used to display the policy color tag indicator.
7072
/// </summary>
71-
internal SolidColorBrush? TagColorBrush { get; set => SP(ref field, value); }
73+
internal SolidColorBrush? TagColorBrush
74+
{
75+
get; set
76+
{
77+
if (SP(ref field, value))
78+
{
79+
if (field is null)
80+
{
81+
IsTagVisible = Visibility.Collapsed;
82+
}
83+
else
84+
{
85+
IsTagVisible = field.Color == Colors.Transparent ? Visibility.Collapsed : Visibility.Visible;
86+
}
87+
}
88+
}
89+
}
7290

7391
/// <summary>
7492
/// The visibility of the policy color tag indicator.
7593
/// </summary>
76-
internal Visibility IsTagVisible { get; set => SP(ref field, value); } = Visibility.Collapsed;
94+
internal Visibility IsTagVisible { get; private set => SP(ref field, value); } = Visibility.Collapsed;
7795

7896
/// <summary>
7997
/// Helper method to generate the identifier string.
@@ -110,6 +128,16 @@ internal SiPolicy PolicyObj
110128
/// <returns></returns>
111129
public override string ToString() => PolicyIdentifier;
112130

131+
/// <summary>
132+
/// Creates a Deep/Full copy of the current policy.
133+
/// </summary>
134+
internal PolicyFileRepresent CreateCopy() => new(policyObj: PolicyObj, kind: kind)
135+
{
136+
FilePath = FilePath,
137+
FileName = FileName,
138+
FileSize = FileSize
139+
};
140+
113141
/// <summary>
114142
/// Accepts a policy file representation, offers a save dialog so user can save it somewhere,
115143
/// Then opens the file in the default file handler in the OS.

AppControl Manager/Strings/en-US/Resources.resw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7241,4 +7241,14 @@ NOTE: This option is always enforced if any App Control UMCI policy enables it.
72417241
<data name="PoliciesLibraryContextualSearchToggleMenuFlyoutItem.AutomationProperties.HelpText" xml:space="preserve">
72427242
<value>Search through the contents of all policies.</value>
72437243
</data>
7244+
<!--NEW-->
7245+
<data name="DuplicatePolicyMenuFlyoutItem.Text" xml:space="preserve">
7246+
<value>Duplicate Policy</value>
7247+
</data>
7248+
<data name="DuplicatePolicyMenuFlyoutItem.ToolTipService.ToolTip" xml:space="preserve">
7249+
<value>Duplicate the policy by creating a copy of it in the library.</value>
7250+
</data>
7251+
<data name="DuplicatePolicyMenuFlyoutItem.AutomationProperties.HelpText" xml:space="preserve">
7252+
<value>Duplicate the policy by creating a copy of it in the library.</value>
7253+
</data>
72447254
</root>

AppControl Manager/ViewModels/MainWindowVM.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ await Atlas.AppDispatcher.EnqueueAsync(() =>
695695
if (parsedColor != Colors.Transparent)
696696
{
697697
policyToAdd.TagColorBrush = new SolidColorBrush(parsedColor);
698-
policyToAdd.IsTagVisible = Visibility.Visible;
699698
}
700699
}
701700

0 commit comments

Comments
 (0)