2008-06-11

Why Microsoft? Why?!

Take the cab file format. It's present on every windows from Windows 95. If you use the LZW compression algorithm you get small archives.
986.875 oggcodecs.7z
1.150.890 oggcodecs.cab
1.618.917 oggcodecs.zip

It's better than zip and a bit worse as 7-zip.

The problem with cab file format it's that it's hard to use it in command line.

For example here is what you need to code to compress one directory into a cab file:
for %%i in (oggcodecs\*.*) do echo "%cd%\%%i" >> files.ddf
makecab /L . /D CompresionMemory=21 /D CompressionType=LZX /D DestinationDir=oggcodecs /F files.ddf
del files.ddf
move disk1\1.cab oggcodecs.cab
rmdir disk1
del setup.inf
del setup.rpt

Pretty hard core. One might say that this is not a tool to be used from a command line as rar or other popular archiving programs. This is done only once by me in a script file, so I can live with it.

The problem is with the extraction method. I have created a folder inside that cab file, which I can see with Total Commander, 7-zip File Manager etc, but with Windows Explorer I see directly the files, without the directory. There is one command line program which handles cab archives - expand.exe. Expand.exe doesn't know about directories in cab files, there is no switch to instruct him to preserve the directory structure from the cab file.

Why Microsoft? Why?

The solution is simple, create the destination folder first, d'oh!

mkdir oggcodecs
expand oggcodecs.cab -F:* oggcodecs\

Why not use 7-zip and ignore all this trouble? A cab file I can digitally sign and you can see it's coming from me and you don't need a 3rd party program to unpack!

2008-06-10

Why Microsoft? Why?!

I haven't mentioned here that I lost my fate in Microsoft that they can deliver good development tools a long time ago, I guess that was when I saw Visual Studio .NET 2002 for the first time. The .NET age fuc*ed it up real good.

At work I have Visual Studio 2003 and 2005 installed on D drive. Now I had to install Visual Studio 2008 on my system. I choose D drive, I verify every component that it should install on D drive and click Next, Next... Finish.

To my surprise the C++ component (VC directory) was installed on C drive, I said to myself... hmm, maybe I've forgot to install it on D, but it was working and I've ignored the issue.

The problem was when I've tried to compile something from the console. I've opened a console, setup the environment variables "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" and then hit nmake.

It complained that it could not find rc.exe, WTF. Then I found out that rc.exe is part of the Microsoft SDK which was on D (D:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\). When I try to setup the environment variables for Microsoft SDK ("d:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\SetEnv.Cmd" ) it complains that it can not find a compiler...

So now I'm installing everything on C drive, because for Microsoft, C++ should stay on C drive.

Edit: It works now (everything is on drive D), I've uninstalled all the programs that had a connection with Visual Studio 2008. If at first you don't succeed then try again, and again, and again.

2008-06-07

Authenticode

By using code signing with a certificate provided by Certum I was able to change how the oggcodecs installer looks on Windows Vista from this:



to this:



The name of the installer looks different, but my name is displayed under :)

Maintainer for Directshow Filters for Ogg Vorbis, Speex, Theora and FLAC

I probably should have blogged sooner, but here it is: I'm the current maintainer for Directshow Filters for Ogg Vorbis, Speex, Theora and FLAC.

If you want a hardware Ogg Player you should consider buying a Trekstor Samsung (most of their MP3 players support Ogg Vorbis and FLAC formats) product!

2008-05-31

New beta version of Y!M 9

Yahoo Messesnger 9.0 has reached version 9.0.0.1389. This version fixes the long standing bug with Romanian „ă” character inserted with AltGr-A which was interpreted as Ctrl-Alt-A.

This is a great victory for the glorious people of Romania!

2008-04-29

Pimpin' Windows XP's cmd.exe

I like the command line interface, not because I own a Das Keyboard and I'm forced to look at the screen, but because I like to type.

Windows XP's cmd.exe was not one of my favorite consoles, it lacked configurability, especially in the font area. You have only two options when it comes fonts: raster fonts and "Lucida Console".

I grew accustomed with "DejaVu Sans Mono" font from my Linux days and since then when I think about a monospaced font I think of "DejaVu Sans Mono".

One option is to use an alternative console, but I found out that it's not as fast as cmd.exe.

The solution is to replace "Lucida Console" with "DejaVu Sans Mono"! Just fire you your favourite font editor and do the required changes, then install the new "Lucida Console" and that's it.

Here is a screenshot with my pimped cmd.exe



In the meantime I've found an easier way of changing the console font, read more about it here

2008-03-09

Limba noastră-i o comoară

This post is intended to the Romanian audience.

Astăzi am dat peste ceva la care nu m-am gândit niciodată, să traduc în limba română cuvintele cheie din C/C++.

Soluţia este simplă, se foloseşte preprocesorul, iată un exemplu:


#include <cstdio>
#include "romanian.h"

folosim spatiunume::std;

int principal()
{
    scrie("Salutare Lume!\n");
}


Arată foarte interesant. Am văzut acest lucru la semnătura lui Marian Dragomir, iar fişiereul "romanian.h" arată astfel:



#ifndef ROMANIAN_H
#define ROMANIAN_H

#define asm asm
#define auto auto
#define pausa break
#define caz case
#define cara char
#define const const
#define continua continue
#define predefinit default
#define fa do
#define dublu double
#define altfel else
#define enum enum
#define extern extern
#define flotador float
#define pentru for
#define dutela goto
#define daca if
#define expandeaza inline
#define int int
#define lung long
#define registru register
#define restrict restrict
#define intoarce return
#define mic short
#define semnat signed
#define marimede sizeof
#define static static
#define structura struct
#define comuta switch
#define definestetip typedef
#define tipde typeof
#define uniune union
#define farasemn unsigned
#define vid void
#define inflamabil volatile
#define atitcit while
/* definitii pentru C++ */
#define bool bool
#define prinde catch
#define clasa class
#define mold_const const_cast
#define sterge delete
#define mold_dinamic dynamic_cast
#define explicit explicit
#define export export
#define fals false
#define prieten friend
#define mutabil mutable
#define spatiunume namespace
#define nou new
#define operator operator
#define privat private
#define protejat protected
#define public public
#define mold_reinterpreteaza
#define molda_static static_cast
#define sablon template
#define acesta this
#define arunca throw
#define adevarat true
#define intentioneaza try
#define numetip typename
#define idtip typeid
#define folosim using
#define virtual virtual
#define lchar_t wchar_t

/* definitii de functii comune */
#define principal main
#define scrie printf

#endif


Spor la scris „poezii”! ;-)

2007-11-24

Windows Time Sync

Sometimes you need to know if your computer has the correct time, what do you do to ensure that?

On Windows XP you double click on the clock in the right corner of your screen select "Internet Time" and click "Update Now". All the times I did this I got an error. Windows has only two entries in that combobox, and both return errors, why?!

Today I have gone a step further I googled for more Internet Time Servers, on this page I've found plenty. For example Germany has 214 servers in a time server pool (de.pool.ntp.org).

It was about time ;-)

2007-11-10

New Updates to MFC in Visual Studio 2008

Here is an half an hour interview with Pat Brenner on the topic "New Updates to MFC in Visual Studio 2008".

A very informative movie, my favorite quote is "we kinda moved out from the '90s"!

And a quick summary:

What's new for MFC developers:
  • Ribbon

  • Customisable Menubar / Toolbar

  • Visual Studio 2005 like Docking

  • Tabbed MDI

  • New status bar

  • and many more



  • You can get a full visual tour on what's new on the Visual C blog entry.

    Here is a screenshot of MFC demo made by the Wizard:




    All this functionality is available now from 3rd party vendors, but this will be backed by Microsoft. Impressive!

    Edit MFC Update powered by BCGSoft as you can read here.

    Y!M 9.0 Without Ads

    One way to disable the ads from the main window of Yahoo Messenger 9.0 is to cut access to one specific file. With this version it doesn't work any more the trick of clearing the file and making it read only.

    If you have installed Y!M on a NTFS file system you are lucky, you can remove the Read security attribute and the ads are gone (at least until they fix this too).

    Here is the code to remove the access to the file from the command line, or batch file:
    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml"  /E /P %USERNAME%:N


    If you want to bring the ads back because they were adding color to your contact list here is the command line to do just that:
    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml"  /E /P %USERNAME%:F


    I hope they won't read this blog and fix the hole until the final version 9.0 gets out next year ;-)

    Edit: by upgrading to version 9.0.0.907 I found out that removing reading rights from the file was not enough, you need to fiddle with the Windows Registry e bit. Here is a batch file that does it for you:

    @ECHO OFF
    TITLE Remove ads from Yahoo Messenger 9

    > %TEMP%.\noYMads.reg ECHO REGEDIT4
    >>%TEMP%.\noYMads.reg ECHO.
    >>%TEMP%.\noYMads.reg ECHO [HKEY_CURRENT_USER\Software\Yahoo\Pager\YUrl]
    >>%TEMP%.\noYMads.reg ECHO "First Login Beacon"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Change Room Banner"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Finance Disclaimer"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Messenger Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Chat Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Calendar Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Conf Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Mail Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "News Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Personals Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Stock Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Medium"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Big"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Upload Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Chat Transition Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "N2Phone Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Bid"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "IMVironment Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Auction Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Login Mobile Ad"="noads.html"
    REGEDIT /S %TEMP%.\noYMads.reg
    DEL %TEMP%.\noYMads.reg

    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml" /E /P %USERNAME%:N

    2007-11-09

    Yahoo Keyboard Patch!

    Yahoo! Messenger had a very annoying problem, text selection with Ctrl-A was done when it shouldn't be done.

    For example Windows maps AltGr key to Ctrl-Alt keys combination, which is default behaviour. Yahoo! Messenger treats AltGr-A as Ctrl-Alt-A but then it gets the Ctrl-A part, whole text selection, and afterwards it goes to normal keyboard handling, which with a certain Romanian keyboard layout generates the character "ă", but because the text was selected before, "ă" was the only character left in the sentence you wrote.

    This was very annoying, but then by using the wonderful Microsoft technology called Detours I was able to intercept certain WIN32 API Messages and prevent the text selection from happening. Yahoo! keyboard patch was created.

    Cristian Secară was very nice to host this patch on his webserver, also he made some very good suggestions which improved whole the quality of the software.

    The patch is available at this location (Romanian language only).

    Note: this patch also works with other keyboard layouts, for example the Hungarian default keyboard layout can be used to generate the character "ä" now.

    2007-10-29

    To C or Not to C

    Today I was a bit puzzled by this code (test.c):

    #include <stdio.h>

    int main()
    {
        int i = ceil(2.9f);
        printf("i is: %d\n", i);
    }

    I had compiled the code using the command cl test.c, clean compile no warnings, no messages, after running the program the result was: i is: 1024. WTF?!

    The proper compile command cl /W4 test.c returned this:

    test.c(5) : warning C4013: 'ceil' undefined; assuming extern returning int

    C assumes a bit too much.

    Next time I want to try a code snippet I won't use the .c extension, I'll use .cc, one character makes a big difference:

    test.cc(5) : error C3861: 'ceil': identifier not found


    D'oh, I forgot to #include <math.h>!

    2007-07-13

    Pidgin gems

    Pidgin keyboard shortcuts cannot be edited by using a configuration dialog, but they can be edited "by hand".

    I wanted two actions to remap: closing the conversation dialog with Escape key and show/hide offline buddies with Control-H.

    This can be achieved by editing the ".purple/accels" file, which is located in your home directory on Linux and in "{drive letter}:\Documents and Settings\{user name}\Application Data" on Windows, and inserting the following lines:


    (gtk_accel_path "<PurpleMain>/Buddies/Show Offline Buddies" "<Control>h")
    (gtk_accel_path "<main>/Conversation/Close" "Escape")

    2007-03-29

    CMake support for SciTE

    I have added support for CMake in SciTE text editor. It should be available in the upcoming 1.73 release.

    Here is a picture of a rather small CMake script file:

    2007-02-02

    Eclipse C++ Programming with MinGW

    MinGW brings the powerful (free) GNU C++ compiler to the Windows world. The only drawback is that you get only command line tools, no GUI interface. While this is OK only for small programs, it becomes an issue when you need a debugger and / or the project contains more than one source file.

    That's where Eclipse kicks in. With the CDT plug-in you can edit, compile and debug your C++ programs.

    These are the required downloads (compiler, debugger and editor):
    • MinGW and GDB installers from here (I've downloaded MinGW-5.1.3.exe from MinGW->Current section) and from here for the latter (I've downloaded gdb-6.3-2.exe from Snapshot section)
    • EasyEclipse for C and C++ from here (I've downloaded release 1.2.1.1).

    After creating a C++ project in Eclipse you will notice that there is warning complaining that cygpath is not found, it's a benign warning since we're not using Cygwin to build programs.

    Eclipse expects that g++, make and gdb executables to be in PATH, since I don't like to pollute the global PATH environment variable with MinGW executables I've created a "launcher" for Eclipse that adds MinGW to PATH before running Eclipse.

    Here is the code (eclipse.js):
    var program = "eclipse.exe";

    // Add the arguments
    for (var i = 0; i < WScript.Arguments.length; ++i)
    {
        program += " " + WScript.Arguments.Item(i);
    }

    var shell = new ActiveXObject("WScript.Shell");

    // Add mingw to path
    var env = shell.Environment("PROCESS");
    var path = "c:\\mingw\\bin;";
    path += env("PATH");
    env("PATH") = path;

    // Execute the program and don't wait for completion
    shell.Exec(program);


    Copy the "launcher" to Eclipse directory (c:\Program Files\EasyEclipse for C and C++ 1.2.1.1) and use it from now on to start Eclipse.

    We need one more step to get everything to work, change the C/C++ build command from make to mingw32-make (or rename mingw32-make it to make in c:\mingw\bin, if you want the eclipse project to be crossplatform) like in the picture bellow:


    That was all. Now we have a full C++ IDE. Now we can develop console applications or Win32 C GUI applications. For C++ GUI applications we can use the free (GPL) Trolltech Qt library.

    2007-01-15

    It's not a bug, it's a feature

    In my previous post I've said that I found a C# bug, now I've found out that it's not a bug, that behavior is by design.

    It's written in the C# standard, around page 88 (110 real page):

    [Note: As specified above, the declaration space of a block cannot share names with the declaration spaces of any nested blocks. Thus, in the following example, the F and G methods result in a compile-time error because the name i is declared in the outer block and cannot be redeclared in the inner block. However, the H and I methods are valid since the two i’s are declared in separate non-nested blocks.

    class A
    {
        void F() {
            int i = 0;
            if (true) {
                int i = 1;
            }
        }
        void G() {
            if (true) {
                int i = 0;
            }
            int i = 1;
        }
        void H() {
            if (true) {
                int i = 0;
            }
            if (true) {
                int i = 1;
            }
        }
        void I() {
            for (int i = 0; i < 10; i++)             H();         for (int i = 0; i < 10; i++)             H();     } }

    end note]


    I hate compilers that impose stupid constrains.

    2007-01-10

    My first C# bug

    Consider this piece of code:
    class Foo
    {
        public static void Bar()
        {
            if (true)
            {
                int i = 0;
            }
            int i = 1; // CS0136
        }
        
        public static void Main()
        {
        }
    }


    Any C (C++, Java) coder will say that there is nothing wrong with that code.
    I thought that was the same in C# language, I was wrong.
    Here is the output from Visual Studio .NET 2003:
    test.cs(9,13): error CS0136: A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else

    test.cs(9,13): error CS0103: The name 'i' does not exist in the class or namespace 'Foo'

    Here is the output from Visual Studio 2005:
    test.cs(9,13): error CS0136: A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else


    While VS2005 got better than VS2003, but it's still in error.

    Here is what MSDN has to say about error CS0136

    Compiler Error CS0136A local variable named 'var' cannot be declared in this scope because it would give a different meaning to 'var', which is already used in a 'parent or current' scope to denote something else
    A variable declaration hides another declaration that would otherwise be in scope. Rename the variable that is declared on the line that generated CS0136.
    The following sample generates CS0136:

    // CS0136.cs
    namespace x
    {
       public class a
       {
          public static void Main()
          {
             int i = 0;
             {
                char i = 'a';   // CS0136, hides int i
             }
             i++;
          }
       }
    }



    Well, in our case i variable was declared after the if block and not before it. It doesn't make any sense to say that the second i is in the if's i scope.

    I know it's a bad practice to reuse the same name for more variables in a function, but I don't expect that to be an error, just a warning at the highest warning level.

    What's sad is that the alternative C# implementation, naming Mono, has the same behaviour. Here is the output:
    test.cs(9,7): error CS0136: A local variable named `i' cannot be declared in this scope because it would give a different meaning to `i', which is already used in a `child' scope to denote something else
    test.cs(7,8): (Location of the symbol related to previous error)


    They've copied Microsoft's implementation bug by bug (for compatibility :). The sad part is that this bug was reported to Mono in 2003 but they've closed it saying it's not a bug. Here is the link to that bug

    By the way I've posted a comment there, just to complain about it :)

    It seems that this is not a bug, but a feature, read more about it here

    2006-12-22

    NTFS3g on OpenSuse 10.2

    I have installed openSuSE 10.2 on my brand new computer (bought more than a month ago).

    I'm happy with openSuSE 10.2, YaST has been improved, it gives more feedback to the user. Now there is an native KDE updater, so I don't have to install a GNOME Mono application, the source repository knows about YUM repositories, and so on and so forth.

    After installing it I've noticed that my Windows XP wasn't booting anymore. The fact was that I had two NTFS partitions, the first had the boot loader and boot.ini and the second had Windows files. The second partition number had shifted after creating two linux partitions, so Windows boot loader got confused and refused to work.

    Well I said, it's easy, all I have to do is to modify boot.ini and change multi(0)disk(0)rdisk(0)partition(2) to multi(0)disk(0)rdisk(0)partition(4). There was one problem, that the file resided on a NTFS file system. Linux has readonly access by default.

    Eeeek, but then I remembered that there is something new out there ntfs-3g that can mount read/write a NTFS file system.

    I've searched the net and found that I had to install fuse, fuse-ntfsprogs and ntfs-3g packages. The first two came with openSuSE 10.2, the latter from GURU 3rd party repository. GURU had a ntfs-3g version from 20061115, which was too old for fuse 2.6.0 that came with openSuSE 10.2. Eeeek.

    The solution was to get the latest and greatest sources and the RPM spec files from fuse and ntfs-3g to create my own rpm packages.

    I've got fuse 2.6.1 and ntfs-3g 20061218, after hacking the RPM spec files I've managed to create two nice rpm packages. The problem was that the command ntfs-3g /dev/hda1 /windows/C was still failing. Eeeek again.

    The problem was with the fuse kernel module, it was too old. openSuSE 10.2 fuse spec file didn't create a kernel module because kernel included the fuse module. I've hacked fuse RPM spec file to --enable-kernel-module, all nice until the very last step when the packages were to be created. Because fuse.ko module was still in RPM's database, RPM could not create a new module that contained fuse.ko because of some incompatibilities later on. Tired of eeeking.

    Solution was to copy the new fuse.ko module and store it somewhere, then put back --disable-kernel-module in fuse RPM spec and run a rpmbuild -ba fuse.spec. Then I've copied fuse.ko over the one from /lib/modules/linux-2.6.18.../kernel/fs/fuse/fuse.ko.
    After installing fuse and fuse-devel packages I've build ntfs-3g package, installed it and the command: ntfs-3g /dev/hda1 /windows/C was working!

    In order to always mount read/write I've modified /etc/fstab and instead of ntfs I've put ntfs-3g and removed the ro (read only) flag from the next option on the same line.

    After modifying boot.ini and a reboot I got my Windows XP back!

    In conclusion, I like openSuSE they didn't made all the things easy, most of them are easy but some issues are still to be fixed, like the one above. One can say that this is the price to pay for bleeding edge software, but every now and then it's fun to hack something, to remember the good old days of hacking Slackware to do the things you wanted.

    2006-12-03

    The DaVinci Code

    I've just finished reading The DaVinci Code by Dan Brown. I've done this after watching the movie twice, at the cinema and the director's cut on my computer.

    I've enjoyed the book more, in the movie they've made some hacks to keep the plot on the feet.

    If you haven't read the book please do so ;)