Unique class for compression/decompression file. Represents a Zip file.
Inheritance: IDisposable
Beispiel #1
0
 // ToDo: PRIORITY TASK! This code needs more testing & condensation
 private void AddAdditionalFiles(ZipStorer zipStorer)
 {
     foreach (FileMask additionalFiles in Settings.AdditionalReportFiles)
     {
         additionalFiles.AddToZip(zipStorer);
     }
 }
Beispiel #2
0
		// ToDo: PRIORITY TASK! This code needs more testing & condensation
		private void AddAdditionalFiles(ZipStorer zipStorer)
		{
			foreach (var mask in Settings.AdditionalReportFiles)
			{
				// Join before spliting because the mask may have some folders inside it
				var fullPath = Path.Combine(Settings.NBugDirectory, mask);
				var dir = Path.GetDirectoryName(fullPath);
				var file = Path.GetFileName(fullPath);

				if (!Directory.Exists(dir))
				{
					continue;
				}

				if (file.Contains("*") || file.Contains("?"))
				{
					foreach (var item in Directory.GetFiles(dir, file))
					{
						this.AddToZip(zipStorer, Settings.NBugDirectory, item);
					}
				}
				else
				{
					this.AddToZip(zipStorer, Settings.NBugDirectory, fullPath);
				}
			}
		}
Beispiel #3
0
        // ToDo: PRIORITY TASK! This code needs more testing & condensation
        private void AddToZip(ZipStorer zipStorer, string basePath, string path, FileShare share)
        {
            path = Path.GetFullPath(path);

            // If this is not inside basePath, lets change the basePath so at least some directories are kept
            if (!path.StartsWith(basePath))
            {
                basePath = Path.GetDirectoryName(path);
            }

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path))
                {
                    this.AddToZip(zipStorer, basePath, file, share);
                }

                foreach (var dir in Directory.GetDirectories(path))
                {
                    this.AddToZip(zipStorer, basePath, dir, share);
                }
            }
            else if (File.Exists(path))
            {
                var nameInZip = path.Substring(basePath.Length);
                if (nameInZip.StartsWith("\\") || nameInZip.StartsWith("/"))
                {
                    nameInZip = nameInZip.Substring(1);
                }

                nameInZip = Path.Combine("files", nameInZip);

                using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare))
                {
                    zipStorer.AddStream(ZipStorer.Compression.Deflate, nameInZip, stream, File.GetLastWriteTime(path), string.Empty);
                }
            }
        }
Beispiel #4
0
        // ToDo: PRIORITY TASK! This code needs more testing & condensation
        private void AddToZip(ZipStorer zipStorer, string basePath, string path, FileShare share)
        {
            path = Path.GetFullPath(path);

            // If this is not inside basePath, lets change the basePath so at least some directories are kept
            if (!path.StartsWith(basePath))
            {
                basePath = Path.GetDirectoryName(path);
            }

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path))
                {
                    this.AddToZip(zipStorer, basePath, file, share);
                }

                foreach (var dir in Directory.GetDirectories(path))
                {
                    this.AddToZip(zipStorer, basePath, dir, share);
                }
            }
            else if (File.Exists(path))
            {
                var nameInZip = path.Substring(basePath.Length);
                if (nameInZip.StartsWith("\\") || nameInZip.StartsWith("/"))
                {
                    nameInZip = nameInZip.Substring(1);
                }

                nameInZip = Path.Combine("files", nameInZip);

                using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare))
                {
                    zipStorer.AddStream(ZipStorer.Compression.Deflate, nameInZip, stream, File.GetLastWriteTime(path), string.Empty);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Add all additional files represented by this instance to the zip file using the zipStorer
        /// </summary>
        /// <param name="zipStorer"></param>
        internal void AddToZip(ZipStorer zipStorer)
        {
            // Join before spliting because the mask may have some folders inside it
            var fullPath = Path.Combine(Settings.NBugDirectory, FilePath);
            var dir      = Path.GetDirectoryName(fullPath);
            var file     = Path.GetFileName(fullPath);

            if (!Directory.Exists(dir))
            {
                return;
            }

            if (file.Contains("*") || file.Contains("?"))
            {
                foreach (var item in Directory.GetFiles(dir, file))
                {
                    this.AddToZip(zipStorer, Settings.NBugDirectory, item, FileShare);
                }
            }
            else
            {
                this.AddToZip(zipStorer, Settings.NBugDirectory, fullPath, FileShare);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Add all additional files represented by this instance to the zip file using the zipStorer
        /// </summary>
        /// <param name="zipStorer"></param>
        internal void AddToZip(ZipStorer zipStorer)
        {
            // Join before spliting because the mask may have some folders inside it
            var fullPath = Path.Combine(Settings.NBugDirectory, FilePath);
            var dir = Path.GetDirectoryName(fullPath);
            var file = Path.GetFileName(fullPath);

            if (!Directory.Exists(dir))
            {
                return;
            }

            if (file.Contains("*") || file.Contains("?"))
            {
                foreach (var item in Directory.GetFiles(dir, file))
                {
                    this.AddToZip(zipStorer, Settings.NBugDirectory, item, FileShare);
                }
            }
            else
            {
                this.AddToZip(zipStorer, Settings.NBugDirectory, fullPath, FileShare);
            }
        }
Beispiel #7
0
        // ToDo: PRIORITY TASK! This code needs more testing & condensation
        private void AddToZip(ZipStorer zipStorer, string basePath, string path)
        {
            path = Path.GetFullPath(path);

            // If this is not inside basePath, lets change the basePath so at least some directories are kept
            if (!path.StartsWith(basePath))
                basePath = Path.GetDirectoryName(path);

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path))
                    AddToZip(zipStorer, basePath, file);
                foreach (var dir in Directory.GetDirectories(path))
                    AddToZip(zipStorer, basePath, dir);
            }
            else if (File.Exists(path))
            {
                var nameInZip = path.Substring(basePath.Length);
                if (nameInZip.StartsWith("\\") || nameInZip.StartsWith("/"))
                    nameInZip = nameInZip.Substring(1);
                nameInZip = Path.Combine("files", nameInZip);

                zipStorer.AddFile(ZipStorer.Compression.Deflate, path, nameInZip, string.Empty);
            }
        }