Skip to content

Commit

Permalink
Make Windows Defender Autofix preference names more expressive
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Feb 17, 2024
1 parent 7d3801b commit 6d495fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
@Component(service = EventHandler.class)
@EventTopics(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE)
public class WindowsDefenderConfigurator implements EventHandler {
private static final String WINDOWS_DEFENDER_EXCLUDED_INSTALLATION_PATH = "windows.defender.excluded.path"; //$NON-NLS-1$
public static final String PREFERENCE_SKIP = "windows.defender.check.skip"; //$NON-NLS-1$
public static final boolean PREFERENCE_SKIP_DEFAULT = false;
private static final String PREFERENCE_EXCLUDED_INSTALLATION_PATH = "windows.defender.excluded.path"; //$NON-NLS-1$
public static final String PREFERENCE_STARTUP_CHECK_SKIP = "windows.defender.startup.check.skip"; //$NON-NLS-1$
public static final boolean PREFERENCE_STARTUP_CHECK_SKIP_DEFAULT = false;

@Reference
private IPreferencesService preferences;
Expand All @@ -87,13 +87,14 @@ public void handleEvent(Event event) {
if (runStartupCheck()) {
Job job = Job.create(WorkbenchMessages.WindowsDefenderConfigurator_statusCheck, m -> {
SubMonitor monitor = SubMonitor.convert(m, 10);
if (preferences.getBoolean(PI_WORKBENCH, PREFERENCE_SKIP, PREFERENCE_SKIP_DEFAULT, null)) {
if (preferences.getBoolean(PI_WORKBENCH, PREFERENCE_STARTUP_CHECK_SKIP,
PREFERENCE_STARTUP_CHECK_SKIP_DEFAULT, null)) {
return;
}
Optional<Path> installLocation = getInstallationLocation();
if (installLocation.isPresent()) {
String checkedPath = getPreference(ConfigurationScope.INSTANCE)
.get(WINDOWS_DEFENDER_EXCLUDED_INSTALLATION_PATH, ""); //$NON-NLS-1$
.get(PREFERENCE_EXCLUDED_INSTALLATION_PATH, ""); //$NON-NLS-1$
if (!checkedPath.isBlank() && installLocation.get().equals(Path.of(checkedPath))) {
return; // This installation has already been checked at the current location
}
Expand Down Expand Up @@ -156,15 +157,16 @@ private static Boolean runExclusionCheck(IProgressMonitor m, Optional<Path> inst
case EXECUTE_EXCLUSION -> {
try {
WindowsDefenderConfigurator.excludeDirectoryFromScanning(monitor.split(2));
savePreference(ConfigurationScope.INSTANCE, WINDOWS_DEFENDER_EXCLUDED_INSTALLATION_PATH,
savePreference(ConfigurationScope.INSTANCE, PREFERENCE_EXCLUDED_INSTALLATION_PATH,
installLocation.map(Path::toString).orElse("")); //$NON-NLS-1$
} catch (IOException e) {
PlatformUI.getWorkbench().getDisplay()
.syncExec(() -> MessageDialog.openError(null, "Exclusion failed", //$NON-NLS-1$
bindProductName(WorkbenchMessages.WindowsDefenderConfigurator_exclusionFailed)));
}
}
case IGNORE_THIS_INSTALLATION -> savePreference(ConfigurationScope.INSTANCE, PREFERENCE_SKIP, "true"); //$NON-NLS-1$
case IGNORE_THIS_INSTALLATION -> savePreference(ConfigurationScope.INSTANCE, PREFERENCE_STARTUP_CHECK_SKIP,
"true"); //$NON-NLS-1$
}
}
return decision == HandlingOption.EXECUTE_EXCLUSION ? Boolean.TRUE : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;

import static org.eclipse.ui.internal.WindowsDefenderConfigurator.PREFERENCE_STARTUP_CHECK_SKIP;
import static org.eclipse.ui.internal.WindowsDefenderConfigurator.PREFERENCE_STARTUP_CHECK_SKIP_DEFAULT;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -198,8 +201,7 @@ private void updateCheckState() {
private void updateWindowsDefenderHandlingOptions() {
windowsDefenderIgnore.forEach((scope, button) -> {
IEclipsePreferences node = WindowsDefenderConfigurator.getPreference(scope);
boolean ignore = node.getBoolean(WindowsDefenderConfigurator.PREFERENCE_SKIP,
WindowsDefenderConfigurator.PREFERENCE_SKIP_DEFAULT);
boolean ignore = node.getBoolean(PREFERENCE_STARTUP_CHECK_SKIP, PREFERENCE_STARTUP_CHECK_SKIP_DEFAULT);
button.setSelection(ignore);
});
}
Expand All @@ -214,8 +216,7 @@ protected void performDefaults() {
IPreferenceStore store = PrefUtil.getInternalPreferenceStore();
store.setToDefault(IPreferenceConstants.PLUGINS_NOT_ACTIVATED_ON_STARTUP);
updateCheckState();
windowsDefenderIgnore.values()
.forEach(b -> b.setSelection(WindowsDefenderConfigurator.PREFERENCE_SKIP_DEFAULT));
windowsDefenderIgnore.values().forEach(b -> b.setSelection(PREFERENCE_STARTUP_CHECK_SKIP_DEFAULT));
updateWindowsDefenderHandlingOptions();
}

Expand All @@ -237,7 +238,7 @@ public boolean performOk() {
windowsDefenderIgnore.forEach((scope, button) -> {
try {
String skip = Boolean.toString(button.getSelection());
WindowsDefenderConfigurator.savePreference(scope, WindowsDefenderConfigurator.PREFERENCE_SKIP, skip);
WindowsDefenderConfigurator.savePreference(scope, PREFERENCE_STARTUP_CHECK_SKIP, skip);
} catch (CoreException e) {
WorkbenchPlugin.log("Failed to save Windows Defender exclusion check preferences", e); //$NON-NLS-1$
}
Expand Down

0 comments on commit 6d495fc

Please sign in to comment.