Commits

shuerhaaken committed d2299d8

change constructor to allow fallback to Info class with file type resolver

  • Participants
  • Parent commits 58fbd19

Comments (0)

Files changed (2)

File libtaginfo/info.cc

 
 // Info
 
-Info::Info(const string &filename) {
+Info::Info(const string &filename, bool create_own_fileref) {
     
     taglib_fileref = NULL;
     taglib_file    = NULL;
     has_image = false;
     
     changedflag = CHANGED_DATA_NONE;
-};
-
+    
+    if(create_own_fileref) {
+        if(!file_name.isEmpty() && !create_file_ref())
+            printf("Error creating file ref! %s\n", filename.c_str());
+        if(taglib_fileref && !taglib_fileref->isNull()) {
+            taglib_file = taglib_fileref->file();
+            taglib_tag = taglib_file->tag();
+            if(!taglib_tag) {
+                printf("Cant get tag object from '%s'\n", file_name.toCString(false));
+                delete taglib_fileref;
+                taglib_fileref = NULL;
+                taglib_file    = NULL;
+                taglib_tag     = NULL;
+            }
+        }
+        else {
+            delete taglib_fileref;
+            taglib_fileref = NULL;
+            taglib_file    = NULL;
+            taglib_tag     = NULL;
+        }
+    }
+}
 
 Info::~Info() {
     if(taglib_fileref)
         taglib_fileref = new TagLib::FileRef(file_name.toCString(false), true, TagLib::AudioProperties::Fast);
     else
         return false;
-    
-    if(taglib_fileref && !taglib_fileref->isNull()) {
-        taglib_file = taglib_fileref->file();
-        taglib_tag = taglib_file->tag();
-        if(!taglib_tag) {
-            printf("Cant get tag object from '%s'\n", file_name.toCString(false));
-            return false;
-        }
-        return true;
-    }
-    else {
-        return false;
-    }
 }
 
 

File libtaginfo/taginfo.h

             void set_is_compilation(bool compilation);
             
             
-            Info(const string &filename = "");
+            Info(const string &filename = "", bool create_own_fileref = false);
             ~Info();