예제 #1
0
 /// <summary>
 /// Remove specified task
 /// </summary>
 /// <param name="data"></param>
 public static void RemoveTask(ref ClamWinScheduleData data)
 {
     lock (MainLock)
     {
         try
         {
             // Delete task
             tasks.DeleteTask(data.TaskName);
         }
         catch (ArgumentException)
         {
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Show schedule form modally and add caller string to form caption
        /// </summary>
        /// <param name="caller"></param>
        public DialogResult ScheduleDoModal(string caller, ref ClamWinScheduleData data)
        {
            Text = "Schedule: " + caller;

            comboBoxType.SelectedIndex = (int)data.Type;

            #region Apply data values to controls
            switch (data.Type)
            {
            case ClamWinScheduleData.SchedulingTypes.Once:
            {
                dateTimePickerOnce.Value = data.Date;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Minutely:
            {
                numericUpDownMinutely.Value = data.Frequency;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Hourly:
            {
                numericUpDownHourly.Value = data.Frequency;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Daily:
            {
                if (data.DailyType == ClamWinScheduleData.DailyTypes.EveryNDays)
                {
                    radioButtonDailyEveryN.Checked = true;
                }
                else if (data.DailyType == ClamWinScheduleData.DailyTypes.EveryWeekday)
                {
                    radioButtonDailyEveryWeekday.Checked = true;
                }
                else
                {
                    radioButtonDailyEveryWeekend.Checked = true;
                }

                checkBoxDailyUseTime.Checked = data.UseDateTime;

                if (data.UseDateTime)
                {
                    dateTimePickerDaily.Value = data.Date;
                }
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Weekly:
            {
                checkBoxWeeklySu.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Su);
                checkBoxWeeklyMo.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Mo);
                checkBoxWeeklyTu.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Tu);
                checkBoxWeeklyWe.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.We);
                checkBoxWeeklyTh.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Th);
                checkBoxWeeklyFr.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Fr);
                checkBoxWeeklySa.Checked = data.IsDayChecked(ClamWinScheduleData.DaysOfTheWeek.Sa);

                checkBoxWeeklyUseTime.Checked = data.UseDateTime;

                if (data.UseDateTime)
                {
                    try
                    {
                        dateTimePickerWeekly.Value = data.Date;
                    }
                    catch
                    {
                    }
                }
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Monthly:
            {
                numericUpDownMonthlyN.Value    = data.Frequency;
                checkBoxMonthlyUseTime.Checked = data.UseDateTime;
                if (data.UseDateTime)
                {
                    dateTimePickerMonthly.Value = data.Date;
                }
                break;
            }
            }
            #endregion

            DialogResult result = ShowDialog();

            if (result != DialogResult.OK)
            {
                return(result);
            }

            #region Fill data with new values
            data.Type = (ClamWinScheduleData.SchedulingTypes)comboBoxType.SelectedIndex;
            switch (data.Type)
            {
            case ClamWinScheduleData.SchedulingTypes.Once:
            {
                data.Date = dateTimePickerOnce.Value;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Minutely:
            {
                data.Frequency = (int)numericUpDownMinutely.Value;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Hourly:
            {
                data.Frequency = (int)numericUpDownHourly.Value;
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Daily:
            {
                if (radioButtonDailyEveryN.Checked)
                {
                    data.DailyType = ClamWinScheduleData.DailyTypes.EveryNDays;
                    data.Frequency = (int)numericUpDownDailyEveryN.Value;
                }
                else if (radioButtonDailyEveryWeekday.Checked)
                {
                    data.DailyType = ClamWinScheduleData.DailyTypes.EveryWeekday;
                }
                else
                {
                    data.DailyType = ClamWinScheduleData.DailyTypes.EveryWeekend;
                }

                data.UseDateTime = checkBoxDailyUseTime.Checked;

                if (checkBoxDailyUseTime.Checked)
                {
                    data.Date = dateTimePickerDaily.Value;
                }
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Weekly:
            {
                data.Days = ClamWinScheduleData.DaysOfTheWeek.Su |
                            ClamWinScheduleData.DaysOfTheWeek.Mo |
                            ClamWinScheduleData.DaysOfTheWeek.Tu |
                            ClamWinScheduleData.DaysOfTheWeek.We |
                            ClamWinScheduleData.DaysOfTheWeek.Th |
                            ClamWinScheduleData.DaysOfTheWeek.Fr |
                            ClamWinScheduleData.DaysOfTheWeek.Sa;

                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Su, checkBoxWeeklySu.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Mo, checkBoxWeeklyMo.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Tu, checkBoxWeeklyTu.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.We, checkBoxWeeklyWe.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Th, checkBoxWeeklyTh.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Fr, checkBoxWeeklyFr.Checked);
                data.ChangeDay(ClamWinScheduleData.DaysOfTheWeek.Sa, checkBoxWeeklySa.Checked);

                data.UseDateTime = checkBoxWeeklyUseTime.Checked;

                if (checkBoxWeeklyUseTime.Checked)
                {
                    data.Date = dateTimePickerWeekly.Value;
                }
                break;
            }

            case ClamWinScheduleData.SchedulingTypes.Monthly:
            {
                data.Frequency = (int)numericUpDownMonthlyN.Value;

                data.UseDateTime = checkBoxMonthlyUseTime.Checked;

                if (checkBoxMonthlyUseTime.Checked)
                {
                    data.Date = dateTimePickerMonthly.Value;
                }

                break;
            }
            }
            #endregion

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Assign settings values to controls
        /// </summary>
        private void AssignSettingsToControls()
        {
            // Protection panel
            checkBoxEnableProtection.Checked = ClamWinSettings.EnableProtection;
            checkBoxRunAtStartup.Checked     = ClamWinSettings.RunAtStartup;

            // File Antivirus Panel
            checkBoxEnableFA.Checked = ClamWinSettings.OnAccessScannerStatus == ClamWinSettings.OnAccessStatus.Enabled ?
                                       true : false;

            switch (ClamWinSettings.FileAntiVirusOnDetectAction)
            {
            case ClamWinSettings.OnDetectActions.Prompt:
                radioButtonFAPrompt.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.BlockAccess:
                radioButtonFABlock.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.Delete:
                radioButtonFADelete.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.MoveToQuarantine:
                radioButtonFAQuarantine.Checked = true;
                break;
            }

            // Mail Antivirus Panel
            checkBoxMAEnable.Checked = ClamWinSettings.EnableMailAntiVirus;

            // Scan
            switch (ClamWinSettings.ScanOnDetectAction)
            {
            case ClamWinSettings.OnDetectActions.Prompt:
                radioButtonScanPromptDuringScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.PromptAfterScan:
                radioButtonScanPromptAfterScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.Delete:
                radioButtonScanDelete.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.DoNothing:
                radioButtonScanDoNothing.Checked = true;
                break;
            }
            ScanScheduleData              = ClamWinSettings.ScanScheduleData;
            ScanFilterData                = ClamWinSettings.ScanFilterData;
            checkBoxScanSchedule.Checked  = ClamWinSettings.ScanSchedule;
            checkBoxScanSchedule.Text     = ClamWinSettings.ScanScheduleData.GetDescription();
            checkBoxScanUseFilter.Checked = ClamWinSettings.ScanUseFilter;

            // Scan Critical Panel
            switch (ClamWinSettings.ScanCriticalOnDetectAction)
            {
            case ClamWinSettings.OnDetectActions.Prompt:
                radioButtonScanCriticalPromptDuringScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.PromptAfterScan:
                radioButtonScanCriticalPromptAfterScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.Delete:
                radioButtonScanCriticalDelete.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.DoNothing:
                radioButtonScanCriticalDoNothing.Checked = true;
                break;
            }
            ScanCriticalScheduleData             = ClamWinSettings.ScanCriticalScheduleData;
            checkBoxScanCriticalSchedule.Checked = ClamWinSettings.ScanCriticalSchedule;
            checkBoxScanCriticalSchedule.Text    = ClamWinSettings.ScanCriticalScheduleData.GetDescription();
            ScanCriticalFilterData = ClamWinSettings.ScanCriticalFilterData;
            checkBoxScanCriticalUseFilter.Checked = ClamWinSettings.ScanCriticalUseFilter;

            // Scan My PC Panel
            switch (ClamWinSettings.ScanMyPCOnDetectAction)
            {
            case ClamWinSettings.OnDetectActions.Prompt:
                radioButtonScanMyPCPromptDuringScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.PromptAfterScan:
                radioButtonScanMyPCPromptAfterScan.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.Delete:
                radioButtonScanMyPCDelete.Checked = true;
                break;

            case ClamWinSettings.OnDetectActions.DoNothing:
                radioButtonScanMyPCDoNothing.Checked = true;
                break;
            }

            ScanMyPCScheduleData             = ClamWinSettings.ScanMyPCScheduleData;
            checkBoxScanMyPCSchedule.Checked = ClamWinSettings.ScanMyPCSchedule;
            checkBoxScanMyPCSchedule.Text    = ClamWinSettings.ScanMyPCScheduleData.GetDescription();
            ScanMyPCFilterData = ClamWinSettings.ScanMyPCFilterData;
            checkBoxScanMyPCUseFilter.Checked = ClamWinSettings.ScanMyPCUseFilter;

            // Service Panel
            checkBoxEnableNotifications.Checked = ClamWinSettings.EnableNotifications;

            // Update Panel
            UpdateScheduleData = ClamWinSettings.UpdateScheduleData;

            switch (ClamWinSettings.UpdateRunMode)
            {
            case ClamWinSettings.RunModes.Auto:
                radioButtonUpdateAuto.Checked = true;
                break;

            case ClamWinSettings.RunModes.Manual:
                radioButtonUpdateManual.Checked = true;
                break;

            case ClamWinSettings.RunModes.Scheduled:
                radioButtonUpdateEvery.Checked = true;
                break;
            }
            radioButtonUpdateEvery.Text      = UpdateScheduleData.GetDescription();
            checkBoxRescanQuarantine.Checked = ClamWinSettings.RescanQuarantineAfterUpdate;

            // Data Files Panel
            checkBoxKeepOnlyRecent.Checked       = ClamWinSettings.KeepOnlyRecentEvents;
            checkBoxLogNonCritical.Checked       = ClamWinSettings.LogNonCriticalEvents;
            checkBoxDeleteReports.Checked        = ClamWinSettings.DeleteReportsAfterTime;
            checkBoxDeleteFromQuarantine.Checked = ClamWinSettings.DeleteQuarantineItemsAfterTime;

            numericUpDownDeleteReportsDays.Value          = ClamWinSettings.ReportsLifeTime;
            numericUpDownDeleteReportsDays.Enabled        = ClamWinSettings.DeleteReportsAfterTime;
            numericUpDownDeleteFromQuarantineDays.Value   = ClamWinSettings.QuarantineItemsLifeTime;
            numericUpDownDeleteFromQuarantineDays.Enabled = ClamWinSettings.DeleteQuarantineItemsAfterTime;
        }
예제 #4
0
        /// <summary>
        /// Add new task or update existing
        /// </summary>
        /// <param name="?"></param>
        public static void AddTask(ref ClamWinScheduleData data)
        {
            lock (MainLock)
            {
                Task task;

                try
                {
                    // Delete previous task if exists
                    tasks.DeleteTask(data.TaskName);
                    // Create new
                    task = tasks.CreateTask(data.TaskName);
                }
                catch (ArgumentException)
                {
                    return;
                }

                task.ApplicationName = ClamWinPathName;
                task.Parameters      = "-" + data.CmdLineArguments;
                task.Comment         = "ClamWin " + data.Name + ".";
                task.IdleWaitMinutes = 0;
                task.Priority        = System.Diagnostics.ProcessPriorityClass.Normal;

                switch (data.Type)
                {
                case ClamWinScheduleData.SchedulingTypes.Once:
                {
                    task.Triggers.Add(new RunOnceTrigger(data.Date));
                    break;
                }

                case ClamWinScheduleData.SchedulingTypes.Minutely:
                {
                    DateTime date = DateTime.Now;
                    date = date.Add(new TimeSpan(0, data.Frequency, 0));
                    Trigger trigger = new DailyTrigger((short)date.Hour, (short)date.Minute, 1);
                    trigger.DurationMinutes = 24 * 60;
                    trigger.IntervalMinutes = data.Frequency;
                    task.Triggers.Add(trigger);
                    //TODO: no such trigger available currently
                    break;
                }

                case ClamWinScheduleData.SchedulingTypes.Hourly:
                {
                    DateTime date = DateTime.Now;
                    date = date.Add(new TimeSpan(data.Frequency, 0, 0));
                    Trigger trigger = new DailyTrigger((short)date.Hour, (short)date.Minute, 1);
                    trigger.DurationMinutes = 24 * 60;
                    trigger.IntervalMinutes = data.Frequency * 60;
                    task.Triggers.Add(trigger);
                    //TODO: no such trigger available currently
                    break;
                }

                case ClamWinScheduleData.SchedulingTypes.Daily:
                {
                    short hour    = 0;
                    short minutes = 0;

                    if (data.UseDateTime)
                    {
                        hour    = (short)data.Date.Hour;
                        minutes = (short)data.Date.Minute;
                    }

                    switch (data.DailyType)
                    {
                    case ClamWinScheduleData.DailyTypes.EveryNDays:
                    {
                        task.Triggers.Add(new DailyTrigger(hour, minutes, (short)data.Frequency));
                        break;
                    }

                    case ClamWinScheduleData.DailyTypes.EveryWeekday:
                    {
                        task.Triggers.Add(new DailyTrigger(hour, minutes));
                        break;
                    }

                    case ClamWinScheduleData.DailyTypes.EveryWeekend:
                    {
                        task.Triggers.Add(new WeeklyTrigger(hour, minutes, DaysOfTheWeek.Saturday | DaysOfTheWeek.Sunday));
                        break;
                    }
                    }

                    break;
                }

                case ClamWinScheduleData.SchedulingTypes.Weekly:
                {
                    short hour    = 0;
                    short minutes = 0;

                    if (data.UseDateTime)
                    {
                        hour    = (short)data.Date.Hour;
                        minutes = (short)data.Date.Minute;
                    }

                    task.Triggers.Add(new WeeklyTrigger(hour, minutes, (DaysOfTheWeek)data.Days));
                    break;
                }

                case ClamWinScheduleData.SchedulingTypes.Monthly:
                {
                    short hour    = 0;
                    short minutes = 0;

                    if (data.UseDateTime)
                    {
                        hour    = (short)data.Date.Hour;
                        minutes = (short)data.Date.Minute;
                    }

                    int[] day = new int[1];
                    day[0] = data.Frequency;
                    task.Triggers.Add(new MonthlyTrigger(hour, minutes, day));
                    break;
                }
                }
                task.Save();
                task.Close();
            }
        }