/// <summary> /// toolStripMenuItemQuarantine on-click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemQuarantine_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } if (ClamWinQuarantine.IsFileInQuarantine(openFileDialog.FileName)) { MessageBox.Show("File is already quarantined!"); return; } IntPtr[] Listeners = new IntPtr[2]; Listeners[0] = this.Handle; Listeners[1] = MainFomrHandle; ClamWinQuarantine.QuarantineResults result = ClamWinQuarantine.QuarantineFile(openFileDialog.FileName, Listeners); if (result != ClamWinQuarantine.QuarantineResults.Success) { MessageBox.Show("Operation failed with message: " + ClamWinQuarantine.QuarantineResultToString(result)); } }
/// <summary> /// toolStripMenuItemQueueCancelProcessing on-click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemQueueCancelProcessing_Click(object sender, EventArgs e) { foreach (ListViewItem item in listViewQueuedItems.Items) { if (!item.Selected) { continue; } IntPtr[] Listeners = new IntPtr[1]; Listeners[0] = this.Handle; ClamWinQuarantine.CancelItemProcessing((long)item.Tag, Listeners); } }
/// <summary> /// toolStripMenuItemUnquarantine on-click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemUnquarantine_Click(object sender, EventArgs e) { foreach (ListViewItem item in listViewQuarantineItems.Items) { if (!item.Selected) { continue; } IntPtr[] Listeners = new IntPtr[2]; Listeners[0] = this.Handle; Listeners[1] = MainFomrHandle; ClamWinQuarantine.QuarantineResults result = ClamWinQuarantine.UnquarantineFile(item.SubItems[1].Text, Listeners, false); if (result != ClamWinQuarantine.QuarantineResults.Success) { MessageBox.Show("Operation failed with message: " + ClamWinQuarantine.QuarantineResultToString(result)); break; } } }
/// <summary> /// Fill quarantine items list with database records /// </summary> private void UpdateQuarantineItems() { listViewQuarantineItems.Items.Clear(); //ListViewItem item = listViewQuarantineItems.Items string command = "SELECT * FROM QuarantineItems;"; ArrayList list; ClamWinDatabase.ExecReader(command, out list); if (list.Count == 0) { return; } int FieldsPerRecord = ClamWinDatabase.QuarantineItemsFPR; int RecordsCount = list.Count / FieldsPerRecord; for (int i = 0; i < RecordsCount; i++) { string PathName = (string)list[i * FieldsPerRecord + 1]; string QuarantinePathName = (string)list[i * FieldsPerRecord + 2]; string time = (string)list[i * FieldsPerRecord + 3]; DateTime Time = DateTime.FromBinary(long.Parse(time)); long Size = long.Parse((string)list[i * FieldsPerRecord + 4]); if (!ClamWinQuarantine.CheckQuarantinedFile(QuarantinePathName, Size)) { continue; } string FileName = System.IO.Path.GetFileName(PathName); ListViewItem item = listViewQuarantineItems.Items.Add(FileName); item.SubItems.Add(PathName); item.SubItems.Add(Time.ToShortDateString() + " " + Time.ToShortTimeString()); item.SubItems.Add(Size.ToString()); } }
/// <summary> /// toolStripMenuItemQuaRescan on-click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemQuaRescan_Click(object sender, EventArgs e) { if (ClamWinQuarantine.IsWorking()) { MessageBox.Show("Quarantine queue contain unhandled items.Plese wait until queue is done."); return; } foreach (ListViewItem item in listViewQuarantineItems.Items) { if (!item.Selected) { continue; } IntPtr[] Listeners = new IntPtr[2]; Listeners[0] = this.Handle; Listeners[1] = MainFomrHandle; ClamWinQuarantine.UnquarantineFile(item.SubItems[1].Text, Listeners, true); } ClamWinQuarantine.LockQueue(); WaitingForRescan = true; }