コード例 #1
0
        /// <summary>
        /// Remove current notification
        /// </summary>
        public static void CurrentNotifcationDone()
        {
            lock (MainLocker)
            {
                if (CurrentNotification < 0 || CurrentNotification >= Notifications.Count)
                {
                    return;
                }

                NotificationData data = (NotificationData)Notifications[CurrentNotification];

                string command = "DELETE FROM MainFormNotifications WHERE id = '" + data.ID.ToString() + "';";
                int    result;
                ClamWinDatabase.ExecCommand(command, out result);

                Notifications.RemoveAt(CurrentNotification);

                if (Notifications.Count == 0)
                {
                    CurrentNotification = -1;
                }
                else if (CurrentNotification >= Notifications.Count)
                {
                    CurrentNotification = Notifications.Count - 1;
                }

                PostCurrentChanged();
            }
        }
コード例 #2
0
        /// <summary>
        /// Close and save notifications
        /// </summary>
        public static void Close()
        {
            lock (MainLocker)
            {
                string command = "DELETE FROM MainFormNotifications;";
                int    result;
                ClamWinDatabase.ExecCommand(command, out result);

                while (true)
                {
                    NotificationData data;
                    if (Notifications.Count == 0)
                    {
                        CurrentNotification = -1;
                        return;
                    }

                    data = (NotificationData)Notifications[0];
                    Notifications.RemoveAt(0);


                    command  = "INSERT INTO MainFormNotifications(Message,Code,Type,Time) VALUES(";
                    command += "'" + data.Message + "',";
                    command += "'" + ((int)data.Code).ToString() + "',";
                    command += "'" + ((int)data.Type).ToString() + "',";
                    command += "'" + data.Time.ToBinary().ToString() + "');";

                    ClamWinDatabase.ExecCommand(command, out result);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Insert new or update existing row
        /// </summary>
        /// <param name="data"></param>
        /// <param name="status"></param>
        private void UpdateDatabase(ClamWinScan.FilterNotifyData data, string status)
        {
            int    result  = 0;
            string command = "SELECT * FROM FilterNotifications WHERE Path = '" + data.FileName + "'";

            command += " AND Message = '" + data.Message + "' AND Time = '" + data.Time.ToBinary().ToString() + "';";

            ArrayList items;

            ClamWinDatabase.ExecReader(command, out items);

            if (items.Count == 0)
            {
                // Insert new item
                command  = "INSERT INTO FilterNotifications(Path,Message,Status,Time) VALUES(";
                command += "'" + data.FileName + "',";
                command += "'" + data.Message + "',";
                command += "'" + status + "',";
                command += "'" + data.Time.ToBinary().ToString() + "');";
                ClamWinDatabase.ExecCommand(command, out result);
            }
            else
            {
                // Update existing
                command  = "UPDATE FilterNotifications SET Status = '" + status;
                command += "' WHERE Path = '" + data.FileName + "' AND Message = '" + data.Message + "'";
                command += " AND Time = '" + data.Time.ToBinary().ToString() + "';";
                ClamWinDatabase.ExecCommand(command, out result);
            }
        }
コード例 #4
0
ファイル: ClamWinStatistics.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Clean-up statistics table
        /// </summary>
        /// <returns></returns>
        private static bool StatisticsTableCleanUp()
        {
            string command = "DELETE FROM Statistics;";

            int result;

            return(ClamWinDatabase.ExecCommand(command, out result));
        }
コード例 #5
0
ファイル: ClamWinQuarantine.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Saves file info to database and removes file
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        private static bool PostCompressProcessing(string FileName, string QuarantineName)
        {
            long Size = 0;

            try
            {
                FileInfo fi = new FileInfo(QuarantineName);
                if (!fi.Exists)
                {
                    return(false);
                }

                fi = new FileInfo(FileName);

                if (!fi.Exists)
                {
                    return(false);
                }

                Size = fi.Length;
            }
            catch
            {
                return(false);
            }

            string command = "INSERT INTO QuarantineItems(InitialPath,QuarantinePath,QuarantineTime,Size) VALUES(";

            command += "'" + FileName + "',";
            command += "'" + QuarantineName + "',";
            command += "'" + DateTime.Now.ToBinary().ToString() + "',";
            command += "'" + Size.ToString() + "');";

            int result;

            ClamWinDatabase.ExecCommand(command, out result);

            // Let we ensure record has been inserted successfully
            command = "SELECT * FROM QuarantineItems WHERE InitialPath='" + FileName + "';";
            ArrayList list;

            if (ClamWinDatabase.ExecReader(command, out list))
            {
                if (list.Count != 0)
                {
                    RemoveFile(FileName);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
        /// <summary>
        /// Remove specified notification
        /// </summary>
        public static void NotificationDone(NotificationCodes code)
        {
            lock (MainLocker)
            {
                int CurrID = -1;
                if (CurrentNotification != -1)
                {
                    CurrID = ((NotificationData)Notifications[CurrentNotification]).ID;
                }

                NotificationData data = new NotificationData();
                data.ID = -1;

                bool ok = false;
                for (int i = 0; i < Notifications.Count; i++)
                {
                    data = (NotificationData)Notifications[i];

                    if (data.Code == code)
                    {
                        ok = true;
                        Notifications.RemoveAt(i);
                        break;
                    }
                }

                if (!ok)
                {
                    return;
                }

                string command = "DELETE FROM MainFormNotifications WHERE id = '" + data.ID.ToString() + "';";
                int    result;
                ClamWinDatabase.ExecCommand(command, out result);

                CurrentNotification = -1;
                for (int i = 0; i < Notifications.Count; i++)
                {
                    data = (NotificationData)Notifications[i];

                    if (data.ID == CurrID)
                    {
                        CurrentNotification = i;
                        break;
                    }
                }

                if (CurrentNotification == -1 && Notifications.Count != 0)
                {
                    CurrentNotification = Notifications.Count - 1;
                }

                PostCurrentChanged();
            }
        }
コード例 #7
0
        /// <summary>
        /// Add new notifcation
        /// </summary>
        public static int AddNotification(string message, NotificationCodes code, NotificationType type)
        {
            lock (MainLocker)
            {
                for (int i = 0; i < Notifications.Count; i++)
                {
                    NotificationData item = (NotificationData)Notifications[i];
                    if (code == item.Code)
                    {
                        //Already exist
                        CurrentNotification = i;
                        PostCurrentChanged();

                        return(-1);
                    }
                }
                NotificationData data = new NotificationData();
                data.Message = message;
                data.Code    = code;
                data.Type    = type;
                data.Time    = DateTime.Now;

                string command = "INSERT INTO MainFormNotifications(Message,Code,Type,Time) VALUES(";
                command += "'" + data.Message + "',";
                command += "'" + ((int)data.Code).ToString() + "',";
                command += "'" + ((int)data.Type).ToString() + "',";
                command += "'" + data.Time.ToBinary().ToString() + "');";

                int result;
                ClamWinDatabase.ExecCommand(command, out result);

                command = "SELECT * FROM MainFormNotifications WHERE Time=(SELECT max(Time) FROM MainFormNotifications);";

                ArrayList Items;
                if (!ClamWinDatabase.ExecReader(command, out Items))
                {
                    return(-1);
                }
                else if (Items.Count == 0)
                {
                    return(-1);
                }

                data.ID = int.Parse((string)Items[0]);

                Notifications.Add(data);

                CurrentNotification = Notifications.Count - 1;

                PostCurrentChanged();

                return(data.ID);
            }
        }
コード例 #8
0
ファイル: ClamWinQuarantine.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Check exctracted file size and removes database recod
        /// </summary>
        /// <returns></returns>
        private static bool PostExtractProcessing(string CompressedFileName, string FileName)
        {
            // Let we ensure record has been inserted successfully
            string    command = "SELECT * FROM QuarantineItems WHERE InitialPath='" + FileName + "';";
            ArrayList list;

            if (ClamWinDatabase.ExecReader(command, out list))
            {
                if (list.Count != 0)
                {
                    long size = long.Parse((string)list[4]);
                    try
                    {
                        FileInfo fi = new FileInfo(FileName);
                        if (!fi.Exists)
                        {
                            return(false);
                        }

                        if (fi.Length != size)
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            command = "DELETE FROM QuarantineItems WHERE QuarantinePath='" + CompressedFileName + "';";
            int result;

            ClamWinDatabase.ExecCommand(command, out result);

            RemoveFile(CompressedFileName);

            return(true);
        }
コード例 #9
0
ファイル: ClamWinStatistics.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Save FileAntiVirus statistics to data base
        /// </summary>
        /// <returns>true - on success, false - if failed</returns>
        public static bool FlushFileAntiVirus()
        {
            lock (MainLock)
            {
                //string command = "INSERT INTO Statistics(Object,Scanned,Threats,Deleted,MovedToQuarantine,Archived,Packed,PasswordProtected,Corrupted,LastScanned,ScanID) VALUES(";
                string command     = "UPDATE Statistics SET Scanned = '" + FileAntiVirus.Scanned.ToString() + "', ";
                string LastScanned = FileAntiVirus.LastScanned.Replace("'", "''");
                command += "Threats = '" + FileAntiVirus.Threats.ToString() + "', ";
                command += "Deleted = '" + FileAntiVirus.Deleted.ToString() + "', ";
                command += "MovedToQuarantine = '" + FileAntiVirus.MovedToQuarantine.ToString() + "', ";
                command += "Archived = '" + FileAntiVirus.Archived.ToString() + "', ";
                command += "Packed = '" + FileAntiVirus.Packed.ToString() + "', ";
                command += "PasswordProtected = '" + FileAntiVirus.PasswordProtected.ToString() + "', ";
                command += "Corrupted = '" + FileAntiVirus.Corrupted.ToString() + "', ";
                command += "LastScanned = '" + LastScanned + "', ";
                command += "ScanID = '-1'";
                command += " WHERE Object = '" + FileAntiVirus.Object + "';";

                int result;
                ClamWinDatabase.ExecCommand(command, out result);

                if (result == 0)
                {
                    //UPDATE failed
                    command     = "INSERT INTO Statistics(Object,Scanned,Threats,Deleted,MovedToQuarantine,Archived,Packed,PasswordProtected,Corrupted,LastScanned,ScanID) VALUES(";
                    LastScanned = FileAntiVirus.LastScanned.Replace("'", "''");
                    command    += "'" + FileAntiVirus.Object + "',";
                    command    += "'" + FileAntiVirus.Scanned.ToString() + "',";
                    command    += "'" + FileAntiVirus.Threats.ToString() + "',";
                    command    += "'" + FileAntiVirus.Deleted.ToString() + "',";
                    command    += "'" + FileAntiVirus.MovedToQuarantine.ToString() + "',";
                    command    += "'" + FileAntiVirus.Archived.ToString() + "',";
                    command    += "'" + FileAntiVirus.Packed.ToString() + "',";
                    command    += "'" + FileAntiVirus.PasswordProtected.ToString() + "',";
                    command    += "'" + FileAntiVirus.Corrupted.ToString() + "',";
                    command    += "'" + LastScanned + "',";
                    command    += "'-1');";

                    if (!ClamWinDatabase.ExecCommand(command, out result))
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
コード例 #10
0
ファイル: ClamWinQuarantine.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Check quarantined  file
        /// </summary>
        /// <param name="FilePathName"></param>
        /// <returns></returns>
        public static bool CheckQuarantinedFile(string QuarantinePathName, long SavedSize)
        {
            try
            {
                FileInfo fi = new FileInfo(QuarantinePathName);
                if (!fi.Exists)
                {
                    throw new SystemException();
                }

                return(true);
            }
            catch
            {
            }

            // Something is wrong, perform database and quarantined file clean up

            string command = "DELETE FROM QuarantineItems WHERE QuarantinePath='" + QuarantinePathName + "';";
            int    result;

            ClamWinDatabase.ExecCommand(command, out result);

            try
            {
                FileInfo fi = new FileInfo(QuarantinePathName);

                if (fi.Exists)
                {
                    fi.Delete();
                }
            }
            catch
            {
            }


            return(false);
        }
コード例 #11
0
ファイル: ClamWinStatistics.cs プロジェクト: clamwin/clamwind
        /// <summary>
        /// Cleanup current staitsitcs and delete records from "Statistics" table
        /// </summary>

        /*public static void Reset()
         * {
         *  lock (MainLock)
         *  {
         *      Items.Clear();
         *      StatisticItem item = new StatisticItem(TotalString);
         *      Items.Insert(0, item);
         *  }
         *
         *  StatisticsTableCleanUp();
         * }*/
        /// <summary>
        /// Save items to data base, and clear Items
        /// </summary>
        /// <returns>true - on success, false - if failed</returns>
        public static bool FlushItems(int ScanID)
        {
            lock (MainLock)
            {
                if (!Opened)
                {
                    return(false);
                }

                string ID = ScanID.ToString();
                foreach (StatisticItem item in Items)
                {
                    // Specified record not found , try to insert new record
                    string command = "INSERT INTO Statistics(Object,Scanned,Threats,Deleted,MovedToQuarantine,Archived,Packed,PasswordProtected,Corrupted,LastScanned,ScanID) VALUES(";
                    string Object  = item.Object.Replace("'", "''");
                    command += "'" + Object + "',";
                    command += "'" + item.Scanned.ToString() + "',";
                    command += "'" + item.Threats.ToString() + "',";
                    command += "'" + item.Deleted.ToString() + "',";
                    command += "'" + item.MovedToQuarantine.ToString() + "',";
                    command += "'" + item.Archived.ToString() + "',";
                    command += "'" + item.Packed.ToString() + "',";
                    command += "'" + item.PasswordProtected.ToString() + "',";
                    command += "'" + item.Corrupted.ToString() + "',";
                    command += "'" + item.LastScanned + "',";
                    command += "'" + ID + "');";

                    int result;
                    if (!ClamWinDatabase.ExecCommand(command, out result))
                    {
                        return(false);
                    }
                }
            }

            Items.Clear();

            return(true);
        }