How to remove SVN metadata using PowerShell

Recently I decided to write a PowerShell script that will delete all directories named ".svn" from given directory and all subdirectories (which effectively removes all SVN metadata). On the Stack Overflow website I've found a command which will do what I need:

Get-ChildItem $path -Recurse -Force *.svn |
    Where {$_.PSIsContainer} | Remove-Item -Recurse -Force

And what turned out? The result of its execution is correct, but PowerShell displays ugly error messages by the way:

PowerShell: Remove-SvnMetadata

To get rid of these errors, I recommend using two subsequent commands:

$itemsToRemove = Get-ChildItem $path -Recurse -Force .svn |
    Where {$_.PSIsContainer}
$itemsToRemove | Remove-Item -Recurse -Force

Of course, these commands can be put into a script file which will take the directory path as a parameter. To do this, you should create a file named for example Remove-SvnMetadata.ps1 with the following content:

$itemsToRemove = Get-ChildItem $args[0] -Recurse -Force .svn |
    Where {$_.PSIsContainer}
$itemsToRemove | Remove-Item -Recurse -Force

To use the script, you should place it in a directory that is present in your PATH environment variable (I use C:\Users\BlaSOFT\scripts) or just in PowerShell console go to directory containing the script (then before the script name you should put .\). This is an example call which will remove all SVN metadata from D:\Temp\20110507 directory and all its subdirectories:

Remove-SvnMetadata.ps1 D:\Temp\20110507

I would like to say that I am also aware of the existance of Export function in SVN (svn export), but the solution I presented allows us to do the task even if we don't have any SVN client available in the system (or we don't want to use SVN for some reason).

How to "fix" Power Manager gadget after IE9 installation

In my previous post I wrote that after IE9 installation on my laptop, the transparency of Lenovo Thinkpad PowerManager gadget was broken down. Some time passed from that moment, meanwhile Lenovo released an PowerManager update, but the gadget still doesn't work properly. Because of that, I decided to fix the problem myself.

After some experimenting, I found the reason of broken transparency and figured out a way to bypass the problem. It turned out that the bug is not in the gadget, but in Internet Explorer. Installation of IE9 introduces the following bug. After every value assignment to, the PNG background transparency is toggled on/off. Knowing exactly where the bug is I prepared a small, step-by-step tutorial on how to fix the gadget on our own:

  1. Create some temporary working folder (in my case it was D:\Temp)
  2. Copy PWRMGR.JS file into the temp folder. The file can be found in the gadget folder (in my case it's C:\Program Files\Windows Sidebar\Gadgets\PowerManager.Gadget\EN-US)
  3. From download the scrdec18.exe tool and save it in the temp working folder
  4. Open Command Prompt in the temp folder. It can be done for example by holding Shift key, right clicking somewhere in the Windows Explorer window (but not on a file icon) and selecting the "Open command window here" option
  5. Decode the PWRMGR.JS, file by issuing the following command:
    scrdec18 pwrmgr.js pwrmgr_dec.js
  6. Open the decoded file - pwrmgr_dec.js - in some text editor (i.e. Notepad++)
  7. Find the resizeView() function
  8. Inside that function, replace every occurance of
    with =

    The replacing will be necessary in 3 places, totally. Then, we save the changes, of course.

  9. Delete file PWRMGR.JS from the temp directory. Next, rename pwrmgr_dec.js into PWRMGR.JS
  10. From our temp working directory, copy PWRMGR.JS file into the folder from whick we took its original version. (in my case it's C:\Program Files\Windows Sidebar\Gadgets\PowerManager.Gadget\EN-US). Allow overwriting the file.
  11. We're done! For the changes to be visible we now have to restart the sidebar.exe process. It can be done for example by logging out and logging in again. Instead of that I recomend to issue the following command in the Command Prompt:
    tskill sidebar && "%programfiles%\Windows Sidebar\sidebar.exe"

Of course, after performing all the above steps we are free to delete the temporary working directory.

How to use TFS 2010 without launching VS 2010

Visual Studio 2010 is a very demanding IDE, as far as hardware requirements are concerned. Due to that fact, its usability on low-end machines (e.g. netbooks) is seriously limited. However, sometimes we might need to use such kind of "weakly equipped" computer to work on some project which is developed with Visual Studio 2010 and Team Foundation Server 2010. In this post I will show you how to do the following activities without the need of launching the whole Visual Studio IDE:

  1. Download latest versions of project files from the TFS
  2. Edit one of the files using an editor with syntax highliting
  3. Upload modified file to the TFS

To do this, in fact we need to perform the following steps:

  1. Create a new workspace
  2. Get the latest versions of project files
  3. Check Out a file
  4. Modify a file
  5. Check In the modified file

We won't launch Visual Studio, but it has to be installed on our machine. Further description is based on the following configuration:

TFS address: http://tfs-server:8080/tfs
Project Collection name: DefaultCollection
Team Project name: TeamProject1
Source Control project directory: $/TeamProject1

So let's begin. We will use tf command-line utility, which was installed along with VS IDE.  First, we have to open Visual Studio Command Prompt, which can be found in Start Menu.

Then, we create a new folder and change current dir to that folder:

Now, we create a new TFS workspace and name it TeamProject1Workspace:

tf workspace /new ^
  /s:http://tfs-server:8080/tfs/DefaultCollection/ TeamProject1Workspace

It might be necessary to enter our TFS credentials:

Next, we can verify displayed settings and click OK:

Finally, we are able to get latest versions of TeamProject1 files which are stored in Source Control:

tf get TeamProject1 /recursive

After downloading, all files have "read only" attribute set, because they shouldn't be modified before they're checked out. Now we may enter the directory which contains file we want to edit:

We perform Check Out:

tf checkout Program.cs

Now we can open and modify this file, for example using the free and lightweight Notepad++ text editor:

After making some modifications, we save changes and close the editor. Now, we perform Check In:

tf checkin Program.cs

And that's it! We're done :)

If we would like to work on the same team project in future, we won't need to create new TFS workspace. We can just use tha one that was created before. However, before starting our work I recommend downloading latest versions of files with tf get some_path /recursive command.

On the other hand, if we're not going to work on this project (using the same computer) any more, we are free to delete the TFS workspace and remove the working directory along with it's content:

tf workspace /delete TeamProject1Workspace

What is TIC and how to use it?

Sorry, this post is available only in Polish.

Microsoft Visual Studio 2008 - first steps

Some time ago, I've noticed that many novice C++ programmers still use obsolete Dev-C++ IDE, which is in my opinion quite uncomfortable and buggy. I wonder why they won't try something else, e.g. Code::Blocks or... Microsoft Visual Studio. I think it's one of the best IDEs for Windows. At first glance, one might feel a bit overwhelmed with the huge number of features it offers. The truth is that when one learns the basics, VS appears to be very easy and convenient in use. To prove it, I've written the short step-by-step tutorial showing how to compile the simpliest "Hello World" program with Visual Studio 2008:

  1. Choose File --> New --> Project...
  2. Select  Win32 Console Application template and click OK.
  3. Click Next.
  4. Deselect Precompiled header option and click Finish.
  5. Go to Solution Explorer. If it isn't shown by default, you can make it visible by choosing View --> Solution Explorer menu option. Then delete the following files: stdafx.h, targetver.h, stdafx.cpp and ReadMe.txt .
  6. There should be only one .cpp file left. Its default content looks like this:

    We will make it simplier by removing fragments marked red:

    // HelloWorld.cpp : Defines the entry point for the console application.
    #include "stdafx.h"
    int _tmain(int argc, _TCHAR* argv[])
        return 0;

    So the modified code is:

    int main()
        return 0;
  7. Now you can type some simple C/C++ code and press F5 to compile and run the application.
As you can see, Visual Studio is not so scary and I'm sure that every programmer (even beginner) can successfully use it. So why won't you have a try?