Esempio n. 1
0
        private void DirSearch(string path)
        {
            Dictionary <int, string> Positions = new Dictionary <int, string>();

            foreach (var tempFile in Directory.GetFiles(path))
            {
                using (FileStream stream = File.OpenRead(tempFile))
                {
                    if (Path.GetFileNameWithoutExtension(tempFile) == "manifest")
                    {
                        using (JsonTextReader reader = new JsonTextReader(File.OpenText(tempFile)))
                        {
                            JArray o2 = (JArray)JToken.ReadFrom(reader);
                            int    i  = 0;
                            foreach (var value in o2.First.Last.Values())
                            {
                                int index = value.ToString().IndexOf('/');
                                Positions.Add(i++, value.ToString().Substring(0, index));
                            }
                        }
                    }
                }
            }

            foreach (var dir in Directory.GetDirectories(path))
            {
                MyDirectory layer = new MyDirectory(Path.GetFileName(dir));
                if (Positions.ContainsValue(layer.DirectoryName))
                {
                    layer.Position = Positions.FirstOrDefault(s => s.Value == layer.DirectoryName).Key;
                }
                layer.Dive(dir);
                Layers.Add(layer);
            }
        }
        public void Dive(string path)
        {
            foreach (var tempDir in Directory.GetDirectories(path))
            {
                MyDirectory subDir = new MyDirectory(Path.GetFileName(tempDir));
                Directories.Add(subDir);
                subDir.Dive(tempDir);
            }

            foreach (var tempFile in Directory.GetFiles(path))
            {
                using (FileStream stream = File.OpenRead(tempFile))
                {
                    var    sha      = new SHA256Managed();
                    byte[] checksum = sha.ComputeHash(stream);
                    MyFile file     = new MyFile(Path.GetFileName(tempFile), BitConverter.ToString(checksum).Replace("-", String.Empty));
                    Files.Add(file);
                }
            }
        }