<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Crows Programming &#187; General</title>
	<atom:link href="http://www.crowsprogramming.com/archives/category/general/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crowsprogramming.com</link>
	<description>Computer Programming and Random Blurbs</description>
	<lastBuildDate>Mon, 19 Sep 2011 20:53:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>List of Top Open Source Games</title>
		<link>http://www.crowsprogramming.com/archives/176</link>
		<comments>http://www.crowsprogramming.com/archives/176#comments</comments>
		<pubDate>Fri, 16 Sep 2011 03:47:55 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=176</guid>
		<description><![CDATA[Lately I’ve been compiling a list of the best open source games out on the Internet, partly just for new games to play and partly because I was thinking of contributing to one of the games. It’s amazing how many good quality open source games are available now days. I am Impressed. Anyway, I figured [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I’ve been compiling a list of the best open source games out on the Internet, partly just for new games to play and partly because I was thinking of contributing to one of the games. It’s amazing how many good quality open source games are available now days. I am Impressed. Anyway, I figured I would share my list so far with all of you. If you know of any other fun and interesting open source games be sure to let me know. So, without further ado, my top ten open source games:<br />
<span id="more-176"></span><br />
<br class="clear" /></p>
<table border="1">
<tr>
<td width="100%" bgcolor="#dddddd"><center><b>Secret Maryo Chronicles</b></center></td>
<td width="320px"><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/smc.png" /></td>
</tr>
<tr>
<td colspan="2">Type: 2D Platformer</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://www.secretmaryo.org/>http://www.secretmaryo.org</a></td>
</tr>
<tr>
<td colspan="2" width="100%">This is one of my favorites. A classic Mario type platform game including great art and a lot of fun. Now, if only the community was more active in developing new levels, enemy types, and game play mechanics. If nothing else you should give this game a try.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>Tremulous</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/tremulous.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: First Person Shooter</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://tremulous.net/>http://tremulous.net</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>0 A.D.</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/0ad.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: Real Time Strategy</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://wildfiregames.com/0ad/>http://wildfiregames.com/0ad</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>SuperTux</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/supertux.jpg" width="320" height="240" /></td>
</tr>
<tr>
<td colspan="2">Type: 2D Platformer</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://supertux.lethargik.org/>http://supertux.lethargik.org</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>Red Eclipse</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/redeclipse.png" width="320" height="240" /></td>
</tr>
<tr>
<td colspan="2">Type: First Person Shooter</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://www.redeclipse.net/>http://www.redeclipse.net</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>UFO: Alien Invasion</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/ufoai.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: Turn Based Strategy</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://ufoai.ninex.info>http://ufoai.ninex.info</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>Vertigo</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/vertigo.jpg" width="320" height="240" /></td>
</tr>
<tr>
<td colspan="2">Type: Action?</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://www.vertigo-game.com/>http://www.vertigo-game.com</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>Freeciv</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/freeciv.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: Strategy</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://freeciv.wikia.com>http://freeciv.wikia.com</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>Warzone 2100</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/Warzone2100.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: Real Time Strategy</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://wz2100.net/>http://wz2100.net</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td bgcolor="#dddddd"><center><b>World of Padman</b></center></td>
<td><img src="http://www.crowsprogramming.com/wp-content/uploads/2011/09/wop.jpg" /></td>
</tr>
<tr>
<td colspan="2">Type: First Person Shooter</td>
</tr>
<tr>
<td colspan="2">Download: <a href=http://worldofpadman.com/website/>http://worldofpadman.com/website/</a></td>
</tr>
<tr>
<td colspan="2">.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</table>
<p><br class="clear" /><br />
So that&#8217;s it, my list of the top 10 open source games. Do you know of any other great open source games? Do you, or have you, contributed to any open source games? If so, please share your experience here as it may help many people who don&#8217;t quite know how to get started.</p>
<fb:like href='http://www.crowsprogramming.com/archives/176' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/176/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is game programming</title>
		<link>http://www.crowsprogramming.com/archives/140</link>
		<comments>http://www.crowsprogramming.com/archives/140#comments</comments>
		<pubDate>Sat, 27 Aug 2011 22:31:39 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=140</guid>
		<description><![CDATA[What is game programming What is game programming? Well, I suppose game programming is a little bit of everything in the computer science world. Programming games is one part science, one part art, and one part fun (most of the time!). Programming games is much different than &#8220;normal&#8221; programming. Traditional business apps today are largely [...]]]></description>
			<content:encoded><![CDATA[<h3>What is game programming</h3>
<p>What is game programming? Well, I suppose game programming is a little bit of everything in the computer science world. Programming games is one part science, one part art, and one part fun (most of the time!). Programming games is much different than &#8220;normal&#8221; programming. Traditional business apps today are largely event-driven programs. In a game, you don&#8217;t wait for events. The game has to continually update the screen, check the network, respond to user input, run game logic, play audio, and many more things some 30 to 60 times a second. It&#8217;s quite a challenge, especially considering some games run on devices with constrained resources like a smart phone.<br />
<br class="clear" /><br />
If you are really interested in game programming, be warned, it&#8217;s a lot of work. It&#8217;s hard. But, it&#8217;s also very rewarding. There is something unique about watching your users &#8220;play&#8221; your software as opposed to watching your users &#8220;use&#8221; your program, so to speak. Anyway, I&#8217;ve provided an outline below if your interested in getting started with game programming.<br />
<br class="clear" /></p>
<h3>Getting Started</h3>
<p>The first thing you need to do is learn a programming language. A game can be programmed in just about any programming language. Some of the more popular ones are:</p>
<p><b>C/C++</b> &#8211; This is the traditional language (actually they are two distinct languages) used to program high performance games. Most of the AAA commercial games on PC, PS3, XBox, etc are programmed in C++ or C. Many people starting out consider these hard languages to learn and they are also considered the most costly to develop a game with. Check the links below for more information. </p>
<div style="background-color:#E6E6D8;">
<a href="http://www.cprogramming.com">www.cprogramming.com</a><br />
<a href="http://en.wikipedia.org/wiki/C_(programming_language)">en.wikipedia.org/wiki/C_(programming_language)</a><br />
<a href="http://www.cplusplus.com">www.cplusplus.com</a><br />
<a href="http://en.wikibooks.org/wiki/C++_Programming">en.wikibooks.org/wiki/C++_Programming</a>
</div>
<p><br class="clear" /></p>
<p>
<b>Java</b> &#8211; Java is a bit easier to learn when compared with C++ but you don’t <i>generally</i> get the same level of performance. I don’t know of a lot of commercial/successful games written in Java, although that may change soon with the proliferation of Android devices. If you are going to write a game on Android your most likely going to be using Java. If you know of any great Java games for the PC let me know! See the following links for more information about Java. </p>
<div style="background-color:#E6E6D8;">
<a href="http://en.wikipedia.org/wiki/Java_(programming_language)">en.wikipedia.org/wiki/Java_(programming_language)</a><br />
<a href="http://java.sun.com/docs/books/jls/">http://java.sun.com/docs/books/jls/</a><br />
<a href="http://www.javabeginner.com/">http://www.javabeginner.com/</a>
</div>
</p>
<p><br class="clear" /></p>
<p>
The list goes on: ActionScript for programming Flash games, python, C# (which you can use with the XNA Framework to create games for the XBox 360). Have a look at all of these languages and pick the one that makes the most since to you to start learning.</p>
<div style="background-color:#E6E6D8;">
<a href="http://www.actionscript.org/resources/articles/611/1/Getting-started-with-Actionscript-3/Page1.html">AS3</a><br />
<a href="http://www.python.org/">Python</a><br />
<a href="http://create.msdn.com/en-US/">XNA</a>
</div>
</p>
<p><br class="clear" /><br />
<span id="more-140"></span></p>
<h3>Data Structures and Algorithms</h3>
<p>
Next up, you will want to hit Wikipedia (or just search Google) and check out some of these data structures commonly used in video games. If you have taken any computer science classes in college, you most definitively are already comfortable with many of these structures/algorithms. The ones below are fundamental though and you should really get to know them inside and out. As a game programmer you will make use of these over and over again.</p>
<div style="background-color:#E6E6D8;">
<ul>
<li><a href="http://en.wikipedia.org/wiki/Linked_list">Linked List</a></li>
<li><a href="http://en.wikipedia.org/wiki/Stack_(data_structure)">Stack</a></li>
<li><a href="http://en.wikipedia.org/wiki/Hash_table">Hash Table</a></li>
<li><a href="http://en.wikipedia.org/wiki/Queue_(data_structure)">Queue</a></li>
<li><a href="http://en.wikipedia.org/wiki/Tree_(data_structure)">Tree</a></li>
</ul>
</div>
<p><br class="clear" /></p>
<h3>Specific Skills</h3>
<p>
You may want to think about some specific skills required in game programming as well. Think about which ones interest you the most or sound like they would be a lot of fun. A few of those skills would be:</p>
<div style="background-color:#E6E6D8;">
<ul>
<li>
<b>Graphics</b> &#8211; This is mostly concerned with getting stuff on the screen. There is a lot to it, especially when you are making 3D games. You have to think about how to store your data so it can be accessed fast when the game is running, how to quickly determine what things on the screen should be drawn, handle lighting, and lots of other things. You even get to write little programs called shaders that run directly on the video card! Graphics programming is a huge topic!
</li>
<p><br class="clear" /></p>
<li>
<b>Physics</b> &#8211; This is basically what you think it is. You program the rules that govern your game world. It can get very complicated though, just think about how you would do collision testing if you had 3,000 objects in your game world that all had to be tested against each other!
</li>
<p><br class="clear" /></p>
<li>
<b>Network</b> &#8211; Online multiplayer gaming is a huge thing these days and programming it correctly is not easy. Think about the scenario in which you have a server and several clients playing the game. You have to manage security so people can&#8217;t cheat, synchronize the game state for all players involved, manage the network bandwidth usage. And this is just a small glimpse into network game programming.
</li>
<p><br class="clear" /></p>
<li>
<b>AI</b> &#8211; Again, this one is straight forward. You get to program the brains for the game world &#8220;inhabitants&#8221;. Just getting an AI character to chase an enemy in a 3D environment is a pretty tough thing to do. How does the AI know where walls are? How does the AI know he can jump to get close to the player? Does the AI know he is low on health and should run away? Oh, the possibilities.
</li>
</ul>
</div>
<p>These are subjects people devote their entire careers to and they are not the only sub-disciplines in game programming. Lots of fun stuff there to explore if you&#8217;re interested.
</p>
<p><br class="clear" /></p>
<h3>The Fun Part</h3>
<p>
Now it’s time to just jump in head first. Start with a simple 2D game and have at it. Something like Pacman or Tetris might be appropriate. I would stay away from 3D games to start with. The number one thing is make sure <b>you finish the game</b>. It doesn’t matter how bad it is just <b>get it done</b> and <b>start small</b>. I would also stay away from things like OpenGL and DirectX when your starting out. They’re nice but they complicate things a lot. If you use say C++ for example, then you should check out SDL to handle audio, graphics, etc. Another possibility is to start out with Javascript and the new HTML5 canvas element.</p>
<p><br class="clear" /><br />
After you have that first game under your belt, you can have a look at the many open source games out there and try and contribute to a project. Heck, before you even finish your first game you should join an online game development community and get to know people. See what they are working on. Have fun, ya know? Check of the <a href="http://forums.tigsource.com">TigSource Forums</a>. That&#8217;s a great little online community focused on game development that&#8217;s very active. Oh yea, I believe the infamous game Minecraft began there as well.</p>
<p>One more thing, don&#8217;t be embarrassed by how awesome your programmer art is! <img src='http://www.crowsprogramming.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Programming games is fun, right?</p>
<p><br class="clear" /></p>
<h3>Conclusion</h3>
<p>So again, <b>what is game programming</b>? Glad you asked! Well, finish that first game and if you still like programming games then come back here and let me know!</p>
<p>Here are a few links to some helpful tools and websites:<br />
<br class="clear" /><br />
<a href="http://www.microsoft.com/express">Visual Studio</a> &#8211; You can use to program games in C++, C#, and more. There is a free edition.<br />
<a href="http://www.eclipse.org/">Eclipse</a> &#8211; Make games with Java (but handles many more langagues).<br />
<a href="http://www.libsdl.org/">SDL</a> &#8211; Helpful library for graphics, audio, etc so you can focus on your game!<br />
<a href="http://www.gamedev.net/">GameDev.Net</a> &#8211; Nice game development community.<br />
<a href="http://www.gamasutra.com/">Gamasutra</a> &#8211; Another nice game development community.<br />
<a href="http://create.msdn.com/en-US/">XNACreatersClub</a> &#8211; For Xbox360 development (although PC, Windows Phone also included).<br />
<br class="clear"/></p>
<fb:like href='http://www.crowsprogramming.com/archives/140' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/140/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I&#8217;m Back</title>
		<link>http://www.crowsprogramming.com/archives/91</link>
		<comments>http://www.crowsprogramming.com/archives/91#comments</comments>
		<pubDate>Thu, 16 Jul 2009 02:58:14 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=91</guid>
		<description><![CDATA[Hey guys, sorry I&#8217;ve been away for a bit. I&#8217;ll try and respond to your questions, especially those over on the C# dynamic web service page. I&#8217;ll be adding a whole lot of new content as well. If anyone has any suggestions on a topic feel free to leave them for me. See Ya!!]]></description>
			<content:encoded><![CDATA[<p>Hey guys, sorry I&#8217;ve been away for a bit. I&#8217;ll try and respond to your questions, especially those over on the <a href="http://www.crowsprogramming.com/archives/66">C# dynamic web service page</a>.</p>
<p>I&#8217;ll be adding a whole lot of new content as well. If anyone has any suggestions on a topic feel free to leave them for me.</p>
<p>See Ya!!</p>
<fb:like href='http://www.crowsprogramming.com/archives/91' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/91/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Extract A Zip File With C#</title>
		<link>http://www.crowsprogramming.com/archives/50</link>
		<comments>http://www.crowsprogramming.com/archives/50#comments</comments>
		<pubDate>Fri, 03 Apr 2009 05:49:51 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=50</guid>
		<description><![CDATA[The .Net Framework Class Libraries are great and allow you to manipulate many different file formats. Unfortunately they seemed to have left out support for standard Zip files. Thankfully our good friends over at ICSharpCode have released an awesome little library for handling Zip files called the SharpZipLib. The library is very simple to use [...]]]></description>
			<content:encoded><![CDATA[<p>The .Net Framework Class Libraries are great and allow you to manipulate many different file formats. Unfortunately they seemed to have left out support for standard Zip files. Thankfully our good friends over at <a href=http://www.icsharpcode.net/> ICSharpCode</a> have released an awesome little library for handling Zip files called the SharpZipLib.</p>
<p>The library is very simple to use and supports several formats including:</p>
<ul>
<li> Zip </li>
<li> GZip </li>
<li> Tar </li>
<li> BZip2 </li>
</ul>
<h2>Using SharpZipLib </h2>
<p>Extracting a file with SharpZipLib is really quite simple. First you create a ZipInputStream from an existing FileStream to the zip file.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ZipInputStream zinstream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ZipInputStream<span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenRead</span><span style="color: #008000;">&#40;</span>source<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Next you read the entries from the zip file, which could be either a file or directory.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ZipEntry theEntry<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>theEntry <span style="color: #008000;">=</span> zinstream<span style="color: #008000;">.</span><span style="color: #0000FF;">GetNextEntry</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">// if theEntry is a directory then create it on disk</span>
   <span style="color: #008080; font-style: italic;">// otherwise it’s a file so read from zinstream just like</span>
   <span style="color: #008080; font-style: italic;">// you would any other file</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The ZipEntry represents either a file or directory that must be read and reproduced in the target directory where you are extracting the files to. GetNextEntry will continue to return either the next directory or the next file in the Zip file until no more exist. Here is a complete example of extracting all files (while maintaining directory structure) to a local folder.</p>
<h2>The Extraction Function</h2>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> ExtractAll<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> source, <span style="color: #6666cc; font-weight: bold;">string</span> destination<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            ZipInputStream zinstream <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// used to read from the zip file</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> numFileUnzipped <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// number of files extracted from the zip file</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// create a zip input stream from source zip file</span>
                zinstream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ZipInputStream<span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenRead</span><span style="color: #008000;">&#40;</span>source<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// we need to extract to a folder so we must create it if needed</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>destination<span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span>
                    Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateDirectory</span><span style="color: #008000;">&#40;</span>destination<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                ZipEntry theEntry<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// an entry in the zip file which could be a file or directory</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// now, walk through the zip file entries and copy each file/directory</span>
                <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>theEntry <span style="color: #008000;">=</span> zinstream<span style="color: #008000;">.</span><span style="color: #0000FF;">GetNextEntry</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">string</span> dirname <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDirectoryName</span><span style="color: #008000;">&#40;</span>theEntry<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// the file path</span>
                    <span style="color: #6666cc; font-weight: bold;">string</span> fname   <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFileName</span><span style="color: #008000;">&#40;</span>theEntry<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>      <span style="color: #008080; font-style: italic;">// the file name</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// if a path name exists we should create the directory in the destination folder</span>
                    <span style="color: #6666cc; font-weight: bold;">string</span> target <span style="color: #008000;">=</span> destination <span style="color: #008000;">+</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectorySeparatorChar</span> <span style="color: #008000;">+</span> dirname<span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>dirname<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> 
                        Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateDirectory</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// now we know the proper path exists in the destination so copy the file there</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>fname <span style="color: #008000;">!=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        DecompressAndWriteFile<span style="color: #008000;">&#40;</span>destination <span style="color: #008000;">+</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectorySeparatorChar</span> <span style="color: #008000;">+</span> theEntry<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, zinstream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        numFileUnzipped<span style="color: #008000;">++;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">finally</span>
            <span style="color: #008000;">&#123;</span>
                zinstream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> numFileUnzipped<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>And the DecompressAndWrite method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> DecompressAndWriteFile<span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">string</span> destination, ZipInputStream source <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            FileStream wstream <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// create a stream to write the file to</span>
                wstream <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>destination<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> block <span style="color: #008000;">=</span> <span style="color: #FF0000;">2048</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// number of bytes to decompress for each read from the source</span>
&nbsp;
                <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>block<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// location to decompress the file to</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// now decompress and write each block of data for the zip file entry</span>
                <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">int</span> size <span style="color: #008000;">=</span> source<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span>data, <span style="color: #FF0000;">0</span>, data<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>size <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                        wstream<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>data, <span style="color: #FF0000;">0</span>, size<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">else</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// no more data</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span><span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">finally</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span> wstream <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span>
                    wstream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Pretty neat huh? I love how simple it is.<br />
If those methods are placed into a class called Zip, then extracting a Zip file is as easy as:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Zip<span style="color: #008000;">.</span><span style="color: #0000FF;">ExtractAll</span><span style="color: #008000;">&#40;</span>myZipFile, myDestinationFolder<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>I’ve put together a sample project that uses the SharpZipLib to extract the contents of a zip file. It basically just allows you to select the zip file and the destination from a form and uses the methods above. You can find it below.</p>
<p><a href="http://www.crowsprogramming.com/wp-content/uploads/2009/04/zipfileexample.zip">DOWNLOAD SAMPLE APPLICATION</a></p>
<p>Let me know if you find this useful or need any help!!!</p>
<fb:like href='http://www.crowsprogramming.com/archives/50' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/50/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Documentation Template Via Visual Studio Macro</title>
		<link>http://www.crowsprogramming.com/archives/40</link>
		<comments>http://www.crowsprogramming.com/archives/40#comments</comments>
		<pubDate>Thu, 02 Apr 2009 06:50:51 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=40</guid>
		<description><![CDATA[Consistency is the key when working on computer software, especially if you are developing a large system with multiple programmers. You should be consistent with the layout and format of your source code. Unfortunately this can be difficult to achieve when time is precious – and isn’t it always. However Visual Studios macro system makes [...]]]></description>
			<content:encoded><![CDATA[<p>Consistency is the key when working on computer software, especially if you are developing a large system with multiple programmers. You should be consistent with the layout and format of your source code. Unfortunately this can be difficult to achieve when time is precious – and isn’t it always. However Visual Studios macro system makes it a breeze to automate this task with little to no work. Here is a simple way to implement this in C#.</p>
<p>What I would like to be able to do is execute a simple macro and see a dialog box that lets me enter information specific to the source file I am working with. That information will then be inserted into the file using a predefined template. The dialog will look something like this: </p>
<p><img src="http://www.crowsprogramming.com/wp-content/uploads/2009/04/templatedialog.png" /></p>
<p>To accomplish this task we need to things; a .Net class library that implements the dialog and the macro to launch it and interact with Visual Studio using its automation model.<br />
<span id="more-40"></span><br />
Creating the dialog is easy.  Simply create a class library in the .Net language of your choice and add a form to it. Then make sure it has public properties that contain the information entered by the user so the macro can consume it. Once you have built your library you will have a .DLL file. This file needs to be copied to:<br /> “C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies” <br />for Visual Studio 2008. For earlier versions the location will be similar. This will make your dialog type available to your macro.</p>
<p>Next comes the macro. To do this open the Macros IDE using Tools->Macros->Macros IDE. Right click MyMacros in the IDE and select Add->New Module. Name the new module AutoDocCSharpSourceFile. Right click MyMacros again and select add reference. Add a reference to your class library. In your new macro add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Text.RegularExpressions
&nbsp;
<span style="color: #E56717; font-weight: bold;">Public</span> Module AutoDocCSharpSourceFile
    <span style="color: #E56717; font-weight: bold;">Sub</span> AutoDocCSharpSourceFile()
        <span style="color: #008000;">' This is the main entry point for the macro
</span>        <span style="color: #008000;">' it will automatically document the c# source file selected
</span>        <span style="color: #008000;">' by the user in the custom dialog using the custom template
</span>        <span style="color: #008000;">' This should be used on new files only as it will not retain the
</span>        <span style="color: #008000;">' existing code
</span>
        <span style="color: #008000;">' note that we only acknowlege Windows line endings (carrige return/line feed)
</span>        <span style="color: #008000;">' if your source file is using a LF only you will have to replace all &quot;\r\n&quot; with &quot;\n&quot;
</span>
        <span style="color: #008000;">' also there is no error handling. You can catch any exceptions thrown and handle them
</span>        <span style="color: #008000;">' nicely or you can just let Visual Studio catch them and show them to you
</span>
        <span style="color: #008000;">' make sure Visual Studio has a document open... of course this may not be a C# file
</span>        <span style="color: #8D38C9; font-weight: bold;">If</span> DTE.ActiveDocument <span style="color: #8D38C9; font-weight: bold;">Is</span> <span style="color: #00C2FF; font-weight: bold;">Nothing</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
            MsgBox(<span style="color: #800000;">&quot;Cannot Continue Because No Documents Are Open&quot;</span>, MsgBoxStyle.OkOnly)
            Return
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #008000;">' first grab the text for the entire source file
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> sel <span style="color: #151B8D; font-weight: bold;">As</span> TextSelection = DTE.ActiveDocument.Selection
        sel.SelectAll()
        <span style="color: #151B8D; font-weight: bold;">Dim</span> documentText <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> = sel.Text
&nbsp;
        <span style="color: #008000;">' now extract the namespace name and the class name so
</span>        <span style="color: #008000;">' we can populate the dialog for the user
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> namespaceName <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> = GetNamespaceName(documentText)
        <span style="color: #151B8D; font-weight: bold;">Dim</span> className <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> = GetClassName(documentText)
&nbsp;
        <span style="color: #008000;">' display the dialog, the user can enter source file specific information
</span>        <span style="color: #008000;">' such as the file description or rename the class etc...
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> dialog <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> AutoTemplateDialog.AutoTemplateDialog(className, namespaceName)
        dialog.TopLevel = <span style="color: #00C2FF; font-weight: bold;">True</span>
        dialog.ShowDialog()
        dialog.Focus()
&nbsp;
        <span style="color: #008000;">' exit if user hit cancel
</span>        <span style="color: #8D38C9; font-weight: bold;">If</span> dialog.DialogResult = System.Windows.Forms.DialogResult.Cancel <span style="color: #8D38C9; font-weight: bold;">Then</span>
            sel.StartOfDocument()
            dialog.Dispose()
            Return
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
        namespaceName = dialog.NamespaceName
        className = dialog.ClassName
&nbsp;
        <span style="color: #008000;">' we no longer need the contents of the source file
</span>        sel.Delete(sel.Text.Length)
        sel.StartOfDocument()
&nbsp;
        <span style="color: #008000;">' now insert the template documentation
</span>        GenFileDescription(dialog.Description)
        GenUsingStatements(documentText)
        GenFile(className, namespaceName, documentText)
&nbsp;
        dialog.Dispose() <span style="color: #008000;">' it seems visual studio prevents automatic disposal?
</span>        <span style="color: #008000;">' strange behavior results after a while if this isn't done
</span>    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Sub</span> GenFileDescription(<span style="color: #151B8D; font-weight: bold;">ByVal</span> desc <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>)
        <span style="color: #008000;">' This will generate the file description that goes at the top of
</span>        <span style="color: #008000;">' the source file
</span>        <span style="color: #008000;">' desc - A text description of the source file that will be inserted
</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> fileDescription <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> <span style="color: #008000;">' the file description that goes into the description tag
</span>
        <span style="color: #8D38C9; font-weight: bold;">If</span> desc = <span style="color: #F660AB; font-weight: bold;">String</span>.<span style="color: #00C2FF; font-weight: bold;">Empty</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
            fileDescription = <span style="color: #800000;">&quot;//&quot;</span> + Environment.NewLine
        <span style="color: #8D38C9; font-weight: bold;">Else</span>
            <span style="color: #008000;">' split the description into seperate lines so that we can add them into single line comments
</span>            <span style="color: #151B8D; font-weight: bold;">Dim</span> lines <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>() = Regex.Split(desc, <span style="color: #800000;">&quot;\r\n&quot;</span>)
&nbsp;
            <span style="color: #008000;">' comment each description line
</span>            <span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> <span style="color: #151B8D; font-weight: bold;">line</span> <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> <span style="color: #8D38C9; font-weight: bold;">In</span> lines
                fileDescription += (<span style="color: #800000;">&quot;//     &quot;</span> + <span style="color: #151B8D; font-weight: bold;">line</span> + Environment.NewLine)
            <span style="color: #8D38C9; font-weight: bold;">Next</span>
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #008000;">' now insert the header template
</span>        DTE.ActiveDocument.Selection.Insert( _
            <span style="color: #800000;">&quot;#region File Description&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//------------------------------------------------------------------------------&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;// &lt;file&gt;&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//     &quot;</span> &amp; DTE.ActiveDocument.Name &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;// &lt;/file&gt;&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;// &lt;description&gt;&quot;</span> &amp; vbNewLine &amp; _
                  fileDescription &amp; _
            <span style="color: #800000;">&quot;// &lt;/description&gt;&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;// &lt;copyright file=&quot;</span><span style="color: #800000;">&quot;&quot;</span> &amp; DTE.ActiveDocument.Name &amp; <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot; company=&quot;</span><span style="color: #800000;">&quot;My Company&quot;</span><span style="color: #800000;">&quot;&gt;&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//     Copyright (c) 2009 My Company Inc. All rights reserved.&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;// &lt;/copyright&gt;&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;//------------------------------------------------------------------------------&quot;</span> &amp; vbNewLine &amp; _
            <span style="color: #800000;">&quot;#endregion&quot;</span> &amp; vbNewLine &amp; vbNewLine)
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Sub</span> GenUsingStatements(<span style="color: #151B8D; font-weight: bold;">ByVal</span> documentText <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>)
        <span style="color: #008000;">' This will extract the using statements and wrap them
</span>        <span style="color: #008000;">' in a region
</span>        <span style="color: #008000;">' documentText is the body of the source file
</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> mc <span style="color: #151B8D; font-weight: bold;">As</span> MatchCollection <span style="color: #008000;">' holds matches to the regular expression
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> ex <span style="color: #151B8D; font-weight: bold;">As</span> Regex <span style="color: #008000;">' regular expression for finding the using statements
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> nl <span style="color: #151B8D; font-weight: bold;">As</span> Regex <span style="color: #008000;">' holds maches for new lines
</span>
        <span style="color: #008000;">' find all using statements
</span>        ex = <span style="color: #E56717; font-weight: bold;">New</span> Regex(<span style="color: #800000;">&quot;using&quot;</span>)
        nl = <span style="color: #E56717; font-weight: bold;">New</span> Regex(<span style="color: #800000;">&quot;\n&quot;</span>)
&nbsp;
        mc = ex.Matches(documentText)
&nbsp;
        <span style="color: #008000;">' start new region in source file
</span>        DTE.ActiveDocument.Selection.Insert(<span style="color: #800000;">&quot;#region Using Statements&quot;</span> &amp; vbNewLine)
&nbsp;
        <span style="color: #008000;">' now place each using statement in the region
</span>        <span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> m <span style="color: #151B8D; font-weight: bold;">As</span> Match <span style="color: #8D38C9; font-weight: bold;">In</span> mc
            <span style="color: #151B8D; font-weight: bold;">Dim</span> x <span style="color: #151B8D; font-weight: bold;">As</span> Match = nl.Match(documentText.Substring(m.Index)) <span style="color: #008000;">'end statement at newline
</span>
            <span style="color: #8D38C9; font-weight: bold;">If</span> x.Success <span style="color: #8D38C9; font-weight: bold;">Then</span>
                DTE.ActiveDocument.Selection.Insert(documentText.Substring(m.Index, x.Index))
            <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
        <span style="color: #8D38C9; font-weight: bold;">Next</span>
&nbsp;
        <span style="color: #008000;">' close off the region
</span>        DTE.ActiveDocument.Selection.Insert(<span style="color: #800000;">&quot;#endregion&quot;</span> &amp; vbNewLine &amp; vbNewLine)
&nbsp;
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Function</span> GetNamespaceName(<span style="color: #151B8D; font-weight: bold;">ByVal</span> documentText <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>
        <span style="color: #008000;">' finds the root namespace defined in the document and returns it
</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> mc <span style="color: #151B8D; font-weight: bold;">As</span> Match <span style="color: #008000;">' matches in regular expression
</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> ex <span style="color: #151B8D; font-weight: bold;">As</span> Regex
        <span style="color: #151B8D; font-weight: bold;">Dim</span> nl <span style="color: #151B8D; font-weight: bold;">As</span> Regex
&nbsp;
        <span style="color: #008000;">' use regular expression to find the namespace name
</span>        ex = <span style="color: #E56717; font-weight: bold;">New</span> Regex(<span style="color: #800000;">&quot;namespace[^\r\n]*&quot;</span>)
&nbsp;
        mc = ex.Match(documentText)
&nbsp;
        <span style="color: #008000;">' return result
</span>        <span style="color: #8D38C9; font-weight: bold;">If</span> mc.Success <span style="color: #8D38C9; font-weight: bold;">Then</span>
            Return mc.Value.Substring(10) <span style="color: #008000;">' using 10 will create a 
</span>            <span style="color: #008000;">' a problem if anything comes
</span>            <span style="color: #008000;">' before the namespace keyword
</span>        <span style="color: #8D38C9; font-weight: bold;">Else</span>
            Return <span style="color: #800000;">&quot;&quot;</span>
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Function</span> GetClassName(<span style="color: #151B8D; font-weight: bold;">ByVal</span> documentText <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>
        <span style="color: #008000;">' finds the class name defined in the document
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> mc <span style="color: #151B8D; font-weight: bold;">As</span> Match
&nbsp;
        <span style="color: #151B8D; font-weight: bold;">Dim</span> ex <span style="color: #151B8D; font-weight: bold;">As</span> Regex
        <span style="color: #151B8D; font-weight: bold;">Dim</span> nl <span style="color: #151B8D; font-weight: bold;">As</span> Regex
&nbsp;
        <span style="color: #008000;">' use a regular expression just as in finding the namespace name
</span>        ex = <span style="color: #E56717; font-weight: bold;">New</span> Regex(<span style="color: #800000;">&quot;class[^\r\n]*&quot;</span>)
&nbsp;
        mc = ex.Match(documentText)
&nbsp;
        <span style="color: #8D38C9; font-weight: bold;">If</span> mc.Success <span style="color: #8D38C9; font-weight: bold;">Then</span>
            Return mc.Value.Substring(6)
        <span style="color: #8D38C9; font-weight: bold;">Else</span>
            Return <span style="color: #800000;">&quot;&quot;</span>
        <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Sub</span> GenFile(<span style="color: #151B8D; font-weight: bold;">ByVal</span> className <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> namespaceName <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> documentText <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>)
        <span style="color: #008000;">' now we will generate the body of the source file
</span>
        <span style="color: #008000;">' insert initial class and namespace declaration
</span>        DTE.ActiveDocument.Selection.Insert(<span style="color: #800000;">&quot;namespace &quot;</span> &amp; namespaceName &amp; vbNewLine &amp; <span style="color: #800000;">&quot;{&quot;</span> &amp; vbNewLine &amp; vbTab &amp; <span style="color: #800000;">&quot;public class &quot;</span> &amp; className &amp; vbNewLine &amp; vbTab &amp; <span style="color: #800000;">&quot;{&quot;</span> &amp; vbNewLine)
&nbsp;
        <span style="color: #008000;">' insert the regions of the body
</span>        InsertRegion(<span style="color: #800000;">&quot;Properties&quot;</span>)
        InsertRegion(<span style="color: #800000;">&quot;Events&quot;</span>)
        InsertRegion(<span style="color: #800000;">&quot;Constructors&quot;</span>)
        InsertRegion(<span style="color: #800000;">&quot;Public Methods&quot;</span>)
        InsertRegion(<span style="color: #800000;">&quot;Private Methods&quot;</span>)
        InsertRegion(<span style="color: #800000;">&quot;Fields&quot;</span>)
&nbsp;
        <span style="color: #008000;">' close namespace and class
</span>        DTE.ActiveDocument.Selection.Insert(vbTab &amp; <span style="color: #800000;">&quot;}&quot;</span> &amp; vbNewLine &amp; <span style="color: #800000;">&quot;}&quot;</span>)
&nbsp;
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Sub</span> InsertRegion(<span style="color: #151B8D; font-weight: bold;">ByVal</span> name <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>)
        <span style="color: #008000;">' just a helper routine to add a region statment to the source file
</span>        DTE.ActiveDocument.Selection.Insert(vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;#region &quot;</span> &amp; name &amp; vbNewLine &amp; vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;#endregion&quot;</span> &amp; vbNewLine &amp; vbNewLine)
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> Module</pre></div></div>

<p>The macro is pretty straight forward with lots of documentation. It primarily is using the EnvDTE80.DTE2 class to interact with Visual Studio and write the source template.</p>
<p>Once you have saved the macro you can execute it by opening the Macro Explorer and running the AutoDocCSharpSourceFile macro. If you want you can also bind it to a key combination so you don’t have to use the explorer. You can accomplish this using the options dialog from the tools menu.</p>
<p>When you run the macro you should see a file header that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080;">#region File Description</span>
<span style="color: #008080; font-style: italic;">//------------------------------------------------------------------------------</span>
<span style="color: #008080; font-style: italic;">// &lt;file&gt;</span>
<span style="color: #008080; font-style: italic;">//     Program.cs</span>
<span style="color: #008080; font-style: italic;">// &lt;/file&gt;</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// &lt;description&gt;</span>
<span style="color: #008080; font-style: italic;">//     This is a TEST!</span>
<span style="color: #008080; font-style: italic;">// &lt;/description&gt;</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// &lt;copyright file=&quot;Program.cs&quot; company=&quot;My Company&quot;&gt;</span>
<span style="color: #008080; font-style: italic;">//     Copyright (c) 2009 My Company Inc. All rights reserved.</span>
<span style="color: #008080; font-style: italic;">// &lt;/copyright&gt;</span>
<span style="color: #008080; font-style: italic;">//------------------------------------------------------------------------------</span>
<span style="color: #008080;">#endregion</span></pre></div></div>

<p>And several regions reserved for specific C# constructs. The one issue with the current implementation is that it only preserves a single class name, the namespace name, and the using directives. Anything else in the file is lost.  I’ve also noticed a now and then on Vista the dialog appears behind Visual Studio, if that’s the case just alt-tab to get it back.</p>
<p>I Hope this proves helpful to you and saves you some time. I would love to hear feedback on any issues or improvements that could be made. </p>
<p><a href="http://www.crowsprogramming.com/wp-content/uploads/2009/04/autotemplatedialog.zip">Here is my Visual Studio solution that implements the dialog window as well as the VB script macro.</a></p>
<fb:like href='http://www.crowsprogramming.com/archives/40' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/40/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WP-Syntax Test</title>
		<link>http://www.crowsprogramming.com/archives/10</link>
		<comments>http://www.crowsprogramming.com/archives/10#comments</comments>
		<pubDate>Sun, 08 Feb 2009 06:59:06 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=10</guid>
		<description><![CDATA[Just wanted to check out the WP-Syntax plugin and see how it works/looks. &#160; #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; &#160; int main&#40; void &#41; &#123; printf&#40; &#34;HELLO WP-Syntax\n&#34; &#41;; &#160; return 0; &#125;]]></description>
			<content:encoded><![CDATA[<p>Just wanted to check out the WP-Syntax plugin and see how it works/looks.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">&quot;HELLO WP-Syntax<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<fb:like href='http://www.crowsprogramming.com/archives/10' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/10/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Welcome!!</title>
		<link>http://www.crowsprogramming.com/archives/7</link>
		<comments>http://www.crowsprogramming.com/archives/7#comments</comments>
		<pubDate>Fri, 06 Feb 2009 06:57:19 +0000</pubDate>
		<dc:creator>crow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.crowsprogramming.com/?p=7</guid>
		<description><![CDATA[Welcome to Crows Programming! This site is dedicated to my various rants and raves, mostly related to computer programming and related technologies. I look forward to hearing feedback from all of you on my thoughts and ideas! ~Crow&#8211;]]></description>
			<content:encoded><![CDATA[<p>Welcome to Crows Programming!</p>
<p>This site is dedicated to my various rants and raves, mostly related to computer programming and related technologies.</p>
<p>I look forward to hearing feedback from all of you on my thoughts and ideas!</p>
<p>~Crow&#8211;</p>
<fb:like href='http://www.crowsprogramming.com/archives/7' send='false' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.crowsprogramming.com/archives/7/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

