Esempio n. 1
0
        static int Add(string path)
        {
            int cnt = 0;

            IEnumerable <string> Dir = EnumFile(path, "*", SearchOption.AllDirectories);

            foreach (string dir in Dir)
            {
                try {
                    EntityFile file = new EntityFile(dir);
                    try {
                        DataBase.InsertRecord(file);
                        cnt++;
                    }
                    catch (Exception e)
                    {
                        LogWriter.AddLog(e.Message);
                    }
                }
                catch (Exception e)
                {
                    LogWriter.AddLog(e.Message);
                }
            }
            return(cnt);
        }
Esempio n. 2
0
        public static void InsertRecord(EntityFile file)
        {
            string query = "INSERT INTO files VALUES ('" + file.FilePath + "', '" + file.Hash + "', " + file.Size.ToString() +
                           ", '" + file.ModificationDate.ToString() + "' )";

            DoQuery(query);
        }
Esempio n. 3
0
        static void Analize(string needPath)
        {
            SQLiteDataReader reader      = DataBase.GetDataReader(needPath);
            bool             ok          = true;
            HashSet <string> onlyBase    = new HashSet <string>();
            HashSet <string> baseAndDisk = new HashSet <string>();
            HashSet <string> onlyDisk    = new HashSet <string>();

            foreach (System.Data.Common.DbDataRecord record in reader)
            {
                string path = record["path"].ToString();

                if (!File.Exists(path))
                {
                    onlyBase.Add(path);
                }
                else
                {
                    baseAndDisk.Add(path);
                    string hash = record["hash"].ToString();
                    string size = record["size"].ToString();
                    string date = record["date"].ToString();

                    try
                    {
                        EntityFile nE      = new EntityFile(path);
                        bool       hashDif = (hash != nE.Hash);
                        bool       sizeDif = (Convert.ToInt32(size) != nE.Size);
                        bool       dateDif = (date != nE.ModificationDate.ToString());
                        if (hashDif || sizeDif || dateDif)
                        {
                            Console.WriteLine("Следующий файл был изменен: " + path);
                            if (hashDif)
                            {
                                Console.WriteLine("Изменен хэш " +
                                                  "\nстарый хэш: " + hash + "\nновый хэш: " + nE.Hash);
                            }
                            if (sizeDif)
                            {
                                Console.WriteLine("Изменен размер " +
                                                  "\nстарый размер: " + Convert.ToInt32(size) + "\nновый размер: " + nE.Size);
                            }
                            if (dateDif)
                            {
                                Console.WriteLine("Изменена дата модификации" +
                                                  "\nстарая дата: " + date + "\nновая дата: " + nE.ModificationDate.ToString());
                            }
                            Console.WriteLine();
                            ok = false;
                        }
                    }
                    catch (Exception e)
                    {
                        LogWriter.AddLog(e.Message);
                    }
                }
            }

            try
            {
                IEnumerable <string> Dir = EnumFile(needPath, "*", SearchOption.AllDirectories);
                foreach (string dir in Dir)
                {
                    if (!baseAndDisk.Contains(dir))
                    {
                        onlyDisk.Add(dir);
                    }
                }
            }
            catch (Exception e)
            {
                LogWriter.AddLog(e.Message);
            }

            if (onlyBase.Count != 0)
            {
                Console.WriteLine("Следующие файлы в базе есть, а на диске не обнаружены");
                foreach (string file in onlyBase)
                {
                    Console.WriteLine(file);
                    ok = false;
                }
            }

            Console.WriteLine();

            if (onlyDisk.Count != 0)
            {
                Console.WriteLine("Следующие файлы на диске есть, а в базе не обнаружены");
                foreach (string file in onlyDisk)
                {
                    Console.WriteLine(file);
                    ok = false;
                }
            }

            if (ok)
            {
                Console.WriteLine("Различий в базе и на диске не обнаружено.");
            }
        }