[content] Change codes fabout content path not including extension
[platform/framework/native/content.git] / src / FCnt_ContentManagerUtilImpl.cpp
index 15a44ca..d73ed3d 100755 (executable)
@@ -22,6 +22,7 @@
 
 #include <new>
 #include <stdlib.h>
+#include <aul/aul.h>
 #include <mime_type.h>
 #include <FAppApp.h>
 #include <FBaseByteBuffer.h>
@@ -47,7 +48,6 @@
 #include "FCnt_ImageMetadataImpl.h"
 #include "FCnt_VideoMetadataImpl.h"
 
-
 using namespace std;
 using namespace Tizen::App;
 using namespace Tizen::Base;
@@ -59,6 +59,7 @@ using namespace Tizen::System;
 
 namespace Tizen { namespace Content
 {
+
 // Types of content, format supported and default values
 static const int _IMAGE_BUFF_LENGTH = 100;
 static const int _THUMBNAIL_IMAGE_WIDTH = 80;
@@ -1589,6 +1590,7 @@ _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool intern
        ClearLastResult();
 
        ContentType contentType = CONTENT_TYPE_UNKNOWN;
+       String mimeType(L"");
 
        if (!internal)
        {
@@ -1602,25 +1604,46 @@ _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool intern
 
        String fileExt = _FileImpl::GetFileExtension(contentPath);
        result r = GetLastResult();
-       SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] GetFileExtension failed.", GetErrorMessage(r));
 
-       unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
-       SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
-                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       if (!IsFailed(r))
+       {
+               unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
+               SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       char* pTempMimeType = null;
-       int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
-       SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
-                       "[E_INVALID_ARG] mime_type_get_mime_type failed.");
-       SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
-                       "[E_INVALID_ARG] mime_type_get_mime_type failed.");
+               char* pTempMimeType = null;
+               int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
+               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] mime_type_get_mime_type failed.");
+               SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] mime_type_get_mime_type failed.");
 
-       unique_ptr<char, CharDeleter> pMimeType;
-       pMimeType.reset(pTempMimeType);
+               unique_ptr<char, CharDeleter> pMimeType;
+               pMimeType.reset(pTempMimeType);
 
-       SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
+               SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
 
-       String mimeType(pMimeType.get());
+               r = mimeType.Append(pMimeType.get());
+               SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+       }
+       else
+       {
+               SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
+
+               unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
+               SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+               char tempType[255] = {0, };
+               int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
+               SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
+
+               r = mimeType.Append(tempType);
+               SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+       }
 
        if (mimeType.Contains(L"image"))
        {
@@ -1637,10 +1660,7 @@ _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool intern
        }
        else if (mimeType.Contains(L"video"))
        {
-               String format;
-               fileExt.ToLowerCase(format);
-
-               if (format == L"3gp" || format == L"mp4")
+               if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
                {
                        return CheckStream(contentPath);
                }
@@ -1840,4 +1860,5 @@ _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, cons
 
        return r;
 }
+
 }}