Thursday, December 23, 2010

C# and Static Linking

When I was writing application that required to parse HTML pages, I selected HtmlAgilityPack to do this. It is excellent library but it's sometimes inconvenient to distribute program with multiple DLLs. So, I decided to link required DLL statically.

The first solving that I found was to merge required assemblies into my own using ILMerge. Spent a little time to find required options I merged DLL into the program:

ILMerge.exe /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework4.0.30319" /out:appout.exe app.exe HtmlAgilityPack.dll

It works ok, but while searching command line options I found another decision by Jeffrey Richter how to get one file for application. Read the comments I took a notice on this one by Jeff:

ILMerge produces a new assembly file from a set of existing assemblies. This means that the original assemblies lose their identity (name, version, culture, and public key).
What I am showing here is creating an assembly that embeds the EXISTING assemblies into it so that they do not lose their identity at all.

So, I decided to use his method. But there was one problem - it didn't work for me :). His code couldn't find the resource. So, I started to search further for its another variations. But I couldn't find what's was wrong.

Nevertheless, I found two ways how to implement Jeff's idea. The first resolution is direct:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
    if (new AssemblyName(args.Name).Name == "HtmlAgilityPack")
        return Assembly.Load(Properties.Resources.HtmlAgilityPack);
    return null;
}

And the second is more universal and doesn't require to write "if" for every embedded assembly:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
    var requestedAssemblyName = new AssemblyName(args.Name).Name;
    var manifestResourceName = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Name + ".Properties.Resources.resources";
    using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName))
    {
        using (var reader = new ResourceReader(stream))
        {
            var resource = reader.GetEnumerator();
            while (resource.MoveNext())
            {
                if ((string)resource.Key == requestedAssemblyName)
                    return Assembly.Load((byte[])resource.Value);
            }
        }
    }
    return null;
}

Friday, November 19, 2010

GetColor Color Picker

I'm not a designer, and marking-up HTML is not my primary duty too, but sometimes I have requirement to choose some colors. I've tried several color pickers, but they turned out to be not very convenient. The problem was that I had to press "Copy" button.

Therefore, I decided to write my own. And here it is.

It hasn't great functions like some other pickers, but it might being liked to you of its "Your selected color is already in the clipboard" function. It's really handy, try it right now! :)

Hold ALT key and move your mouse to view zoomed region. You can change zoom factor and click on the preview window to select the color.

Download GetColor v0.7 (10 KB)

Download GetColor v0.7 Sources (12 KB)

Thursday, October 14, 2010

foobar2000 Plugin for Windows 7 - Progress Bar on Its Taskbar Icon

Some tautology but it's true :).
Shows progress of currently played song in the taskbar. Foobar is stopped:

Foobar is playing song:

Foobar is paused:

Minimal OS is Windows 7, of cause.

NOTE! This plugin is for version 0.8.3, not 0.9 or 1.0, 'cos I like it. It's sad, but new versions (since 0.9) don't satisfy my requirements (the main is customization of playlist with my own colors, not default one with several tones).

Download "foo_win7_taskbar_progress" plugin (3 KB)

Download Sources for "foo_win7_taskbar_progress" plugin (927 KB)

uTorrent DHT Patcher Departs This Life

I've noticed that new versions can't be patched ever more, so uTorrent DHT Patcher is staying unusable...

Wednesday, August 11, 2010

I Can See 3D

For many years I'm interesting in stereo-images - pictures with garbage that stay 3D if you look properly on them. I could see none of them and that got me upset. But several days ago I found a new (for me) technology of 3D that I could see! 

Here're two 3D mages that I made. The first is part of the view outside of my office, and the second is two IT guys and designer (without me) I work with. Click on them to enlarge.

   

To see picture in 3D you must start look at the point between eyes and LCD. You'll see third image between these two. This image is 3D. And the last thing - you must get the right eyes' focus to take away the blur.

Sunday, June 27, 2010

uTorrent DHT Patcher

Some time ago I required to download a torrent from a private tracker but I didn't want to lose my rating. So, I decided to remove private tracker from the list and enable DHT. There was a one problem - I couldn't do it - "Enable DHT" checkbox was disabled!

Within five minutes I found several patches to fix it, but there was no patch for the latest version. So, I wrote my own patcher to do it automatically.

And here I'm glad to announce it for you too! :) It searches for the "private" string, then for reference for it and then for "je" in next 50 bytes.

uTorrent DHT Patcher 1.1 (5 KB)

uTorrent DHT Patcher 1.1 with UPX 3.00 (258 KB)

Saturday, May 29, 2010

Hi, People!

Just decided to open a my own blog to post some stuff that might be interesting for others.