void DocumentIconFinder::useIconFromFile(const wstring& iconFile)
{
	TCHAR buffer[MAX_PATH];
	throwOnFailure<OleException>(
		StringCchCopy(buffer, MAX_PATH, iconFile.data()));
	m_iconIndex = PathParseIconLocation(buffer);
	m_iconFile = buffer;
}
Example #2
0
CFilePath CFilePath::SplitIconLocation(
    CString const &sPathIcon,
    int *pnIcon,
    DWORD dwCleanup)
{
    CString sPath = sPathIcon;
    int icon = PathParseIconLocation(CStringLock(sPath));
    if (pnIcon)
        *pnIcon = icon;

    return CFilePath(sPath, dwCleanup & ~epcRemoveIconLocation);
}
Example #3
0
CFilePath &CFilePath::Clean(DWORD dwCleanup)
{
    if (dwCleanup & epcRemoveArgs)
    {
        if (dwCleanup & epcTrim)
            msPath.TrimLeft();

        PathRemoveArgs(CStringLock(msPath));
    }

    if (dwCleanup & epcRemoveIconLocation)
        PathParseIconLocation(CStringLock(msPath));

    if (dwCleanup & epcTrim)
        Trim();

    if (dwCleanup & epcUnquote)
    {
        Unquote();

        if (dwCleanup & epcTrimInQuote)
            Trim();
    }

    if (dwCleanup & epcExpandEnvStrings)
        ExpandEnvStrings();

    if (dwCleanup & epcCanonicalize)
        Canonicalize();

    if (dwCleanup & epcRemoveXXL)
        ShrinkXXLPath();

    if (dwCleanup & epcSlashToBackslash)
        msPath.Replace('/', '\\');

    if (dwCleanup & epcMakePretty)
        MakePretty();

    return *this;
}
Example #4
0
//関連付けを取得
//Extの情報を元に、FileTypeとそのIconについて調べる
bool AssocGetAssociation(ASSOCINFO &AssocInfo)
{
	if(AssocInfo.Ext.IsEmpty()){
		TRACE(_T("AssocGetAssociation():Ext is Empty\n"));
		return false;
	}
	HKEY hKey;
	LONG Ret = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, AssocInfo.Ext, NULL, KEY_READ, &hKey);
	if(ERROR_SUCCESS!=Ret){
		TRACE(_T("AssocGetAssociation():Failed to Open '%s'\n"),AssocInfo.Ext);
		return false;
	}
	//拡張子を小文字で統一する
	AssocInfo.Ext.MakeLower();
	//拡張子に対応するFileType取得
	std::vector<BYTE> Buffer;
	DWORD dwRead=0;
	::RegQueryValueEx(hKey, NULL, NULL, NULL, NULL,&dwRead);
	Buffer.assign(dwRead+1,0);
	Ret = ::RegQueryValueEx(hKey, NULL, NULL, NULL, &Buffer.at(0),&dwRead);
	if(ERROR_SUCCESS!=Ret){
		::RegCloseKey(hKey);
		TRACE(_T("AssocGetAssociation():Failed to Get FileType\n"));
		return false;
	}
	CString FileType=(TCHAR*)&Buffer.at(0);

	//オリジナルのFileType
	/*
	1.FileTypeが無いとき、OrgFIleType=.???\OrgFileType(NULLにもなりうる)
	2.FileTypeがLhaForgeArchive_*以外の時、OrgFileType=.???\(Default)
	3.FileTypeがLhaForgeArchive_*のとき、OrgFileType=.???\OrgFileType
	*/
	//1.と3.のとき
	if(0==FileType.Left(_tcslen(ASSOC_PREFIX)).CompareNoCase(ASSOC_PREFIX)){
		AssocInfo.bOrgStatus=true;
	}
	else{
		AssocInfo.bOrgStatus=false;
	}
	if(FileType.IsEmpty()||(0==FileType.Left(_tcslen(ASSOC_PREFIX)).CompareNoCase(ASSOC_PREFIX))){
		::RegQueryValueEx(hKey, _T("LhaForgeOrgFileType"), NULL, NULL, NULL,&dwRead);
		Buffer.assign(dwRead+1,0);
		Ret = ::RegQueryValueEx(hKey, _T("LhaForgeOrgFileType"), NULL, NULL, &Buffer.at(0),&dwRead);
		::RegCloseKey(hKey);
		if(ERROR_SUCCESS!=Ret){
			AssocInfo.OrgFileType.Empty();
			TRACE(_T("AssocGetAssociation():Failed to Get OrgFileType\n"));
		}
		else{
			AssocInfo.OrgFileType=(TCHAR*)&Buffer.at(0);
		}
	}
	else{	//2.のとき
		AssocInfo.OrgFileType=FileType;
		::RegCloseKey(hKey);
	}

	//------------------------------
	// FileTypeからアイコン情報取得
	//------------------------------
	CString KeyNameBuffer=FileType;
	KeyNameBuffer+=_T("\\DefaultIcon");
	Ret = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, KeyNameBuffer, NULL, KEY_READ, &hKey);
	if(ERROR_SUCCESS!=Ret){
		TRACE(_T("AssocGetAssociation('%s'):Failed to Open '%s' for Default Icon\n"),AssocInfo.Ext,KeyNameBuffer);
		return false;
	}

	dwRead=0;
	::RegQueryValueEx(hKey, NULL, NULL, NULL, NULL,&dwRead);
	Buffer.assign(dwRead+1,0);
	Ret = ::RegQueryValueEx(hKey, NULL, NULL, NULL, &Buffer.at(0),&dwRead);
	::RegCloseKey(hKey);
	if(ERROR_SUCCESS!=Ret){
		TRACE(_T("AssocGetAssociation():Failed to Get IconInfo\n"));
		return false;
	}
	//アイコン情報の取得
	AssocInfo.IconFile=(TCHAR*)&Buffer.at(0);
	AssocInfo.IconIndex=PathParseIconLocation(AssocInfo.IconFile.GetBuffer(_MAX_PATH*2));
	AssocInfo.IconFile.ReleaseBuffer();
	TRACE(_T("***%d:::%s\n"),AssocInfo.IconIndex,AssocInfo.IconFile);

	AssocInfo.OrgIconFile=AssocInfo.IconFile;
	AssocInfo.OrgIconIndex=AssocInfo.IconIndex;

	//----------------------------
	// Shell\Openのコマンドを読む
	//----------------------------
	if(!AssocInfo.bOrgStatus){
		//関連付けされていない
		return true;
	}
	KeyNameBuffer=FileType;
	KeyNameBuffer+=_T("\\shell\\open\\command");
	Ret = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, KeyNameBuffer, NULL, KEY_READ, &hKey);
	if(ERROR_SUCCESS!=Ret){
		TRACE(_T("AssocGetAssociation():Failed to Open '%s' for Open Command\n"),KeyNameBuffer);
		return false;
	}

	dwRead=0;
	::RegQueryValueEx(hKey, NULL, NULL, NULL, NULL,&dwRead);
	Buffer.assign(dwRead+1,0);
	Ret = ::RegQueryValueEx(hKey, NULL, NULL, /*&ValueType*/NULL, &Buffer.at(0),&dwRead);
	::RegCloseKey(hKey);
	if(ERROR_SUCCESS!=Ret){
		TRACE(_T("AssocGetAssociation():Failed to Get ShellOpenCommand\n"));
		return false;
	}
	AssocInfo.ShellOpenCommand=(TCHAR*)&Buffer.at(0);

	return true;
}
Example #5
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;
}
Example #6
0
BOOL _ShellImageListInit(int cxIcon, int cyIcon, int cxSmIcon, int cySmIcon, UINT flags, BOOL fRestore)
{
    int i;
    TCHAR szModule[MAX_PATH];
    HKEY hkeyIcons;

    ASSERTCRITICAL;

    if (himlIcons == NULL) {
        himlIcons = ImageList_Create(cxIcon, cyIcon, ILC_MASK|ILC_SHARED|flags, 0, 32);
    }
    else {
        ImageList_Remove(himlIcons, -1);
        ImageList_SetIconSize(himlIcons, cxIcon, cyIcon);
    }

    if (himlIcons == NULL) {
        return FALSE;
    }

    if (himlIconsSmall == NULL) {
        himlIconsSmall = ImageList_Create(cxSmIcon, cySmIcon, ILC_MASK|ILC_SHARED|flags, 0, 32);
    }
    else {
        ImageList_Remove(himlIconsSmall, -1);
        ImageList_SetIconSize(himlIconsSmall, cxSmIcon, cySmIcon);
    }

    if (himlIconsSmall == NULL) {
        ImageList_Destroy(himlIcons);
        himlIcons = NULL;
        return FALSE;
    }

    // set the bk colors to COLOR_WINDOW since this is what will
    // be used most of the time as the bk for these lists (cabinet, tray)
    // this avoids having to do ROPs when drawing, thus making it fast

    ImageList_SetBkColor(himlIcons, GetSysColor(COLOR_WINDOW));
    ImageList_SetBkColor(himlIconsSmall, GetSysColor(COLOR_WINDOW));

    GetModuleFileName(HINST_THISDLL, szModule, ARRAYSIZE(szModule));

    // WARNING: this code assumes that these icons are the first in
    // our RC file and are in this order and these indexes correspond
    // to the II_ constants in shell.h.

    hkeyIcons =
        SHGetExplorerSubHkey(HKEY_LOCAL_MACHINE, g_szShellIcons, FALSE);

    for (i = 0; i < ARRAYSIZE(c_SystemImageListIndexes); i++) {

        HICON hIcon=NULL;
        HICON hSmallIcon=NULL;
        int iIndex;

        //
        // Load all of the icons with fRestore == TRUE, or only the overlays
        // if fRestore == FALSE.
        //
        if (fRestore || (i >= II_OVERLAYFIRST && i <= II_OVERLAYLAST))
        {
            //
            // check to see if icon is overridden in the registry
            //
            if (hkeyIcons)
            {
                TCHAR val[10];
                TCHAR ach[MAX_PATH];
                DWORD cb=MAX_PATH;
                int iIcon;

                wsprintf(val, g_szD, i);

                ach[0] = 0;
                RegQueryValueEx(hkeyIcons, val, NULL, NULL, (LPBYTE)ach, &cb);

                if (ach[0])
                {
                    HICON hIcons[2] = {0, 0};

                    iIcon = PathParseIconLocation(ach);

                    ExtractIcons(ach, iIcon,
                        MAKELONG(g_cxIcon,g_cxSmIcon),
                        MAKELONG(g_cyIcon,g_cySmIcon),
                        hIcons, NULL, 2, g_lrFlags);

                    hIcon = hIcons[0];
                    hSmallIcon = hIcons[1];

                    if (hIcon)
                    {
                        DebugMsg(DM_TRACE, TEXT("ShellImageListInit: Got default icon #%d from registry: %s,%d"), i, ach, iIcon);
                    }
                }
            }


            if (hIcon == NULL)
            {
                hIcon      = LoadImage(HINST_THISDLL, MAKEINTRESOURCE(c_SystemImageListIndexes[i]), IMAGE_ICON, cxIcon, cyIcon, g_lrFlags);
                hSmallIcon = LoadImage(HINST_THISDLL, MAKEINTRESOURCE(c_SystemImageListIndexes[i]), IMAGE_ICON, cxSmIcon, cySmIcon, g_lrFlags);
            }

            if (hIcon)
            {
                iIndex = SHAddIconsToCache(hIcon, hSmallIcon, szModule, i, 0);
                Assert(iIndex == i);     // assume index

                if (i >= II_OVERLAYFIRST && i <= II_OVERLAYLAST)
                {
                    ImageList_SetOverlayImage(himlIcons,      iIndex, i - II_OVERLAYFIRST + 1);
                    ImageList_SetOverlayImage(himlIconsSmall, iIndex, i - II_OVERLAYFIRST + 1);
                }
            }
        }
    }

    if (hkeyIcons)
        RegCloseKey(hkeyIcons);

    return TRUE;
}