Manage Your Comic Book Collection with CLibrary
As Seth Cohen said "Life's gritty enough.
Comic books are for fun."
I'll admit it. I have the taste of a 14yr old. I watch the O.C. and I'm starting to read comic books again. Or lets just call them graphic novels to preserve some dignity. Two problems though. They get ruined easily and they're a pain to carry around. One way to get around this is too scan them and archive them in zip or rar files. There's a nice image viewing application called CDisplay to view the digital comics. I also found another great app for the mac called ComicBookLover. Its a viewer/collection manager that lets you set metadata to help searching and displays the covers. I love mac apps. It seems like you can always find a well designed app on the mac for whaterver you need. Sadly my iBook died over the weekend. Coincidently, 2 weeks after my warrenty exprired and I decided not to ante up for the extended AppleCare. At least its a good excuse to buy a new MacBook Pro<g>. Until then I needed a replacement for ComicBookLover. I couldn't find a windows equivalent, so as a good little software developer, I decided to build my own. So thus was born the first *MonkeySource app produced by 10,000 Monkeys. Actually, it was more like 1000 monkeys. The other 9000 were busy watching the Illini dominate Iowa and working on the soon to be unveiled electronic foosball scoreboard app (*MonkeySource software has no support and may or not be updated depending on my current motivation level, but hey, you can always modify the source yourself <g>) So inspired by the ComicBookLover layout, I developed CLibrary, named in honor of CDisplay:
I even used the dreaded MS Comic Sans font. I mean if you can't use comic sans in a comic book manager, then when can you use it. The code is avaible here. Its written in C# with VS 2005 and is still pretty much a pre-pre-alpha application. You can download the free express version of VS 2005 here if you want to build and improve this app which I know you do. Not too much in the way of error handling and features, but it does allow you to import a directory of comics, which takes a thumbnail screenshot of the cover page and loads it into a SQL Express DB. The DB has a few fields to store the name, volume, and issue #. The comic isn't modified in anyway, so I don't think it'll delete anything. But remember, MonkeySource has no support <g>. Oh and if you have CDisplay installed, you can double click on a row or on a cover and it'll open the comic in CDisplay. And you can search by name. I haven't had time to scan many comics from my collection, but it seems to perform relatively well when I loaded the same 4 comics a few hundred times.
So how was it done? Obviously its pretty basic at this point. Though here are some technical tidbits from the app:Reading Comic Archives
I used
#ziplib (for cbz zip files) and the UnRAR dll (for cbr rar files) to open comic archives and grab out a thumbnail of the cover. The cbz files are pretty quick to open and grab a thumb nail since it allows you to grab an entry from the zip and return it as a file stream like so:
private static Bitmap GetCoverFromZip(string file)
{
ZipFile zipFile = new ZipFile(file);
zipFile.GetInputStream(1);
return new Bitmap(zipFile.GetInputStream(1));
}
RAR files a more of a pain to get a file from and its slow since you have to actually scan the whole archive to extract out the image. Maybe there is a better way, but I didn't spend alot of time on it.
private static Bitmap GetCoverFromRar(string file)
{
// Create new unrar class and open archive for listing files
ArrayList files = new ArrayList();
Unrar unrar = new Unrar();
unrar.Open(file, Unrar.OpenMode.List);
while (unrar.ReadHeader())
{
if (!unrar.CurrentFile.IsDirectory)
{
files.Add(unrar.CurrentFile.FileName);
}
unrar.Skip();
}
unrar.Close();
files.Sort();
unrar.Open(file, Unrar.OpenMode.Extract);
while (unrar.ReadHeader())
{
if (unrar.CurrentFile.FileName == files[0].ToString())
{
unrar.Extract("temp.jpg");
break;
}
unrar.Skip();
}
unrar.Close();
return new Bitmap("temp.jpg");
}
Then you can grab a thumbnail like so:
Image cover = GetCoverFromZip(file);
cover.GetThumbnailImage(65, 100, null, new IntPtr());
The rest is just a datagrid view and a list view for the covers. I might write more about that later, but I've already set my new personal record for blog entry length. I'd love to here any suggestions or even better, for someone to download the code and make some improvements.