Fix for bug #5 (some devices not detected)

This was a general bug in the pattern hash handling, so that the
detection could fail in some special cases (for patterns that use a ? or
* placeholder in the first 32 characters and before a space). I also
fixed a possible bug that could lead to unnecessary cache file
regeneration.