/// <summary> /// Execute specified command, used for performing action if response is not expected /// </summary> /// <param name="text">Command text</param> /// <returns>true - on success, false - if failed</returns> public static bool ExecCommand(string text, out int result) { result = 0; lock (MainLock) { if (!Opened) { return(false); } } try { lock (MainLock) { SQLiteCommand command = SQLiteConnection.CreateCommand(); command.CommandText = text; result = command.ExecuteNonQuery(); Win32API.PostMessage(MainFormHandle, UM_DATABASE_CHANGED, 0, 0); return(true); } } catch (SQLiteException ex) { MessageBox.Show("Failed to ExecComand with message:" + ex.Message); return(false); } }
/// <summary> /// Quarantine quueu processing complete /// </summary> private void OnQuarantineQueueDone() { if (WaitingForRescan) { Win32API.PostMessage(MainFomrHandle, ClamWinMainForm.UM_SCAN_QUARANTINE_RESCAN, 0, 0); WaitingForRescan = false; } }
/// <summary> /// Send message to Listeners /// </summary> private static void SendQuarantineNotify(int notification, NotifyData data, IntPtr[] Listeners) { lock (MainLock) { if (Listeners == null) { return; } foreach (IntPtr handle in Listeners) { int size = Marshal.SizeOf(data); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(data, ptr, false); Win32API.PostMessage(handle, notification, (uint)ptr.ToInt32(), 0); } } }
/// <summary> /// Check arguments and send corresponding mesages to existing instance of ClamWin /// </summary> /// <param name="args"></param> public static void OnArguments(string[] args, IntPtr Handle) { foreach (string arg in args) { if (arg == ClamWinScheduleData.UpdateArg) { Win32API.PostMessage(Handle, ClamWinMainForm.UM_SCHEDULED_UPDATE, 0, 0); } else if (arg == ClamWinScheduleData.ScanArg) { Win32API.PostMessage(Handle, ClamWinMainForm.UM_SCHEDULED_SCAN, 0, 0); } else if (arg == ClamWinScheduleData.ScanCriticalArg) { Win32API.PostMessage(Handle, ClamWinMainForm.UM_SCHEDULED_SCAN_CRITICAL, 0, 0); } else if (arg == ClamWinScheduleData.ScanMyPCArg) { Win32API.PostMessage(Handle, ClamWinMainForm.UM_SCHEDULED_SCAN_MY_PC, 0, 0); } } }
/// <summary> /// Post user message to main form /// </summary> public static void PostCurrentChanged() { Win32API.PostMessage(MainFormHandle, UM_CURRENT_NOTIFICATION_CHANGED, 0, 0); }
private static void DownloadWorker(IntPtr[] Listeners) { while (true) { WebClient client = new WebClient(); byte[] data = client.DownloadData("http://clamwin.sourceforge.net/clamwin.ver"); string helper = Encoding.ASCII.GetString(data, 0, data.Length); int pos = helper.IndexOf("="); if (pos == -1) { return; } pos++; int pos1 = helper.IndexOf("[", pos); string version = helper.Substring(pos, pos1 - pos); Version Version = new Version(); try { pos = version.IndexOf("."); if (pos != -1) { Version.part1 = int.Parse(version.Substring(0, pos)); } else { throw new SystemException(); } pos++; pos1 = version.IndexOf(".", pos); if (pos1 != -1) { Version.part2 = int.Parse(version.Substring(pos, pos1 - pos)); } else { throw new SystemException(); } pos1++; pos = version.IndexOf(".", pos1); if (pos != -1) { Version.part3 = int.Parse(version.Substring(pos1, pos - pos1)); } else { throw new SystemException(); } pos++; if (pos != -1) { Version.part4 = int.Parse(version.Substring(pos)); } else { throw new SystemException(); } } catch { Version = CurrentVersion; } if (CurrentVersion.Compare(Version) == -1) { NotifyData notify = new NotifyData(); notify.Version = Version; notify.CurrentVersion = CurrentVersion; foreach (IntPtr handle in Listeners) { int size = Marshal.SizeOf(notify); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(notify, ptr, false); Win32API.PostMessage(handle, UM_NEW_VERSION_AVAILABLE, (uint)ptr.ToInt32(), 0); } } System.Threading.Thread.Sleep(60000 * 60 * 12); } }