示例#1
0
/**
 * Install a shortcut for the virtual folder in the Windows Start Menu.
 * This method knows when we're installing under WOW64 so creating a shortcut will allow
 * the user to access the virtual folder, even when using a 32bit DLL under 64bit Windows.
 */
HRESULT UpdateStartMenuLink(LPCWSTR pstrDisplayName, LPCWSTR pstrDescription, KNOWNFOLDERID FolderId, BOOL bRegister)
{
   HRESULT Hr = S_OK;
   // Get folder for installation...
   CPidl pidlFolderPath;
   CCoTaskString strFolderPath;
   HR( pidlFolderPath.CreateFromKnownFolder(FolderId) );
   HR( pidlFolderPath.GetName(SIGDN_DESKTOPABSOLUTEPARSING, &strFolderPath) );
   // Create shortcut link...
   CComPtr<IShellLink> spLink;
   HR( spLink.CoCreateInstance(CLSID_ShellLink) );
   BOOL bIsWOW64 = FALSE; ::IsWow64Process(::GetCurrentProcess(), &bIsWOW64);
   CComBSTR bstrPath = bIsWOW64 ? L"%windir%\\syswow64\\explorer.exe" : L"%windir%\\explorer.exe";
   CComBSTR bstrIcon = bIsWOW64 ? L"%windir%\\syswow64\\shell32.dll" : L"%SystemRoot%\\system32\\shell32.dll";
   int iIconIndex = _ShellModule.GetConfigBool(VFS_HAVE_VIRTUAL_FILES) ? SIID_DRIVEFIXED : SIID_FOLDER;
   WCHAR wszArgs[MAX_PATH + 80] = { 0 };
   ::wnsprintf(wszArgs, lengthof(wszArgs) - 1, L"/separate,%s%s%s::%s", bIsWOW64 ? L"/select," : L"", static_cast<LPCWSTR>(strFolderPath), strFolderPath.IsEmpty() ? L"" : L"\\", static_cast<LPCWSTR>(CComBSTR(CLSID_ShellFolder)));
   spLink->SetPath(bstrPath);
   spLink->SetArguments(wszArgs);
   spLink->SetIconLocation(bstrIcon, iIconIndex);
   spLink->SetDescription(pstrDescription);
   // Write the link file to the Windows Start Menu...
   CComQIPtr<IPersistFile> spPersist = spLink;
   if( spPersist == NULL ) return E_UNEXPECTED;
   CCoTaskString strLinkPath;
   HR( ::SHGetKnownFolderPath(FOLDERID_StartMenu, 0, NULL, &strLinkPath) );
   WCHAR wszLinkFilename[MAX_PATH] = { 0 };
   ::wnsprintf(wszLinkFilename, lengthof(wszLinkFilename) - 1, L"%s\\%s.lnk", static_cast<LPCWSTR>(strLinkPath), pstrDisplayName);
   if( bRegister ) Hr = spPersist->Save(wszLinkFilename, TRUE);
   else ::DeleteFileW(wszLinkFilename);
   return Hr;
}
示例#2
0
/**
 * Return property information.
 */
HRESULT CNseBaseItem::GetProperty(REFPROPERTYKEY pkey, CComPropVariant& v)
{
   ATLASSERT(v.vt==VT_EMPTY);
   if( pkey == PKEY_ParsingName ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromString(wfd.cFileName, &v);
   }
   if( pkey == PKEY_ItemName ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromString(wfd.cFileName, &v);
   }
   if( pkey == PKEY_ItemNameDisplay ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromString(wfd.cFileName, &v);
   }
   if( pkey == PKEY_FileName ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromString(wfd.cFileName, &v);
   }
   if( pkey == PKEY_FileAttributes ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromUInt32(wfd.dwFileAttributes, &v);
   }
   if( pkey == PKEY_ParsingPath ) {
      CCoTaskString strPath;
      CPidl pidlFull(m_pFolder->m_pidlRoot, m_pidlFolder, m_pidlItem);
      HR( ::SHGetNameFromIDList(pidlFull, SIGDN_DESKTOPABSOLUTEPARSING, &strPath) );
      return ::InitPropVariantFromString(strPath, &v);
   }
   if( pkey == PKEY_ItemPathDisplay ) {
      CCoTaskString strPath;
      CPidl pidlFull(m_pFolder->m_pidlRoot, m_pidlFolder, m_pidlItem);
      HR( ::SHGetNameFromIDList(pidlFull, SIGDN_DESKTOPABSOLUTEEDITING, &strPath) );
      return ::InitPropVariantFromString(strPath, &v);
   }
   if( pkey == PKEY_ItemPathDisplayNarrow ) {
      CComPropVariant vDispName;
      HR( GetProperty(PKEY_ItemNameDisplay, vDispName) );
      HR( vDispName.ChangeType(VT_LPWSTR) );
      CCoTaskString strParent;
      HR( ::SHGetNameFromIDList(m_pFolder->m_pidlMonitor, SIGDN_DESKTOPABSOLUTEEDITING, &strParent) );
      WCHAR wszNarrow[MAX_PATH + 4] = { 0 };
      ::wnsprintf(wszNarrow, lengthof(wszNarrow) - 1, L"%s (%s)", vDispName.pwszVal, static_cast<LPCWSTR>(strParent));
      return ::InitPropVariantFromString(strParent.IsEmpty() ? vDispName.pwszVal : wszNarrow, &v);
   }
   if( pkey == PKEY_ItemFolderPathDisplay ) {
      CCoTaskString strFolder;
      HR( ::SHGetNameFromIDList(m_pFolder->m_pidlMonitor, SIGDN_DESKTOPABSOLUTEEDITING, &strFolder) );
      return ::InitPropVariantFromString(strFolder, &v);
   }
   if( pkey == PKEY_ItemFolderPathDisplayNarrow ) {
      CCoTaskString strFolder;
      HR( ::SHGetNameFromIDList(m_pFolder->m_pidlMonitor, SIGDN_DESKTOPABSOLUTEEDITING, &strFolder) );
      LPWSTR pstrSep = wcsrchr(strFolder, '\\');
      if( pstrSep == NULL ) pstrSep = L"\0\0"; else *pstrSep = '\0';
      WCHAR wszNarrow[MAX_PATH + 4] = { 0 };
      ::wnsprintf(wszNarrow, lengthof(wszNarrow) - 1, L"%s (%s)", pstrSep + 1, static_cast<LPCWSTR>(strFolder));
      return ::InitPropVariantFromString(pstrSep[1] == '\0' ? static_cast<LPCWSTR>(strFolder) : wszNarrow, &v);
   }
   if( pkey == PKEY_ItemType ) {
      // Assume no canonical type; return V_EMPTY
      return S_OK;
   }
   if( pkey == PKEY_ItemTypeText ) {
      // Assume no canonical type; return V_EMPTY
      return S_OK;
   }
   if( pkey == PKEY_PerceivedType ) {
      return ::InitPropVariantFromInt32(PERCEIVED_TYPE_UNKNOWN, &v);
   }
   if( pkey == PKEY_FindData ) {
      const VFS_FIND_DATA wfd = GetFindData();
      return ::InitPropVariantFromBuffer(&wfd, sizeof(WIN32_FIND_DATAW), &v);
   }
   if( pkey == PKEY_SFGAOFlags ) {
      return ::InitPropVariantFromUInt32(GetSFGAOF((SFGAOF)(~SFGAO_VALIDATE)), &v);
   }
   if( pkey == PKEY_DescriptionID ) {
      SHDESCRIPTIONID did = { SHDID_FS_OTHER, CLSID_ShellFolder };
      return ::InitPropVariantFromBuffer(&did, sizeof(did), &v);
   }
   if( pkey == PKEY_Volume_IsRoot ) {
      return ::InitPropVariantFromBoolean(IsRoot(), &v);
   }
#if _WINVER > _WIN32_WINNT_LONGHORN
   if( pkey == PKEY_NamespaceCLSID ) {
      return ::InitPropVariantFromCLSID(CLSID_ShellFolder, &v);
   }
   if( pkey == PKEY_IsPinnedToNameSpaceTree ) {
      return ::InitPropVariantFromBoolean(IsRoot(), &v);
   }
#endif // _WIN32_WINNT_LONGHORN
   return E_FAIL;
}