Exemplo n.º 1
0
        private static void AddDirectoryFiles(this TarArchive tarArchive, string sourceDirectory, bool recurse)
        {
            // Optionally, write an entry for the directory itself.
            // Specify false for recursion here if we will add the directory's files individually.
            //
            var tarEntry = TarEntry.CreateEntryFromFile(sourceDirectory);

            tarArchive.WriteEntry(tarEntry, false);

            // Write each file to the tar.
            //
            var filenames = Directory.GetFiles(sourceDirectory);

            foreach (string filename in filenames)
            {
                tarEntry = TarEntry.CreateEntryFromFile(filename);
                tarArchive.WriteEntry(tarEntry, true);
            }

            if (recurse)
            {
                var directories = Directory.GetDirectories(sourceDirectory);
                foreach (string directory in directories)
                {
                    tarArchive.AddDirectoryFiles(directory, recurse);
                }
            }
        }
Exemplo n.º 2
0
 public static void Archive(string archive, string password, string directory)
 {
     File.Delete(archive);
     using (Stream stream = File.OpenWrite(archive))
     {
         using (CryptoStream cryptoStream = Cipher.Encrypt(stream, password))
             using (BZip2OutputStream bz2 = new BZip2OutputStream(cryptoStream))
                 using (TarArchive tar = TarArchive.CreateOutputTarArchive(bz2))
                 {
                     tar.RootPath = directory.Replace('\\', '/').TrimEnd('/');
                     tar.AddDirectoryFiles(directory, true);
                 }
     }
 }