示例#1
0
 static DDirectory checkAvailabilty(string path, DDirectory dir)
 {
     for (int i = 0; i < dir.subdirs.Count; i++)
         if (dir.subdirs[i].name.Equals(path))
             return dir.subdirs[i];
     return null;
 }
示例#2
0
        static bool check(string path, DDirectory dir)
        {
            string[] splpath = path.Split('\\');
            string tmppth = "";
            for (int i = 1; i < splpath.Length; i++)
            {
                tmppth = splpath[0];
                for (int j = 1; j <= i; j++)
                    tmppth += '\\' + splpath[j];
                dir = checkAvailabilty(tmppth, dir);
                if (dir == null)
                {
                    Console.WriteLine("Папка {0} не была проверена либо была добавлена после дампа", tmppth);
                    return false;
                }
            }
            Console.WriteLine("Проверка...");
            compare(dir, path);

            return true;
        }
示例#3
0
 public static DDirectory createContext(string path, int iteration)
 {
     string[] folders = path.Split('\\');
     string sub = "";
     DDirectory dir;
     if (iteration < folders.Length - 1)
     {
         for (int i = 0; i < iteration; i++)
             sub += folders[i] + '\\';
         sub += folders[iteration];
         dir = new DDirectory(sub, false);
         dir.subdirs.Add(createContext(path, ++iteration));
     }
     else
     {
         dir = createDB(path);
         dir.isDumped = true;
     }
     return dir;
 }
示例#4
0
 public static void print(DDirectory dir)
 {
     Console.WriteLine("DirName: {0} Dumped:{1}", dir.name, dir.isDumped);
     List<DFile> files = dir.files;
     List<DDirectory> subdirs = dir.subdirs;
     for (int i = 0; i < files.Count; i++)
         Console.WriteLine("FileName: {0} Dumped: {1}", files[i].name, files[i].isDumped);
     for (int i = 0; i < subdirs.Count; i++)
         print(subdirs[i]);
 }
示例#5
0
        public static void compare(DDirectory dump, string path)
        {
            string[] subdirs;
            string[] files;

            try
            {
                subdirs = Directory.GetDirectories(path);
                files = Directory.GetFiles(path);
            }
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine("Доступ запрещен к папке {0}", path);
                return;
            }
            if (!dump.isDumped)
                Console.WriteLine("Внимание! Не полностью проверена папка\n{0}\n" +
                    "Некоторые объекты могли быть проигнорированы при сборе дампа\n", dump.name);
            FileInfo fi;
            bool match;
            for (int i = 0; i < files.Length; i++)
            {
                match = false;
                for (int j = 0; j < dump.files.Count; j++)
                    if (files[i].Equals(dump.files[j].name))
                    {

                        fi = new FileInfo(files[i]);
                        if (fi.Length != dump.files[j].size)
                        {
                            Console.WriteLine("Размер следующего файла был изменен:\n{0}\n", files[i]);
                            changed = true;
                        }
                        byte[] hashBytes = computeFileHash(files[i]);
                        if (hashBytes == null)
                        {
                            match = true;
                            dump.files[j].isChecked = true;
                            break;
                        }
                        if (!BitConverter.ToString(hashBytes).Equals(dump.files[j].hash))
                        {
                            Console.WriteLine("Хеш-сумма следующего файла изменилась:\n{0}\n", files[i]);
                            changed = true;
                        }
                        dump.files[j].isChecked = true;
                        match = true;
                        break;
                    }
                if (!match)
                {
                    if (dump.isDumped)
                        Console.WriteLine("Следующий файл был добавлен:\n{0}\n", files[i]);
                    changed = true;
                }
            }

            for (int i = 0; i < dump.files.Count; i++)
                if (!dump.files[i].isChecked)
                {
                    changed = true;
                    Console.WriteLine("Следующий файл был удален:\n{0}\n", dump.files[i].name);
                }

            for (int i = 0; i < subdirs.Length; i++)
            {
                match = false;
                for (int j = 0; j < dump.subdirs.Count; j++)
                    if (subdirs[i].Equals(dump.subdirs[j].name))
                    {
                        compare(dump.subdirs[j], subdirs[i]);
                        dump.subdirs[j].isChecked = true;
                        match = true;
                        break;
                    }
                if (!match)
                {
                    changed = true;
                    if (dump.isDumped)
                        Console.WriteLine("Следующая папка была добавлена:\n{0}\n", subdirs[i]);
                    else
                        Console.WriteLine("Следующая папка была добавлена либо не была внесена в дамп:\n{0}\n", subdirs[i]);
                }
            }

            for (int i = 0; i < dump.subdirs.Count; i++)
                if (!dump.subdirs[i].isChecked)
                {
                    changed = true;
                    Console.WriteLine("Следующая папка была удалена:\n{0}\n", dump.subdirs[i].name);
                }
        }