BOOL GetFileInfo(CLOUD_MEIDA_METADATA_STRUCT* instruct,const CString filepath,bool* bIsAudio,bool* bIsPhoto,bool* bIsVideo)
{
	CString fileDir ,fileName;
	fileDir.Append(filepath);
 	
	PathRemoveFileSpec((LPWSTR)(LPCTSTR)fileDir);//Get dir Name
	fileName.Append(PathFindFileName(filepath));//Get file name
 
	IShellDispatch* pShellDisp = NULL;  
    Folder *pFolder;  
    FolderItem *pFolderItem;  
    CComBSTR    stitle,str;  
    HRESULT hr = S_OK;  
	CoInitialize(NULL);  
  
    hr =  ::CoCreateInstance( CLSID_Shell, NULL,CLSCTX_SERVER, IID_IShellDispatch, (LPVOID*)&pShellDisp );  
  
    if( hr == S_OK )  
    {  
        hr = pShellDisp->NameSpace(CComVariant(fileDir),&pFolder);    
        hr = pFolder->ParseName(CComBSTR(fileName),&pFolderItem);  
        CComVariant vItem(pFolderItem);  

        //CComVariant vEmpty;  
        //int i = 0;  
   
   //     for (int i = 0 ;i < 100;i++)  
   //     {  
   //         hr = pFolder->GetDetailsOf(vEmpty,i,&stitle);  
   //         hr = pFolder->GetDetailsOf(vItem,i,&str);  
			//COLE2T lpszTitle(stitle);  
			//COLE2T lpszInfo(str);  
			//TCHAR buf[300];  
			//afxDump <<i <<":		"<< lpszTitle.m_psz<<"		"<<lpszInfo.m_psz<<"\n";
   //          int a = 1;  
   //     }  
		CString csPerceivedType;
 
		csPerceivedType = GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_PerceivedType);
		*bIsAudio = PathMatchSpec(csPerceivedType,_T("audio"));
		*bIsPhoto = PathMatchSpec(csPerceivedType,_T("image"));
		*bIsVideo =  PathMatchSpec(csPerceivedType,_T("video"));
		instruct->Duration = GetDurection(GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_Duration));

		if(!*bIsAudio && !*bIsPhoto && !*bIsVideo)
			return FALSE;

		if(*bIsAudio)
		{
			instruct->Album = GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_Album);
		}
		else
		{
 
				instruct->Album = fileDir;
				instruct->Date = GetTime(GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_CreatedDate));	
 
 		}
		instruct->Size = GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_Size);
		instruct->Title = GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_Title);
		if(instruct->Title.IsEmpty())
		{
			CString csFileNameWithOutExtension;
			csFileNameWithOutExtension.Append(fileName);
			 PathRemoveExtension((LPWSTR)(LPCTSTR)csFileNameWithOutExtension);
			 instruct->Title = csFileNameWithOutExtension;
		}
		instruct->Genre = GetDetailsOf(pFolder,vItem,COLUMN_SORTING_TYPE_Genre);
        hr = pShellDisp->Release();  
        pShellDisp = NULL;  

    }  
    CoUninitialize();  
	return TRUE;
}
예제 #2
0
static int MyInvokeShellVerb_ShellDispatchProc(const TCHAR *pcDirectoryName, const TCHAR *pcFileName, const DWORD uiVerbId)
{
	int iSuccess = 0;

	bool bUnloadDll = false;
	HMODULE hShellDll = GetModuleHandleW(shell32); 
	if(hShellDll == NULL)
	{
		bUnloadDll = true;
		hShellDll = LoadLibraryW(shell32);
		if(hShellDll == NULL)
		{
			iSuccess = -3;
			return iSuccess;
		}
	}

	WCHAR pcVerbName[128];
	memset(pcVerbName, 0, sizeof(WCHAR) * 128);
	
	if(LoadStringW(hShellDll, uiVerbId, pcVerbName, 128) < 1)
	{
		if(bUnloadDll)
		{
			FreeLibrary(hShellDll);
			hShellDll = NULL;
		}
		iSuccess = -3;
		return iSuccess;
	}

	if(bUnloadDll)
	{
		FreeLibrary(hShellDll);
		hShellDll = NULL;
	}

	// ----------------------------------- //

	IShellDispatch *pShellDispatch = NULL;
	Folder *pFolder = NULL; FolderItem *pItem = NULL;
	
	HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void**)&pShellDispatch);
	if(FAILED(hr) || (pShellDispatch ==  NULL))
	{
		iSuccess = -3;
		return iSuccess;
	}

	variant_t vaDirectory(pcDirectoryName);
	hr = pShellDispatch->NameSpace(vaDirectory, &pFolder);
	if(FAILED(hr) || (pFolder == NULL))
	{
		iSuccess = -3;
		pShellDispatch->Release();
		return iSuccess;
	}

	pShellDispatch->Release();
	pShellDispatch = NULL;

	variant_t vaFileName(pcFileName);
	hr = pFolder->ParseName(vaFileName, &pItem);
	if(FAILED(hr) || (pItem == NULL))
	{
		iSuccess = -3;
		pFolder->Release();
		return iSuccess;
	}

	pFolder->Release();
	pFolder = NULL;

	// ----------------------------------- //

	long iVerbCount = 0;
	FolderItemVerbs *pVerbs = NULL;
	
	hr = pItem->Verbs(&pVerbs);
	if(FAILED(hr) || (pVerbs == NULL))
	{
		iSuccess = -3;
		pItem->Release();
		return iSuccess;
	}

	pItem->Release();
	pItem = NULL;

	hr = pVerbs->get_Count(&iVerbCount);
	if(FAILED(hr) || (iVerbCount < 1))
	{
		iSuccess = -3;
		pVerbs->Release();
		return iSuccess;
	}

	DispatchPendingMessages(125);

	// ----------------------------------- //

	for(int i = 0; i < iVerbCount; i++)
	{
		variant_t vaVariantIndex(i);
		FolderItemVerb *pCurrentVerb = NULL;
		BSTR pcCurrentVerbName = NULL;

		hr = pVerbs->Item(vaVariantIndex, &pCurrentVerb);
		if (FAILED(hr) || (pCurrentVerb == NULL))
		{
			continue;
		}
		
		hr = pCurrentVerb->get_Name(&pcCurrentVerbName);
		if(FAILED(hr) || (pcCurrentVerbName == NULL))
		{
			pCurrentVerb->Release();
			continue;
		}

		if(_wcsicmp(pcCurrentVerbName, pcVerbName) == 0)
		{
			hr = pCurrentVerb->DoIt();
			if(!FAILED(hr))
			{
				iSuccess = 1;
			}
		}

		SysFreeString(pcCurrentVerbName);
		pCurrentVerb->Release();
	}

	pVerbs->Release();
	pVerbs = NULL;

	// ----------------------------------- //
	
	return iSuccess;
}