Exemplo n.º 1
0
        public static void AddFilesToZip(this ICakeContext context, FilePath zipFile, DirectoryPath start, string newStart, FilePathCollection files, bool append)
        {
            zipFile = context.MakeAbsolute(zipFile);
            if (!append)
            {
                if (context.FileExists(zipFile))
                {
                    context.DeleteFile(zipFile);
                }
            }

            if (newStart != "")
            {
                newStart = newStart.EnsureEndsWith("/");
            }

            var rootPath = context.MakeAbsolute(start).FullPath;

            foreach (var file in files)
            {
                context.Information("Reading " + file.FullPath);
                using (var fileToZip = new FileStream(file.FullPath, FileMode.Open, FileAccess.Read))
                {
                    var pathInZip = newStart == ""
                                        ? file.FullPath.Substring(rootPath.Length + 1)
                                        : newStart + file.FullPath.Substring(rootPath.Length + 1);
                    context.AddStreamToZip(zipFile, fileToZip, pathInZip, true);
                }
            }
        }
Exemplo n.º 2
0
 public static void AddTextFileToZip(this ICakeContext context, FilePath zipFile, string content, string name, bool append)
 {
     using (var sr = context.GenerateStreamFromString(content))
     {
         context.AddStreamToZip(zipFile, sr, name, append);
     }
 }
Exemplo n.º 3
0
 public static void AddBinaryFileToZip(this ICakeContext context, FilePath zipFile, byte[] content, string name, bool append)
 {
     using (var sr = new MemoryStream(content))
     {
         context.AddStreamToZip(zipFile, sr, name, append);
     }
 }
Exemplo n.º 4
0
 public static void AddXmlFileToZip(this ICakeContext context, FilePath zipFile, XmlDocument content, string name, bool append)
 {
     using (var ms = new MemoryStream())
     {
         var writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
         writer.Formatting = Formatting.Indented;
         content.WriteContentTo(writer);
         writer.Flush();
         ms.Flush();
         ms.Position = 0;
         context.AddStreamToZip(zipFile, ms, name, append);
     }
 }
Exemplo n.º 5
0
 public static void AddStreamToZip(this ICakeContext context, FilePath zipFile, Stream fileToZip, string name)
 {
     context.AddStreamToZip(zipFile, fileToZip, name, false);
 }