/*
	ANT_DIRECTORY_ITERATOR_RECURSIVE::NEXT_MATCH_WILDCARD()
	-------------------------------------------------------
*/
char *ANT_directory_iterator_recursive::next_match_wildcard(void)
{
#ifdef _MSC_VER
	ANT_disk_directory *current_file_list;
	size_t path_length;

	while (get_next_candidate())
		{
		if (internals->file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
			if (!(strcmp(internals->file_data.cFileName, ".") == 0 || strcmp(internals->file_data.cFileName, "..") == 0))
				{
				current_file_list = file_list;
				push_directory();
				path_length = strlen(current_file_list->path) - 4;
				sprintf(file_list->path, "%*.*s/%s/*.*", (int)path_length, (int)path_length, current_file_list->path, internals->file_data.cFileName);
				}
			}
		else
			if (PathMatchSpec(internals->file_data.cFileName, wildcard))
				return internals->file_data.cFileName;
		}
	return NULL;
#else
	char *file;
	long match = FALSE, at_end = 1;

	while (!match)
		{
		if (at_end == 0 || file_list->glob_index >= file_list->matching_files.gl_pathc)
			{
			globfree(&file_list->matching_files);
			if (pop_directory())
				{
				file_list->glob_index++;
				return next_match_wildcard();
				}
			else
				return NULL;
			}
		// check if the matching path is a directory
		else if (file_list->matching_files.gl_pathv[file_list->glob_index][strlen(file_list->matching_files.gl_pathv[file_list->glob_index]) - 1] == '/')
			{
			if (true)
				{
				/* tmp is here as push_directory() will trash current file_list*/
				char *tmp=file_list->matching_files.gl_pathv[file_list->glob_index];
				push_directory();
				if ((file = first_match_wildcard(tmp)) != NULL)
					return file;
				}
			}
		else
			if ((match = PathMatchSpec(file_list->matching_files.gl_pathv[file_list->glob_index], wildcard)) != 0)
				break;
		at_end = !(file_list->glob_index++ == file_list->matching_files.gl_pathc);
		}
	return file_list->matching_files.gl_pathv[file_list->glob_index++];
#endif
}
Beispiel #2
0
__inline
void CFileBase::FileBackup(const SYSTEMTIME &Time)
{
	if (NULL == m_pFileHandle)
		return;

	if (m_sLastTime.wDay != Time.wDay)
	{
		CString strValue[2]; 
		if (!GetFileName(Time, 1, strValue[0], strValue[1]))
			return;

		CString strFileName = GetFileName();
		ATLASSERT(strFileName.GetLength() != 0);
		CString strMatchName = strValue[0] + strValue[1];
		if (!PathMatchSpec(strFileName, strMatchName))
		{
			m_iBkCount = -1;
			CloseFile();
		}
	}
	else if (m_iFileSize > m_iMaxFileSize)
	{
		CloseFile();
		AdjustFileName(Time);
	}
}
Beispiel #3
0
__inline
BOOL CFileBase::GetFileName(const SYSTEMTIME &Time,
							CString &strFileName)
{
	CString strName[2]; 
	if (m_strFileName.GetLength() != 0)
	{
		GetFileName(Time, 1, strName[0], strName[1]);
		if (PathMatchSpec(m_strFileName, strName[0] + strName[1]))
		{
			strFileName = m_strFileName;
			return TRUE;
		}
	}

	CFileSearcher Searcher;
	if (Searcher.Search(this, Time, strFileName))
		return TRUE;
	
	GetFileName(Time, 0, strName[0], strName[1]);
	if (CreateFolder(strName[0]))
	{
		strFileName = strName[0] + strName[1];
		return TRUE;
	}

	return FALSE;
}
bool Directory::read(std::string& name, bool& isDir)
{
  if(!dp)
    return false;

  for(;;)
  {
    struct dirent* dent = readdir((DIR*)dp);
    if(!dent)
    {
      closedir((DIR*)dp);
      dp = 0;
      return false;
    }
#ifdef WINDOWS
    if(PathMatchSpec(dent->d_name, filepattern.c_str()))
#else
    if(fnmatch(filepattern.c_str(), dent->d_name, 0) == 0)
#endif
    {
      name = dirname + "/" + dent->d_name;
      isDir = false;
      struct stat buff;
      if(stat(name.c_str(), &buff) == 0)
        if(S_ISDIR(buff.st_mode))
          isDir = true;
      return true;
    }
  }
  return false; // unreachable
}
bool PatchFilesResourceSource::ReadNextEntry(ResourceTypeFlags typeFlags, IteratorState &state, ResourceMapEntryAgnostic &entry, std::vector<uint8_t> *optionalRawData)
{
    if (_stillMore && (_hFind == INVALID_HANDLE_VALUE))
    {
        _hFind = FindFirstFile(_gameFolderSpec.c_str(), &_findData);
    }

    _stillMore = _stillMore && (_hFind != INVALID_HANDLE_VALUE);
    bool foundOne = false;
    while (_stillMore && !foundOne)
    {
        if (PathMatchSpec(_findData.cFileName, g_szResourceSpec))
        {
            int number = ResourceNumberFromFileName(_findData.cFileName);
            if (number != -1)
            {
                // We need a valid number.
                // We do need to peek open the file right now.
                ScopedHandle patchFile;
                std::string fullPath = _gameFolder + "\\" + _findData.cFileName;
                patchFile.hFile = CreateFile(fullPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
                if (patchFile.hFile != INVALID_HANDLE_VALUE)
                {
                    // Read the first two bytes. The first is the type, the next is the offset.
                    uint8_t word[2];
                    DWORD cbRead;
                    if (ReadFile(patchFile.hFile, &word, sizeof(word), &cbRead, nullptr) && (cbRead == sizeof(word)))
                    {
                        ResourceType type = (ResourceType)(word[0] & 0x7f);
                        if (IsFlagSet(typeFlags, ResourceTypeToFlag(type)))
                        {
                            entry.Number = number;
                            entry.Offset = GetResourceOffsetInFile(word[1]) + 2;    // For the word we just read.
                            entry.Type = type;
                            entry.ExtraData = _nextIndex;
                            entry.PackageNumber = 0;

                            // This is hokey, but we need a way to know the filename for an item
                            _indexToFilename[_nextIndex] = _findData.cFileName;
                            _nextIndex++;
                            foundOne = true;
                        }
                    }
                }
            }
        }

        _stillMore = !!FindNextFile(_hFind, &_findData);
    }

    if (!_stillMore)
    {
        FindClose(_hFind);
        _hFind = INVALID_HANDLE_VALUE;
    }

    return _stillMore || foundOne;
}
bool matchInList(const TCHAR *fileName, const std::vector<generic_string> & patterns)
{
	for (size_t i = 0, len = patterns.size(); i < len; ++i)
	{
		if (PathMatchSpec(fileName, patterns[i].c_str()))
			return true;
	}
	return false;
}
Beispiel #7
0
__declspec(dllexport) int fnmatch(const char *pattern, const char *string, int flags)
{
	if (((flags & FNM_PATHNAME) != FNM_PATHNAME) || (flags & FNM_CASEFOLD) || (flags & FNM_EXTMATCH)) {
		printf("FIXME implement workaround for missing features in PathMatchSpec!\n");
		abort();
	}

	if (PathMatchSpec(string, pattern))
		return 0;
	return -1;
}
wstring ConnectedShortcut::disconnectFileName(const wstring& shortcutName)
{
	const wstring suffix = L" + " SHORT_APP_NAME L".lnk";
	if (PathMatchSpec(shortcutName.data(), (L"*" + suffix).data()) == FALSE)
		return shortcutName;

	wstring newName = shortcutName;
	newName.erase(newName.length() - suffix.length());
	newName.append(L".lnk");
	return newName;
}
STDMETHODIMP CBmpCtxMenuExt::Initialize (
                               LPCITEMIDLIST pidlFolder,
                               LPDATAOBJECT  pDO,
                               HKEY          hkeyProgID )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

COleDataObject dataobj;
HGLOBAL        hglobal;
HDROP          hdrop;
bool           bOK = false;

    dataobj.Attach ( pDO, FALSE );      // FALSE = don't release IDataObject interface when destroyed

    // Get the first selected file name.  I'll keep this simple and just check
    // the first name to see if it's a .BMP.

    hglobal = dataobj.GetGlobalData ( CF_HDROP );

    if ( NULL == hglobal )
        return E_INVALIDARG;

    hdrop = (HDROP) GlobalLock ( hglobal );

    if ( NULL == hdrop )
        return E_INVALIDARG;

    // Get the name of the first selected file.

    if ( DragQueryFile ( hdrop, 0, m_szFile, MAX_PATH ))
        {
        // Is its extension .BMP?
        if ( PathMatchSpec ( m_szFile, _T("*.bmp") ))
            {
            // Load the bitmap and attach our CBitmap object to it.
            HBITMAP hbm = (HBITMAP) LoadImage ( NULL, m_szFile, IMAGE_BITMAP, 0, 0, 
                                                LR_LOADFROMFILE );

            if ( NULL != hbm )
                {
                // We loaded the bitmap, so attach the CBitmap to it.
                VERIFY( m_bmp.Attach ( hbm ) );
                bOK = true;
                }
            }
        }

    GlobalUnlock ( hglobal );

    return bOK ? S_OK : E_FAIL;
}
bool ConnectedShortcut::isConnected(const wstring& filePath)
{
	// Shortcut: Don't try non-link files.
	if (PathMatchSpec(filePath.data(), L"*.lnk") == FALSE)
		return false;
	try {
		ConnectedShortcut csc;
		csc.load(filePath, STGM_READ);
		return csc.isConnected();
	}
	catch (std::exception&) {
		return false;
	}
}
Beispiel #11
0
int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
    wchar_t *pat = NULL;
    wchar_t *name = NULL;
    BOOL match;

    (void) __flags;

    name = c_utf8_to_locale(__name);
    pat = c_utf8_to_locale(__pattern);

    match = PathMatchSpec(name, pat);

    c_free_locale_string(pat);
    c_free_locale_string(name);
    if(match)
        return 0;
    else
        return 1;
}
Beispiel #12
0
void ScanFolder(std::vector<std::wstring>& files, std::vector<std::wstring>& filters, bool bSubfolders, const std::wstring& path)
{
	// Get folder listing
	WIN32_FIND_DATA fileData;      // Data structure describes the file found
	HANDLE hSearch;                // Search handle returned by FindFirstFile

	std::wstring searchPath = path + L"*";

	hSearch = FindFirstFile(searchPath.c_str(), &fileData);
	do
	{
		if (hSearch == INVALID_HANDLE_VALUE) break;    // No more files found

		if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			if (bSubfolders &&
				wcscmp(fileData.cFileName, L".") != 0 &&
				wcscmp(fileData.cFileName, L"..") != 0)
			{
				ScanFolder(files, filters, bSubfolders, path + fileData.cFileName + L"\\");
			}
		}
		else
		{
			if (!filters.empty())
			{
				for (int i = 0; i < filters.size(); ++i)
				{
					if (!filters[i].empty() && PathMatchSpec(fileData.cFileName, filters[i].c_str()))
					{
						files.push_back(path + fileData.cFileName);
						break;
					}
				}
			}
			else
			{
				files.push_back(path + fileData.cFileName);
			}
		}
	}
	while (FindNextFile(hSearch, &fileData));
}
BOOL IsDeleteFile(LPCTSTR lpszFilePath, LPCTSTR lpszExtList)
{
	DWORD dwSize = lstrlen(lpszExtList);
	LPTSTR lpszExtList2 = (LPTSTR)GlobalAlloc(0, (dwSize + 1) * sizeof(TCHAR));
	lstrcpy(lpszExtList2, lpszExtList);
	LPCTSTR seps = TEXT(";");
	TCHAR *next;
	LPTSTR token = wcstok_s(lpszExtList2, seps, &next);
	while (token != NULL)
	{
		if (PathMatchSpec(lpszFilePath, token))
		{
			GlobalFree(lpszExtList2);
			return TRUE;
		}
		token = wcstok_s(0, seps, &next);
	}
	GlobalFree(lpszExtList2);
	return FALSE;
}
CString GetAlbumGUID(CString csAlbum,int PLAYER_TYPE, TContentMap* inMap,bool* bAdded)
{
		CString csContentID = _T("");
		TContentMap::iterator p;
 
		// Show key
		for(p = inMap->begin(); p!=inMap->end(); ++p)
		{
			if(p->second->Source == PLAYER_TYPE && PathMatchSpec(p->second->Album,csAlbum))
			{
				csContentID = p->second->UID;
				*bAdded = true;
				break;
			}
		}
		if(!*bAdded)
		{
			csContentID = CreateGUID();
		}
		return csContentID;
}
Beispiel #15
0
//=============================================================================
//
//  DirList_MatchFilter()
//
//  Check if a specified item matches a given filter
//
BOOL DirList_MatchFilter(LPSHELLFOLDER lpsf,LPCITEMIDLIST pidl,PDL_FILTER pdlf)
{

  int i;
  WIN32_FIND_DATA fd;
  BOOL bMatchSpec;

  // Immediately return true if lpszFileSpec is *.* or NULL
  if (pdlf->nCount == 0 && !pdlf->bExcludeFilter)
    return TRUE;

  SHGetDataFromIDList(lpsf,pidl,SHGDFIL_FINDDATA,&fd,sizeof(WIN32_FIND_DATA));

  // All the directories are added
  if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    return(TRUE);

  // Check if exclude *.* after directories have been added
  if (pdlf->nCount == 0 && pdlf->bExcludeFilter)
    return FALSE;

  for (i = 0; i < pdlf->nCount; i++)
  {
    if (*pdlf->pFilter[i]) // Filters like L"\0" are ignored
    {
      bMatchSpec = PathMatchSpec(fd.cFileName,pdlf->pFilter[i]);
      if (bMatchSpec)
      {
        if (!pdlf->bExcludeFilter)
          return(TRUE);
        else
          return(FALSE);
      }
    }
  }

  // No matching
  return(pdlf->bExcludeFilter)?TRUE:FALSE;

}
Beispiel #16
0
//
// HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile)
//
// Takes strings of the form:
//   File.bmp
//   .extract
//   .extract=file.exe[,3]
HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile)
{
    HBITMAP hbmReturn = NULL;
    
    if (pszImage != NULL)
    {
        if (_stricmp(pszImage, ".none") != 0)
        {
            char szImage[MAX_PATH];
            StringCchCopy(szImage, MAX_PATH, pszImage);
            
            // Bitmap merging by Thedd
            //  Thedd - pic1.bmp|pic2.bmp merges the images. Works recursively,
            //  so pic1.bmp|.extract=whatever.dll,3|pic2.bmp also works etc...
            // bitmap merging by grd
            LPSTR pszSecondImage = strchr(szImage, '|');
            if (pszSecondImage)
            {
                HDC hdcFirst, hdcSecond, hdcResult;
                HBITMAP hbmFirst, hbmFirstOld;
                HBITMAP hbmSecond, hbmSecondOld;
                HBITMAP    hbmResult, hbmResultOld;
                HBRUSH hbrTransparent;
                RECT rc;
                int wdtFirst, hgtFirst;
                int wdtSecond, hgtSecond;
                int wdtResult, hgtResult;
                
                // get the position after the [|] character
                *pszSecondImage = '\0';
                ++pszSecondImage;
                
                // load the two bitmaps
                hbmFirst = LoadLSImage(szImage, pszFile);
                hbmSecond = LoadLSImage(pszSecondImage, pszFile);
                
                // if the second one is NULL, then there's no merging to do and
                if (hbmSecond != NULL)
                {
                    // create mem dcs for the bitmaps
                    hdcFirst = CreateCompatibleDC(NULL);
                    hdcSecond = CreateCompatibleDC(NULL);
                    
                    // select the bitmaps
                    hbmFirstOld = (HBITMAP)SelectObject(hdcFirst, hbmFirst);
                    hbmSecondOld = (HBITMAP)SelectObject(hdcSecond, hbmSecond);
                    
                    // get the bitmap sizes..
                    GetLSBitmapSize(hbmFirst, &wdtFirst, &hgtFirst);
                    GetLSBitmapSize(hbmSecond, &wdtSecond, &hgtSecond);
                    
                    // in earlier version of bitmap merge, those were painted on
                    // to each other now let's paint both images to a new one
                    
                    // and we support different sized images!! therefore:
                    wdtResult = std::max(wdtFirst, wdtSecond);
                    hgtResult = std::max(hgtFirst, hgtSecond);
                    
                    // create another dc, compatible with second dc
                    hdcResult = CreateCompatibleDC(hdcSecond);
                    
                    // create a new bitmap for the new dc and select it
                    hbmResult = CreateCompatibleBitmap(hdcSecond,
                        wdtResult, hgtResult);
                    hbmResultOld = (HBITMAP)SelectObject(hdcResult, hbmResult);
                    
                    rc.top = 0;
                    rc.left = 0;
                    rc.right = wdtResult;
                    rc.bottom = hgtResult;
                    
                    // paint the background in transparent color...
                    hbrTransparent = CreateSolidBrush(RGB(255, 0, 255));
                    FillRect(hdcResult, &rc, hbrTransparent);
                    DeleteObject(hbrTransparent);
                    
                    // first "standard blit" the second image into the new one:
                    BitBlt(hdcResult, (wdtResult - wdtSecond) / 2,
                        (hgtResult - hgtSecond) / 2, wdtSecond, hgtSecond,
                        hdcSecond, 0, 0, SRCCOPY);
                    
                    // Secondly "tranparent blit" the first image over the
                    // second one Since TransparentBltLS double buffers the
                    // painting to reduce flicker and we are using only memory
                    // DC's in this function, we will just call
                    // TransparentBltLSWorker and shave off a few BitBlt calls
                    TransparentBltLSWorker(hdcResult, wdtFirst, hgtFirst,
                        hdcFirst, 0, 0, RGB(255, 0, 255));
                    
                    // deselect the bitmap from the dc and delete the dc to get
                    // the image
                    SelectObject(hdcResult, hbmResultOld);
                    DeleteDC(hdcResult);
                    
                    // delete all used objects
                    SelectObject(hdcFirst, hbmFirstOld);
                    DeleteObject(hbmFirst);
                    DeleteDC(hdcFirst);
                    
                    SelectObject(hdcSecond, hbmSecondOld);
                    DeleteObject(hbmSecond);
                    DeleteDC(hdcSecond);
                    
                    hbmReturn = hbmResult;
                }
                else
                {
                    hbmReturn = hbmFirst;
                }
            }
            else
            {
                if (!_strnicmp(szImage, ".extract", 8 /*strlen(".extract")*/))
                {
                    HICON hIcon = NULL;
                    
                    hIcon = LoadLSIcon(szImage, pszFile);
                    
                    if (hIcon)
                    {
                        hbmReturn = BitmapFromIcon(hIcon);
                        DestroyIcon(hIcon);
                    }
                }
                else
                {
                    // Append the image name to the LiteStep image path and
                    // attempt to load the image.
                    char szExpandedImage[MAX_PATH];
                    
                    VarExpansionEx(szExpandedImage, szImage, MAX_PATH);
                    LSGetImagePath(szImage, MAX_PATH);
                    PathAppend(szImage, szExpandedImage);
                    
                    if (PathMatchSpec(szImage, "*.png"))
                    {
                        hbmReturn = LoadFromPNG(szImage);
                    }
                    else
                    {
                        hbmReturn = (HBITMAP)LoadImage(
                            NULL, szImage, IMAGE_BITMAP, 0, 0,
                            LR_DEFAULTCOLOR | LR_LOADFROMFILE);
                    }
                    
                    // If that fails, treat the image as a fully qualified path
                    // and try loading it
                    if (hbmReturn == NULL)
                    {
                        if (PathMatchSpec(szExpandedImage, "*.png"))
                        {
                            hbmReturn = LoadFromPNG(szExpandedImage);
                        }
                        else
                        {
                            hbmReturn = (HBITMAP)LoadImage(
                                NULL, szExpandedImage, IMAGE_BITMAP, 0, 0,
                                LR_DEFAULTCOLOR | LR_LOADFROMFILE);
                        }
                    }
                }
            }
        }
    }
    
    return hbmReturn;
}
Beispiel #17
0
 bool PathMatchesWildcard(const string& path, const string& wildcard)
 {
     return !!PathMatchSpec(path.c_str(), wildcard.c_str());
 }
Beispiel #18
0
BOOL CFilePath::MatchSpec(LPCTSTR psSpec)
{
    return PathMatchSpec(msPath, psSpec) != 0;
}
Beispiel #19
0
/** Iterate to next file object
 *	
 *  @returns TRUE if a next file was found, otherwise FALSE
 */
BOOL CFileIterator::Next(void)
{
	// just return if there's no more files or we weren't successfully initialized
	if (m_bNoMoreFiles) 
	{
		m_bFoundFile = FALSE;
		return FALSE;
	}
	BOOL bFound = FALSE;
	BOOL bMoreFiles;
	do 
	{
		bMoreFiles = (0 != m_ff.FindNextFile());
		if (m_ff.IsDots())
			continue;
		// if we know this isn't a shortcut, or we're not following shortcuts, then 
		// see if we have a filespec match
		if (!m_bFollowShortcuts
			|| m_ff.IsDirectory()
			|| !PathMatchSpec(m_ff.GetFileName(), _T("*.lnk"))
			)
		{
			if (m_bFollowNetworkPaths || !PathIsNetworkPath(m_ff.GetFilePath()))
			{
				if (PathMatchSpec(m_ff.GetFileName(), m_strFilespec))
				{
					bFound = TRUE;
					m_bIsShortcut = FALSE;
				}
			}
		}
		else
		{
			// this may be shortcut.   Try following it...
			WIN32_FIND_DATA fd;
			CString strTargetPath;
			if (SUCCEEDED(GetShortcutInfo(m_ff.GetFilePath(), strTargetPath.GetBuffer(MAX_SHORTCUT_PATH), MAX_SHORTCUT_PATH, &fd)))
			{
				// this is a shortcut.  If we're ignoring shortcuts to remote 
				// files/folders, then verify it's not a network path.
				if (m_bFollowNetworkPaths || !PathIsNetworkPath(strTargetPath))
				{
					// okay, try to match the filespec to it
					if (PathMatchSpec(fd.cFileName, m_strFilespec))
					{	
						bFound = TRUE;
						m_bIsShortcut = TRUE;
						m_strPath = strTargetPath;
						m_sFd = fd;
					}
				}

			}
			
			m_strPath.ReleaseBuffer();

		}

	} while (bFound == FALSE && bMoreFiles == TRUE);

	m_bFoundFile = bFound;
	m_bNoMoreFiles = !bMoreFiles;

	return bFound;
}
Beispiel #20
0
//
// LoadLSIcon(LPCSTR pszIconPath, LPCSTR pszFile)
//
// Takes strings of the form:
//   File.ico
//   libary.icl,3 <- libary extraction in imagesfolder
//   c:\path\     <- icon extraction for path out of desktop.ini
//   .extract
//   .extract=file.exe[,3]  ... and returns an icon
HICON LoadLSIcon(LPCSTR pszIconPath, LPCSTR pszFile)
{
    HICON hIcon = NULL;
    
    if (pszIconPath != NULL)
    {
        if (_stricmp(pszIconPath, ".none") != 0)
        {
            char szIconPath[MAX_PATH];
            char szIconLSImagePath[MAX_PATH];
            LPSTR pszIconFile = (LPSTR)pszIconPath;
            int nIcon = 0;
            
            // here comes a large block which does nothing but turning it into
            // the form <absolute path>[,<iconIndex>]
            
            // if .extract but nothing else is there...
            // then take the file specified as an icon (could probably be done
            // earlier, but anyhow)
            if (_stricmp(pszIconPath, ".extract") == 0)
            {
                pszIconFile = (LPSTR)pszFile;
            }
            else if (_strnicmp(pszIconPath, ".extract=", 9) == 0)
            {
                // remove ".extract=" (as we won't use it anyway)
                pszIconFile = (LPSTR)pszIconPath + 9;
            }
            
            VarExpansionEx(szIconPath, pszIconFile, MAX_PATH);
            
            if (PathIsRelative(szIconPath))
            {
                LSGetImagePath(szIconLSImagePath, MAX_PATH);
                PathAppend(szIconLSImagePath, szIconPath);
                pszIconFile = szIconLSImagePath;
            }
            else
            {
                pszIconFile = szIconPath;
            }
            
            // large block ends here, now time to separate path and index (if we
            // have an index)
            nIcon = PathParseIconLocation(pszIconFile);
            
            // now we have the two vars we would like, and the loading can begin
            // well not really, if it's a path, where we're going to get the
            // icon form desktop.ini there is just a little bit more we have to
            // do before we can start loading
            if (PathIsDirectory(pszIconFile))
            {
                char szTemp[MAX_PATH];
                
                PathAppend(pszIconFile, "desktop.ini");
                nIcon = GetPrivateProfileInt(".ShellClassInfo", "IconIndex",
                    0, pszIconFile);
                
                GetPrivateProfileString(".ShellClassInfo", "IconFile",
                    "", szTemp, MAX_PATH, pszIconFile);
                StringCchCopy(pszIconFile, MAX_PATH, szTemp);
            }
            
            // okay, now it's really time to load the icon... if it's an .ico
            // file we want to do an LoadImage() thing, otherwise it's
            // extracticon so lets find out the extension
            if (PathMatchSpec(pszIconFile, "*.ico"))
            {
                hIcon = (HICON)LoadImage(
                    NULL, pszIconFile, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
            }
            else
            {
                hIcon = ExtractIcon(GetModuleHandle(NULL), pszIconFile, nIcon);
                
                if (hIcon == (HICON)1)
                {
                    hIcon = NULL;
                }
            }
        }
    }
    
    return hIcon;
}
Beispiel #21
0
int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
    if(PathMatchSpec(__name, __pattern))
        return 0;
    else
        return 1;
}
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;
}