diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b5fbae..dcaef3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ ## [Unreleased] +## [3.0.5-beta] - 2023-08-21 + +### Fixed + +* Options window should always enable OK and Cancel buttons (#74) +* Fixed issue with deleting scheduled task after it's been disabled in options (#97) + +## [3.0.4-beta] - 2023-08-19 + +### Fixed + +* Task Scheduler and Options fixes by @DavidMoore in https://github.com/DavidMoore/ipfilter/pull/95 + - Renamed "Save Settings" button in Options to "OK", and it automatically closes the window after saving (#74) + - Scheduled task should be created or deleted according to the chosen option (#72) +* The status / error message should auto-size to fit in the window (#67) +* Corrected the URL in Add/Remove Programs entry + ## [3.0.3-beta] - 2023-08-18 ### Changed @@ -39,7 +56,9 @@ ## [3.0.1.4-beta] -[Unreleased]: https://github.com/DavidMoore/ipfilter/compare/3.0.3-beta...HEAD +[Unreleased]: https://github.com/DavidMoore/ipfilter/compare/3.0.5-beta...HEAD +[3.0.5-beta]: https://github.com/DavidMoore/ipfilter/compare/3.0.4-beta...3.0.5-beta +[3.0.4-beta]: https://github.com/DavidMoore/ipfilter/compare/3.0.3-beta...3.0.4-beta [3.0.3-beta]: https://github.com/DavidMoore/ipfilter/compare/3.0.2.9-beta...3.0.3-beta [3.0.2.9-beta]: https://github.com/DavidMoore/ipfilter/compare/3.0.2.7-beta...3.0.2.9-beta [3.0.2.7-beta]: https://github.com/DavidMoore/ipfilter/compare/3.0.2.4-beta...3.0.2.7-beta diff --git a/Code/IPFilter/Commands/ScheduledTaskCommand.cs b/Code/IPFilter/Commands/ScheduledTaskCommand.cs index 921fddd..f353512 100644 --- a/Code/IPFilter/Commands/ScheduledTaskCommand.cs +++ b/Code/IPFilter/Commands/ScheduledTaskCommand.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.IO; namespace IPFilter.Commands { @@ -69,57 +70,58 @@ public static void Execute(bool enable) if(!enable) { Trace.TraceInformation("Deleting the automatic schedule task..."); - var folder = service.GetFolder("\\"); - var existingTask = folder.GetTask(taskPath); - if (existingTask != null) + var rootFolder = service.GetFolder("\\"); + + try { + var existingTask = rootFolder.GetTask(taskPath); existingTask.Enabled = false; existingTask.Stop(0); - folder.DeleteTask(taskPath, 0); + rootFolder.DeleteTask(taskPath, 0); Trace.TraceInformation("Successfully deleted the scheduled task."); - return; } - Trace.TraceInformation("No task found to delete."); + catch (FileNotFoundException) + { + Trace.TraceInformation("No task found to delete."); + } return; } Trace.TraceInformation("Setting up the automatic schedule..."); var task = service.NewTask(0); - //using (var task = service.NewTask()) - { - task.RegistrationInfo.Description = "Updates the IP Filter for bit torrent clients"; + + task.RegistrationInfo.Description = "Updates the IP Filter for bit torrent clients"; - task.Triggers.Clear(); + task.Triggers.Clear(); - // Schedule to run daily at 4am - var now = DateTime.Now.AddDays(-1); - var date = new DateTime(now.Year, now.Month, now.Day, 4, 0, 0); + // Schedule to run daily at 4am + var now = DateTime.Now.AddDays(-1); + var date = new DateTime(now.Year, now.Month, now.Day, 4, 0, 0); - var trigger = task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY); - trigger.DaysInterval = 1; - trigger.StartBoundary = date.ToString("s"); - trigger.RandomDelay = "PT15M"; // Delay randomly by 15 minutes to stagger the amount of requests hitting list servers + var trigger = task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY); + trigger.DaysInterval = 1; + trigger.StartBoundary = date.ToString("s"); + trigger.RandomDelay = "PT15M"; // Delay randomly by 15 minutes to stagger the amount of requests hitting list servers - // Execute silently - //var action = (IExecAction) task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); - var action = task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); - action.Path = Process.GetCurrentProcess().MainModule.FileName; - action.Arguments = "/silent"; + // Execute silently + //var action = (IExecAction) task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); + var action = task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); + action.Path = Process.GetCurrentProcess().MainModule.FileName; + action.Arguments = "/silent"; - task.Settings.RunOnlyIfNetworkAvailable = true; - task.Settings.StartWhenAvailable = true; - task.Settings.WakeToRun = false; - task.Settings.Enabled = true; + task.Settings.RunOnlyIfNetworkAvailable = true; + task.Settings.StartWhenAvailable = true; + task.Settings.WakeToRun = false; + task.Settings.Enabled = true; - task.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_LUA; - task.Principal.LogonType = _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN; - //task.Principal.UserId = identity.Name; + task.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_LUA; + task.Principal.LogonType = _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN; + //task.Principal.UserId = identity.Name; - var folder = service.GetFolder("\\"); + var folder = service.GetFolder("\\"); - var registered = folder.RegisterTaskDefinition(taskPath, task, (int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, null,null,_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN); - Trace.TraceInformation("Finished creating / updating scheduled task"); - } + var registered = folder.RegisterTaskDefinition(taskPath, task, (int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, null,null,_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN); + Trace.TraceInformation("Finished creating / updating scheduled task"); } } } \ No newline at end of file diff --git a/Code/IPFilter/ViewModels/OptionsViewModel.cs b/Code/IPFilter/ViewModels/OptionsViewModel.cs index b2b48ab..0b48e96 100644 --- a/Code/IPFilter/ViewModels/OptionsViewModel.cs +++ b/Code/IPFilter/ViewModels/OptionsViewModel.cs @@ -57,22 +57,34 @@ void LoadSettings() bool CanResetSettings(object o) { - return PendingChanges; + return true; } void ResetSettings(object o) { Config.Reload(); LoadSettings(); + if (o is not Window window) return; + window.Close(); } bool CanSaveSettings(object o) { - return PendingChanges; + return true; } void SaveSettings(object o) { + var window = o as Window; + + // Just close the dialog if we haven't changed settings + if (!PendingChanges) + { + if (window == null) return; + window.Close(); + return; + } + ErrorMessage = string.Empty; try @@ -116,8 +128,7 @@ void SaveSettings(object o) return; } - if (o is not Window window) return; - window.Close(); + window?.Close(); } public DelegateCommand SaveSettingsCommand { get; private set; } diff --git a/Code/IPFilter/Views/OptionsWindow.xaml b/Code/IPFilter/Views/OptionsWindow.xaml index 132cb38..713e6de 100644 --- a/Code/IPFilter/Views/OptionsWindow.xaml +++ b/Code/IPFilter/Views/OptionsWindow.xaml @@ -18,14 +18,14 @@ - +