Image Renamer Project

by Jeff Alexander 8. January 2010 00:38

Back when the .Net framework was just turning 1.1 I was asked to work on the first C# application by my employer which was mainly a C++ Win32 API shop. I was excited and read a couple C# books but I needed a project for it to really sink in. The quick project I started was a WinForms application to rename my digital photos. I was using a free utlity but wanted to make an application that did just what I wanted.

The reason I wanted to rename digital camera photos was that I bought a network enabled hard drive and started copying all my photos over to it and made a horrible mistake!!! It seems that at one point the photo counter on my digital camera was reset. So when I started to copy a very large list of photos over I was presented with the question do you want to replace ones with the same filename? I had just selected a huge list of photos and just assumed that one or two of them overlapped and figured I would just let those few get re-copied and said to replace. It wasn't until I watched the whole thing progress to 100% until I realized that I probably just lost a ton of pictures since they had the same filename. Ughh...

That's when I decided to start renaming all my photos so that it doesn't happen again. I take the EXIF data and put the date and time the photo was taken in front of the filename. That way if the IMG1234.jpg part overlaps the date, hour, minutes, seconds will not. The best side effect of that is that when you print your digital photos at a lab they put the filename on the back of the photo and you have a cool way to tell when you took the picutre. I wrote a whole blog post about it at AskTheAdmin.com.

The Project:

I found some code to read the EXIF and put together a little WinForms application with a listView a progress bar and a rename button. Worked fine. My EXIF reader was a little slow but who cares it works right? I was a nice starter application, I used it to put together a UI in WinForms, and write some threaded code to keep the UI from getting blocked on long rename's and overall it was a good experience.

Over time I've changed the thread code to use a BackgroundWorker to play around with how it works and I've changed around the EXIF reader a few times to make it faster and try new things as the .Net Framework added image support.

Updates Round 1:

It was kind of a pain to pop in the memory card out of the camera, copy it to the server and rename them. It wasn't horrible but it wasn't quick and easy. I thought about writing something that would register itself as a handler so that the auto play might bring up an option that would copy them from the card to the server for me but after some research it felt like a lot of work and I don't always have that much time. After some thought I decided one way to make it easier would be that if I could pop the SD card in and just copy them to the server and have Windows Home Server do the rest for me. In hindsight I think the amount of work to do that was probably the same.

To do this I wrote a Windows service to delpoy on my Windows Home Server that would watch a directory and rename any files that came in and move them to the photos directory. Pretty straight forward, the only gotcha was that a FileWatcher gives you a Create notify as soon as the file shows up but it still may be in the process of copying and you can't read it until it's done. I ended up writing a simple wait loop that would test if it could open for read and wait to process that until it could.

Now all I had to do was copy the files to the server and they were renamed.

Updates Round 2:

At this point I built my own Windows Home server was using that to store my photos but the folder for my photo's was large, I mean really large. When I was just storing them for backup I didn't care how many there were but my wife hated trying to navigate 1 huge folder on her little netbook. So I broke out the pictures by the year they were taken in which was pretty easy since the first part of each photo had the year. But now the renamer service needed to be updated.

I was storing the folder locations in the Resouces segment of the application and now I needed to update that. I wanted to be able to adjust my settings easily and have the year folder copy done automatically. I wanted to be able to configure the Windows service settings from the settings page in the Windows Home Server console rather than write a little configuration dialog for the renamer service.

I found a template for Windows Home Server Add-Ins and it was simple to write a settings tab. Next I broke out the Resouces to an external XML file that I store in CommonApplicationData and now both the service and the Windows Home Server settings page read and update that xml file.

Now I'm able to Start/Stop the Windows service, update the watch directory/output directory from the Home Server console anywhere. I can even upload files remotely and have them sorted to the right folder.

What's next?

  • WPF

I have never really used WPF and I am currently moving the Rename UI to be a WPF application. The first thing I did was to throw away the BackgroundWorker code since all I have to do is bind the listView to an ObservableCollection and the list updating is handled automatically.

  • Unit testing

I have never been required to write unit tests at work. I have done a little bit of Test Driven Desgin and used unit tests in my existing code but I want to really sit down and start using proper tests. I'll try to write myself a blog post about it later. (Since I'm most likely the only one reading this blog...)

  • Auto Play agent

I still want my wife to be able to pop in the memory card and have the handler give her an option to move the files to the server and if she isn't attached copy them locally. This will require looking into registering file formats with autoplay and showing here a nice little WPF application to do the copy.

  • Installer

If my Windows Home Server should fail I would have to manually install the Windows service and Home Server Add-In on re-install. It would be a good Idea to write a quick installer for the add-in. That way when I rebuild the server it will still be in the add-in folder and I can just re-activate it and configure it within the Home Server.

Conclusion:

If you still reading this wall of text I guess I should say thanks. If you have any interest in the source code or how I did anything post a comment or send me an email and I'll try to answer. And my advice to learning something new is to try to find a reason to use it and go through the process that way.

-Jeff

Tags: , , , ,

ImageRenamer | Projects

Welcome to Jeff In Madison .com

by Jeff Alexander 17. November 2009 19:16

You have most likely come to this site because of a link on my CV/Resume. After recently being laid off, I though it would be a good idea to put together a site to host my resume and to showcase some of my abilities. For the time being it will be a work in progress and I will be attempting to add what I can but for now I set up a BlogEngine.Net blog to easily add content and make changes.

- Jeff Alexander

Tags:

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen Modified by Jeff Alexander