Пример #1
0
        public static void Main(string[] args)
        {
            var envDir = PlatformServices.Default.Application.ApplicationBasePath;
            var pathThings = Path.Combine(envDir, "things.txt");
            var pathStuff = Path.Combine(envDir, "stuff.txt");

            using (var fileStreamThings = File.CreateText(pathThings))
            {
                fileStreamThings.WriteLine("Things lol");
            }

            using (var fileStreamStuff = File.CreateText(pathStuff))
            {
                fileStreamStuff.WriteLine("Stuff lol");
            }

            var zipDef = new BazamZip()
            {
                Files = new string[]
                {
                    pathThings,
                    pathStuff
                },
                ZipFileName = Path.Combine(envDir, "blarpleslamp.zip")
            };

            var bazamZipClient = new BazamZipClient();
            bazamZipClient.Zip(zipDef);
            bazamZipClient.Unzip(zipDef.ZipFileName, Path.Combine(envDir, "unzipped"), false);
        }
Пример #2
0
        public void Zip(BazamZip zipDefinition, bool deleteComponentFilesWhenDone = false)
        {
            using (var zip = ZipFile.Open(zipDefinition.ZipFileName, ZipArchiveMode.Create))
            {
                foreach (var fileName in zipDefinition.Files)
                {
                    var fileInfo = new FileInfo(fileName);
                    var entryName = fileName;

                    if (!zipDefinition.PreserveFilePaths)
                    {
                        entryName = Path.GetFileName(fileName);
                    }
                    else if (!string.IsNullOrEmpty(zipDefinition.FilesRelativeRootForZip))
                    {
                        entryName = entryName.Replace(zipDefinition.FilesRelativeRootForZip, string.Empty);
                    }

                    zip.CreateEntryFromFile(fileName, entryName, CompressionLevel.Optimal);
                }
            }

            if (deleteComponentFilesWhenDone)
            {
                foreach (string fileName in zipDefinition.Files)
                {
                    File.Delete(fileName);
                }
            }
        }