Click here to Skip to main content
11,631,326 members (71,914 online)
Click here to Skip to main content
Add your own
alternative version

Deployer

, 30 Mar 2012 Apache 47.1K 426 89
Automate deployment of Windows Services, ClickOnce, and other .NET applications.
deployer_src.zip
Deployer
Deployer
!copyToDllCache
Interop.VSFlex7L.dll
stdole.dll
ClassDiagram1.cd
clickOnceKey.pfx
deployer-full.xsx
Deployer.csproj.user
DeployTypes
DomainClasses
_tfs
text-base
ConfigReplacesEntry.cs.tfs-base
ConfigReplacesRoot.cs.tfs-base
DllCacheEntry.cs.tfs-base
_tfs
text-base
BaseDeployType.cs.tfs-base
ClickOnce.cs.tfs-base
DatabaseScript.cs.tfs-base
Service.cs.tfs-base
XCopy.cs.tfs-base
Logic
_tfs
text-base
Controller.cs.tfs-base
FileSystemUtil.cs.tfs-base
XmlUtil.cs.tfs-base
mage.exe
Properties
Settings.settings
_tfs
text-base
AssemblyInfo.cs.tfs-base
Resources.Designer.cs.tfs-base
Resources.resx.tfs-base
Settings.Designer.cs.tfs-base
Settings.settings.tfs-base
Zip
.svn
entries
format
prop-base
_tfs
text-base
props
_tfs
text-base
text-base
ZipArchive.cs.svn-base
ZipDirectory.cs.svn-base
ZipEntry.cs.svn-base
ZipEntryCollection.cs.svn-base
ZipException.cs.svn-base
ZipLib.cs.svn-base
ZipStream.cs.svn-base
_tfs
text-base
ZipArchive.cs.svn-base.tfs-base
ZipDirectory.cs.svn-base.tfs-base
ZipEntry.cs.svn-base.tfs-base
ZipEntryCollection.cs.svn-base.tfs-base
ZipException.cs.svn-base.tfs-base
ZipLib.cs.svn-base.tfs-base
ZipStream.cs.svn-base.tfs-base
tmp
prop-base
_tfs
text-base
props
_tfs
text-base
text-base
_tfs
text-base
_tfs
text-base
_tfs
text-base
entries.tfs-base
format.tfs-base
_tfs
text-base
ZipArchive.cs.tfs-base
ZipDirectory.cs.tfs-base
ZipEntry.cs.tfs-base
ZipEntryCollection.cs.tfs-base
ZipException.cs.tfs-base
ZipLib.cs.tfs-base
ZipStream.cs.tfs-base
zlib.dll
TestApp
Properties
Settings.settings
_tfs
text-base
AssemblyInfo.cs.tfs-base
Resources.Designer.cs.tfs-base
Resources.resx.tfs-base
Settings.Designer.cs.tfs-base
Settings.settings.tfs-base
TestClickOnceApp
ClickOnceApp_TemporaryKey.pfx
Properties
Settings.settings
_tfs
text-base
AssemblyInfo.cs.tfs-base
Resources.Designer.cs.tfs-base
Resources.resx.tfs-base
Settings.Designer.cs.tfs-base
Settings.settings.tfs-base
TestClickOnceApp.csproj.user
TestDatabaseScript
Properties
_tfs
text-base
AssemblyInfo.cs.tfs-base
TestWindowsService
Properties
_tfs
text-base
AssemblyInfo.cs.tfs-base
someFiles
_tfs
text-base
will not be included in backup.txt.tfs-base
/* #zlib - Wrapping and enhancing the zlib
 * Copyright (C) 2005-06, Tyron Madlener <zlib@tyron.at>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * See COPYING for details
 */

using System;
using System.IO;
using System.Text;
using System.Collections;

namespace UsefulHeap.Zip {

	public class ZipStream : Stream {
		string _filename;
		ZipArchive archive;
		ZipEntry entry;

		#region Stream properties
		public override bool CanRead {
			get {
				return true;
			}
		}

		public override bool CanWrite {
			get {
				if(File.Exists(archive.Name)) {
					if((File.GetAttributes(archive.Name) & FileAttributes.ReadOnly) != 0)
						return false;
				} else {
					DirectoryInfo info = new DirectoryInfo(Path.GetDirectoryName(archive.Name));
					if((info.Attributes & FileAttributes.ReadOnly) != 0)
						return false;
				}
				return true;
			}
		}

		public override bool CanSeek {
			get {
				return false;
			}
		}

		public override long Length {
			get {
				if(entry==null) {
					archive.OpenWith(FileAccess.Read);

					int result = ZipLib.unzLocateFile(archive.Handle, _filename, 0);
					if (result < 0) {
						string msg = String.Format("Could not locate entry named '{0}'. Errorcode "+result, _filename);
						throw new ZipException(msg);
					}

					result = ZipLib.unzOpenCurrentFile(archive.Handle);
					if (result < 0) {			
						throw new ZipException("Could not open entry for reading.");
					}

					entry = new ZipEntry(archive.Handle);
				}

				return (long)entry.Length;
			}
		}

		public override long Position {
			get {
				throw new Exception("ZipStream does not support Postion setting/getting");			
			}
			set {
				throw new Exception("ZipStream does not support Postion setting/getting");
			}
		}
		#endregion

		public ZipStream(ZipArchive archive, string FileName) {			
			_filename = FileName;
			this.archive = archive;
		}

		#region Read&Write
		public string ReadToEnd() {
			byte []buf = new byte[Length];
			Read(buf,0,(int)Length);
			return System.Text.Encoding.Default.GetString(buf);
		}

		public override int Read(byte[] buffer, int offset, int count) {
			if(archive.Access == FileAccess.Write)
				throw new Exception("You can't read from archive in write mode");

			archive.OpenWith(FileAccess.Read);

			int result = ZipLib.unzLocateFile(archive.Handle, _filename, 0);
			if (result < 0) {
				string msg = String.Format("Could not locate entry named '{0}'. Errorcode "+result, _filename);
				throw new ZipException(msg);
			}

			result = ZipLib.unzOpenCurrentFile(archive.Handle);
			if (result < 0)
				throw new ZipException("Could not open entry for reading.");
			

			if (offset != 0)
				throw new ArgumentException("offset", "Only offset values of zero currently supported.");
			
			int bytesRead = ZipLib.unzReadCurrentFile(archive.Handle, buffer, (uint) count);
			if (bytesRead < 0)
				throw new ZipException("Error reading zip entry.");

			return bytesRead;		
		}

		public override void Write(byte[] buffer, int offset, int count) {
			ZipFileEntryInfo info;
			info.DateTime = DateTime.Now;
			bool FileExists = false;

			if(archive.Access == FileAccess.Read)
				throw new Exception("You can't write to archive in read mode");			

			// Check wether the file already exists in the archive
			if(File.Exists(archive.Name)) {
				archive.OpenWith(FileAccess.Read);				

				if(ZipLib.unzLocateFile(archive.Handle, _filename, 0)==0) 
					FileExists = true;
			}

			// Delete old file first
			if(FileExists) 
				archive.Delete(_filename);

			archive.OpenWith(FileAccess.Write);

			// Add the file
			int result = ZipLib.zipOpenNewFileInZip(archive.Handle, _filename, out info, null, 0, null, 0, String.Empty, (int)CompressionMethod.Deflated, (int)CompressionLevel.Default);
			if (result < 0) {			
				throw new ZipException("Could not open entry for writing.");
			}

			result = ZipLib.zipWriteInFileInZip(archive.Handle, buffer, (uint) count);
			if (result < 0) {			
				throw new ZipException("Could not write entry.");
			}
		}
		#endregion

		#region Stream stubs
		public override long Seek(long offset, SeekOrigin origin) {
			return 0;
		}

		public override void SetLength(long value) {

		}

		public override void Flush() {
			return;
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

lepipele
Chief Technology Officer
United States United States
If you liked this article, consider reading other articles by me. For republishing article on other websites, please contact me by leaving a comment.

Bitcoin wallet:
1ARXmh58S6aRiZPCbneDCzrB1HUU6PLmDQ

Blogs I enjoy:
http://blog.codinghorror.com/

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150723.1 | Last Updated 30 Mar 2012
Article Copyright 2008 by lepipele
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid