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); } } }
private void selectImage1Button_Click(object sender, EventArgs e) { Layers.Clear(); fileDialog = new OpenFileDialog(); fileDialog.Filter = "TAR (*.tar)|*.tar;|All files (*.*)|*.*"; fileDialog.ShowDialog(); fileImage1TextBox.Text = fileDialog.SafeFileName; FolderPath = Path.Combine(Path.GetDirectoryName(fileDialog.FileName), Path.GetFileNameWithoutExtension(fileDialog.FileName)); ExtractFiles.ExtractFile(fileDialog.FileName); DirSearch(Path.Combine(Directory.GetParent(Path.GetFullPath(fileDialog.FileName)).FullName, Path.GetFileNameWithoutExtension(fileDialog.SafeFileName))); Layers = Layers.OrderBy(s => s.Position).ToList(); DockerImage = Layers.First(); foreach (var item in Layers.ToArray()) { layerList.Items.Add(item.DirectoryName.Substring(0, 30)); } }