]> git.datanom.net - lensdb.git/blobdiff - lib/main.cpp
Fix collecting lens data
[lensdb.git] / lib / main.cpp
index e957f1b9193eecf75928c30928532c6c2264c81c..5bf9c43e405956f2ead8cf10fb53e2dfe3a9bb52 100644 (file)
@@ -52,18 +52,33 @@ string ExifScanner::get_maker() {
        
        //g_hash_table_foreach(exif_tags, print_all, NULL);
        const gchar* lensId = (gchar *)g_hash_table_lookup(exif_tags, "LensMake");
-       if (!lensId) {
+       gulong len = g_utf8_strlen(lensId, -1);
+       if (!lensId || g_strcmp0("Unknown (2822)", lensId) == 0 || len < 1) {
                const gchar* s = (gchar *)g_hash_table_lookup(exif_tags, "LensID");
+               if (s && g_strcmp0("Unknown (2822)", s) != 0) {
+                       gchar* pos = g_strstr_len(s, -1, " ");
+                       //cout << pos << endl;
+                       if (pos) {
+                               //cout << "S length: " << strlen(s) << "POS length: " << strlen(pos) << endl;
+                               lensId = g_strndup(s, strlen(s) - strlen(pos));
+                       }
+                       len = g_utf8_strlen(lensId, -1);
+               }
+       }
+
+       if (!lensId || g_strcmp0("Unknown (2822)", lensId) == 0 || len < 1) {
+               const gchar* s = (gchar *)g_hash_table_lookup(exif_tags, "LensModel");
                if (s) {
                        gchar* pos = g_strstr_len(s, -1, " ");
                        //cout << pos << endl;
                        if (pos) {
                                //cout << "S length: " << strlen(s) << "POS length: " << strlen(pos) << endl;
                                lensId = g_strndup(s, strlen(s) - strlen(pos));
+                               len = g_utf8_strlen(lensId, -1);
                        }
                }
        }
-       if (!lensId)
+       if (!lensId || len < 1)
                maker = get_cscring("Unknown");
        else
                maker = get_cscring(lensId);
@@ -75,11 +90,13 @@ string ExifScanner::get_serial_number() {
        string sn;
 
        const gchar* id = (gchar *)g_hash_table_lookup(exif_tags, "LensSerialNumber");
-       if (!id) {
+       gulong len = g_utf8_strlen(id, -1);
+       if (!id || len < 1) {
                id = (gchar *)g_hash_table_lookup(exif_tags, "SerialNumber");
+               len = g_utf8_strlen(id, -1);
        }
        
-       if (!id)
+       if (!id || len < 1)
                sn = get_cscring("Unknown");
        else
                sn = get_cscring(id);
@@ -91,13 +108,17 @@ string ExifScanner::get_lens() {
        string lens;
 
        const gchar* lensId = (gchar *)g_hash_table_lookup(exif_tags, "LensID");
-       if (!lensId) {
+       gulong len = g_utf8_strlen(lensId, -1);
+       if (!lensId || g_strcmp0("Unknown (2822)", lensId) == 0 || len < 1) {
                lensId = (gchar *)g_hash_table_lookup(exif_tags, "LensModel");
-               if (!lensId)
+               len = g_utf8_strlen(lensId, -1);
+               if (!lensId || g_strcmp0("Unknown (2822)", lensId) == 0 || len < 1) {
                        lensId = (gchar *)g_hash_table_lookup(exif_tags, "LensSpec");
+                       len = g_utf8_strlen(lensId, -1);
+               }
        }
        
-       if (!lensId)
+       if (!lensId || g_strcmp0("Unknown (2822)", lensId) == 0 || len < 1)
                lens = get_cscring("Unknown");
        else
                lens = get_cscring(lensId);
This page took 0.45348 seconds and 5 git commands to generate.