Click here to Skip to main content
15,894,646 members
Articles / Web Development / IIS

DotNetNuke Module Packager

Rate me:
Please Sign up or sign in to vote.
4.67/5 (13 votes)
21 Oct 200523 min read 162.6K   1.8K   82  
This article describes the DotNetNuke Module Packager application and source code. The application enables the user to generate DotNetNuke private assemblies that are useable out of the box from a custom module defined in the programmer's development environment.
//////////////////////////////////////////////////////////////////////////
// DNN Module Packager 1.0
// Copyright (C) 2004-2005 Matt Long
// 
// 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.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 
// You can contact the author at: matt.long@matthew-long.com
//
//////////////////////////////////////////////////////////////////////////

using System;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using System.IO;

namespace SkyeRoad.DNNTools
{
	/// <summary>
	/// Summary description for ZipUtility.
	/// </summary>
	public class ZipUtility
	{
		public ZipUtility()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public static void Compress( string outputFilePath, string folderPath )
		{
			if( !Directory.Exists( folderPath ) )
			{
				return;
			}
			DirectoryInfo di = new DirectoryInfo( folderPath );
			FileInfo[] fis = di.GetFiles();
			FileStream fZip =File.Create( outputFilePath );

			ZipOutputStream zipOStream = new ZipOutputStream(fZip);
			zipOStream.SetLevel(9);
            
			foreach(FileInfo fi in fis)
			{
				FileStream fs = File.OpenRead( fi.FullName );
                
				byte[] buffer = new byte[fs.Length];
				fs.Read(buffer , 0, buffer .Length);
				fs.Close();
                    
				ZipEntry entry = new ZipEntry((fi.Name));
				zipOStream.PutNextEntry(entry);
				zipOStream.Write(buffer , 0, buffer .Length);
				FileSystemEventArgs args = new FileSystemEventArgs( WatcherChangeTypes.Created, di.FullName, fi.Name );
			} 
			zipOStream.Finish();
			zipOStream.Close();
			fZip.Close();
		}

		public static void Extract(string zipFileName, string extractLocation, bool overWrite, bool createFolders)
		{
			string myExtractLocation = extractLocation;
			if (myExtractLocation == "")
				myExtractLocation = Directory.GetCurrentDirectory();
			if (!myExtractLocation.EndsWith("\\"))
				myExtractLocation = myExtractLocation + "\\";
			ZipInputStream s = new ZipInputStream(File.OpenRead(zipFileName));		
			ZipEntry theEntry;

			// Iterate through the list of files in the archive
			while ((theEntry = s.GetNextEntry()) != null) 
			{									

				string directoryName = "";
				string pathToZip = "";
				pathToZip = theEntry.Name;

				if (createFolders && (pathToZip != ""))
					directoryName = Path.GetDirectoryName(pathToZip) + "\\";
				string fileName = Path.GetFileName(pathToZip);
				Directory.CreateDirectory(myExtractLocation + directoryName);
				if (fileName != "")
				{
					// If the file exists and the overwrite flag is set to true, or the file 
					// doesn't exist, create the file.
					if ( (File.Exists(myExtractLocation + directoryName + fileName) && overWrite) ||
						(!File.Exists(myExtractLocation + directoryName + fileName)) )
					{

						FileStream streamWriter = File.Create(myExtractLocation + directoryName + fileName);			
						int size = 2048;
						byte[] data = new byte[2048];
						while (true) 
						{
							size = s.Read(data, 0, data.Length);
							if (size > 0) 
								streamWriter.Write(data, 0, size);
							else 
								break;
						}			
						streamWriter.Close();
						// Add the current file to the list of files created so they can be deleted
						// later.
					}
					else
						System.Console.WriteLine( "File Already Exists: \r\r" + 
							myExtractLocation + directoryName + fileName +
							"\r\rIgnoring File. . .");
				}
			}			
			s.Close();
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Matt Long is the Director of Technology for Skye Road Systems, Inc. in Colorado Springs, Colorado. He provides software architecture consulting services to small businesses. To contact Matt ( perlmunger ) send an email to matt@skyeroadsystems.com.

Comments and Discussions