void FacadeDocumentProviderImpl::Configure() { wchar_t fileName[_MAX_PATH] = {0}; if(0 >= ::GetModuleFileNameW(NULL, fileName, _MAX_PATH)) throw Workshare::System::SystemException(_T("Failed to get the filename of the running executable")); PathRemoveExtensionW(fileName); PathStripPathW(fileName); DialogStyle style = dsTab; if(0 == lstrcmpiW(fileName, L"winword")) { style = dsWizard; } else if(0 == lstrcmpiW(fileName, L"WmConfigAssistant")) { style = dsWcaWizard; } else if(0 == lstrcmpiW(fileName, L"WmConfigPixie")) { style = dsWcaWizard; } else if(0 == lstrcmpiW(fileName, L"Msiexec")) { style = dsWcaWizard; } ConnectorManager::Configure(GetConnector(), style); }
bool TESTEXPORT RelatedByName(const std::wstring& fileName1, const std::wstring& fileName2) { if (fileName1.empty()) throw Workshare::ArgumentException(_T("fileName1"), _T("The first file name must be specified to check for a relationship.")); if(0 == lstrcmpiW(fileName1.c_str(), fileName2.c_str())) return false; wchar_t noExtension1[_MAX_PATH] = {0}; wchar_t noExtension2[_MAX_PATH] = {0}; lstrcpynW(noExtension1, fileName1.c_str(), _MAX_PATH); lstrcpynW(noExtension2, fileName2.c_str(), _MAX_PATH); PathRemoveExtensionW(noExtension1); PathRemoveExtensionW(noExtension2); return (0 == lstrcmpiW(noExtension1, noExtension2)); }
/************************************************************************* * PathRemoveExtension [SHELL32.250] */ void WINAPI PathRemoveExtensionAW(LPVOID lpszPath) { if (SHELL_OsIsUnicode()) PathRemoveExtensionW(lpszPath); else PathRemoveExtensionA(lpszPath); }
void TestDominoDocArtifact::TestName() { DomDocHelper domDocHelper(TEST_ARTIFACT_FILE); DominoDocArtifact validArtifact(m_spLibrary, domDocHelper.DocumentId, domDocHelper.GetVersionLabel()); wchar_t fileName[_MAX_PATH] = {0}; lstrcpynW(fileName, PathFindFileNameW(TEST_ARTIFACT_FILE), _MAX_PATH); PathRemoveExtensionW(fileName); assertEquals(domDocHelper.GetFileNameWithoutExtension(), validArtifact.Name); }
bool CLoggingImp::InitLogging() { if (!SHGetSpecialFolderPathW(0, m_wszLogDir, CSIDL_APPDATA, TRUE)) { return false; } PathAppendW(m_wszLogDir, L"Logging"); if (!CreateDirectoryW(m_wszLogDir, 0) && GetLastError() != ERROR_ALREADY_EXISTS) { return false; } CleanOldLog(); wchar_t wszBaseName[MAX_PATH] = {0}; if (!GetModuleFileNameW(0, wszBaseName, MAX_PATH)) { return false; } PathRemoveExtensionW(wszBaseName); PathStripPathW(wszBaseName); wchar_t wszLogFile[MAX_PATH] = {0}; HRESULT hr = StringCchPrintfW(wszLogFile, MAX_PATH, L"%s\\%s_PID%d_%d.log", m_wszLogDir, wszBaseName, GetCurrentProcessId(), GetTickCount()); if (FAILED(hr)) { return false; } //create file std::locale loc(""); m_logwfstream.imbue(loc); m_logwfstream.open(wszLogFile, std::ios_base::out); //TODO: what mode? if (!m_logwfstream) { return false; } //initialize critical section bool bOk = true; try { InitializeCriticalSection(&m_csWriteFile); } catch (...) { bOk = false; m_logwfstream.close(); } m_logwfstream << L"\t\tIF ANY ERROR OCCURRED, " L"PLS CONTACT ME: [email protected].\n\n\n"; return bOk; }
/************************************************************************** * IQueryAssociations_GetString {SHLWAPI} * * Get a file association string from the registry. * * PARAMS * iface [I] IQueryAssociations interface to query * cfFlags [I] ASSOCF_ flags from "shlwapi.h" * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h") * pszExtra [I] Extra information about the string location * pszOut [O] Destination for the association string * pcchOut [I/O] Length of pszOut * * RETURNS * Success: S_OK. pszOut contains the string, pcchOut contains its length. * Failure: An HRESULT error code indicating the error. */ static HRESULT WINAPI IQueryAssociations_fnGetString( IQueryAssociations *iface, ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut) { IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface; const ASSOCF cfUnimplemented = ~(0); DWORD len = 0; HRESULT hr; WCHAR path[MAX_PATH]; TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str, debugstr_w(pszExtra), pszOut, pcchOut); if (cfFlags & cfUnimplemented) FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented); if (!pcchOut) return E_UNEXPECTED; switch (str) { case ASSOCSTR_EXECUTABLE: { hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len); if (FAILED(hr)) return hr; len++; return ASSOC_ReturnData(pszOut, pcchOut, path, len); } case ASSOCSTR_FRIENDLYAPPNAME: { PVOID verinfoW = NULL; DWORD size, retval = 0; UINT flen; WCHAR *bufW; static const WCHAR translationW[] = { '\\','V','a','r','F','i','l','e','I','n','f','o', '\\','T','r','a','n','s','l','a','t','i','o','n',0 }; static const WCHAR fileDescFmtW[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o', '\\','%','0','4','x','%','0','4','x', '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0 }; WCHAR fileDescW[41]; hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len); if (FAILED(hr)) return hr; retval = GetFileVersionInfoSizeW(path, &size); if (!retval) goto get_friendly_name_fail; verinfoW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval); if (!verinfoW) return E_OUTOFMEMORY; if (!GetFileVersionInfoW(path, 0, retval, verinfoW)) goto get_friendly_name_fail; if (VerQueryValueW(verinfoW, translationW, (LPVOID *)&bufW, &flen)) { UINT i; DWORD *langCodeDesc = (DWORD *)bufW; for (i = 0; i < flen / sizeof(DWORD); i++) { sprintfW(fileDescW, fileDescFmtW, LOWORD(langCodeDesc[i]), HIWORD(langCodeDesc[i])); if (VerQueryValueW(verinfoW, fileDescW, (LPVOID *)&bufW, &flen)) { /* Does strlenW(bufW) == 0 mean we use the filename? */ len = strlenW(bufW) + 1; TRACE("found FileDescription: %s\n", debugstr_w(bufW)); return ASSOC_ReturnData(pszOut, pcchOut, bufW, len); } } } get_friendly_name_fail: PathRemoveExtensionW(path); PathStripPathW(path); TRACE("using filename: %s\n", debugstr_w(path)); return ASSOC_ReturnData(pszOut, pcchOut, path, strlenW(path) + 1); } default: FIXME("assocstr %d unimplemented!\n", str); return E_NOTIMPL; } }
void DominoDocArtifact::Upload(const std::wstring& fileToUpload) { if(!PathFileExistsW(fileToUpload.c_str())) throw Workshare::System::IO::FileNotFoundException(_bstr_t(fileToUpload.c_str()), _T("Only files that exist can be uploaded to a Lotus Domino Repository")); DominoDoc::IDocumentPtr spDocument = GetDocument(); wchar_t tempPath[MAX_PATH] = {0}; if(0 == ::GetTempPathW(MAX_PATH, tempPath)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to get the temporary path while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } wchar_t tempFileName[_MAX_PATH] = {0}; if(0 == GetTempFileNameW(tempPath, L"WC", 0, tempFileName)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to get the temporary filename while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } DeleteFileW(tempFileName); PathRemoveExtensionW(tempFileName); if(!::CreateDirectoryW(tempFileName, NULL)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to create a temporary directory [") << tempFileName << _T(", to upload [") << fileToUpload << _T("] for uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } wchar_t fileName[MAX_PATH] = {0}; lstrcpyW(fileName, tempFileName); if(spDocument->FileName.length() > 0) PathAppendW(fileName,spDocument->FileName); else PathAppendW(fileName, PathFindFileNameW(fileToUpload.c_str())); if(!CopyFileW(fileToUpload.c_str(), fileName, TRUE)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to copy [") << fileToUpload << _T("] to [") << fileName << _T("] while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } try { spDocument->SetToWorkingCopy(); spDocument->SetContents(fileName); spDocument->Save(); spDocument->CheckIn(c_revisiontypeDraft, 1, VARIANT_FALSE, "Created By Workshare"); wchar_t versionLabel[32] = {0}; _snwprintf(versionLabel, 32, L"%d.%d", spDocument->VersionNumber, spDocument->DraftNumber); m_versionLabel = versionLabel; Log(_T("The file [%S] was uploaded to the Domino.Doc library [%S] as document [%S]"), fileToUpload.c_str(), m_libraryUrl.c_str(), m_documentId.c_str()); DeleteFileW(fileName); RemoveDirectoryW(tempFileName); } catch(...) { DeleteFileW(fileName); RemoveDirectoryW(tempFileName); throw; } }
Artifact DominoDocArtifact::CreateRelatedItem(const std::wstring& filenameToRelate, const std::wstring& type,const std::wstring& AvailableFileFormats,bool ShowUI) { // HACKETY UNREFERENCED_PARAMETER(AvailableFileFormats); UNREFERENCED_PARAMETER(ShowUI); if(0 != lstrcmpiW(type.c_str(), L"W3")) throw Workshare::ArgumentException(_T("type"), _T("We only support the W3 type")); if(filenameToRelate.empty()) throw Workshare::ArgumentException(_T("filenameToRelate"), _T("We need a file name to create a related item.")); if(!PathFileExistsW(filenameToRelate.c_str())) throw Workshare::System::IO::FileNotFoundException(_bstr_t(filenameToRelate.c_str()), _T("Only files that exist can be uploaded to a Lotus Domino Repository")); DominoDoc::IDocumentPtr spDocument = GetDocument(); wchar_t tempPath[MAX_PATH] = {0}; if(0 == ::GetTempPathW(MAX_PATH, tempPath)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to get the temporary path while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } wchar_t tempFileName[_MAX_PATH] = {0}; if(0 == GetTempFileNameW(tempPath, L"WC", 0, tempFileName)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to get the temporary filename while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } DeleteFileW(tempFileName); PathRemoveExtensionW(tempFileName); if(!::CreateDirectoryW(tempFileName, NULL)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << "Failed to create a temporary directory [" << tempFileName << ", to upload [" << filenameToRelate << "] for uploading artifact, " << m_documentId << ", version, " << m_versionLabel << " which came from repository, " << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } wchar_t fileName[MAX_PATH] = {0}; lstrcpyW(fileName, tempFileName); if(spDocument->FileName.length() > 0) PathAppendW(fileName,spDocument->FileName); else PathAppendW(fileName, PathFindFileNameW(filenameToRelate.c_str())); PathRemoveExtensionW(fileName); lstrcatW(fileName, L"."); lstrcatW(fileName, type.c_str()); if(!CopyFileW(filenameToRelate.c_str(), fileName, TRUE)) { DWORD lastError = ::GetLastError(); std::tostringstream msg; msg << _T("Failed to copy [") << filenameToRelate << _T("] to [") << fileName << _T("] while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends; throw Workshare::System::SystemException(msg.str().c_str(), lastError); } try { DominoDoc::IBinderPtr spBinder = spDocument->Binder; DominoDoc::IDocumentsPtr spDocuments = spBinder->Documents; DominoDoc::IDocumentPtr spRelatedDocument = spDocuments->Add(); std::wstring title = this->Name + L".W3"; spRelatedDocument->Title = title.c_str(); spRelatedDocument->Description = L"File Used by workshare during the collaboration process"; spRelatedDocument->SetContents(fileName); spRelatedDocument->Save(); spRelatedDocument->CheckIn(c_revisiontypeVersion, c_actionReplace, VARIANT_TRUE, _T("Workshare Collaboration Document")); DeleteFileW(fileName); RemoveDirectoryW(tempFileName); return new DominoDocArtifact(spRelatedDocument); } catch(...) { DeleteFileW(fileName); RemoveDirectoryW(tempFileName); throw; } }
static void on_theme_install(HWND dialog) { static const WCHAR filterMask[] = {0,'*','.','m','s','s','t','y','l','e','s',';', '*','.','t','h','e','m','e',0,0}; static const WCHAR themeExt[] = {'.','T','h','e','m','e',0}; const int filterMaskLen = sizeof(filterMask)/sizeof(filterMask[0]); OPENFILENAMEW ofn; WCHAR filetitle[MAX_PATH]; WCHAR file[MAX_PATH]; WCHAR filter[100]; WCHAR title[100]; LoadStringW (GetModuleHandleW(NULL), IDS_THEMEFILE, filter, sizeof (filter) / sizeof (filter[0]) - filterMaskLen); memcpy (filter + lstrlenW (filter), filterMask, filterMaskLen * sizeof (WCHAR)); LoadStringW (GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, sizeof (title) / sizeof (title[0])); ofn.lStructSize = sizeof(OPENFILENAMEW); ofn.hwndOwner = dialog; ofn.hInstance = 0; ofn.lpstrFilter = filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 0; ofn.lpstrFile = file; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(file)/sizeof(filetitle[0]); ofn.lpstrFileTitle = filetitle; ofn.lpstrFileTitle[0] = '\0'; ofn.nMaxFileTitle = sizeof(filetitle)/sizeof(filetitle[0]); ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = title; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = NULL; ofn.lCustData = 0; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; if (GetOpenFileNameW(&ofn)) { static const WCHAR themesSubdir[] = { '\\','T','h','e','m','e','s',0 }; static const WCHAR backslash[] = { '\\',0 }; WCHAR themeFilePath[MAX_PATH]; SHFILEOPSTRUCTW shfop; if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, themeFilePath))) return; if (lstrcmpiW(PathFindExtensionW(filetitle), themeExt)==0) { do_parse_theme(file); SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0); return; } PathRemoveExtensionW (filetitle); /* Construct path into which the theme file goes */ lstrcatW (themeFilePath, themesSubdir); lstrcatW (themeFilePath, backslash); lstrcatW (themeFilePath, filetitle); /* Create the directory */ SHCreateDirectoryExW (dialog, themeFilePath, NULL); /* Append theme file name itself */ lstrcatW (themeFilePath, backslash); lstrcatW (themeFilePath, PathFindFileNameW (file)); /* SHFileOperation() takes lists as input, so double-nullterminate */ themeFilePath[lstrlenW (themeFilePath)+1] = 0; file[lstrlenW (file)+1] = 0; /* Do the copying */ WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file), wine_dbgstr_w (themeFilePath)); shfop.hwnd = dialog; shfop.wFunc = FO_COPY; shfop.pFrom = file; shfop.pTo = themeFilePath; shfop.fFlags = FOF_NOCONFIRMMKDIR; if (SHFileOperationW (&shfop) == 0) { scan_theme_files(); if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO), GetDlgItem (dialog, IDC_THEME_COLORCOMBO), GetDlgItem (dialog, IDC_THEME_SIZECOMBO))) { SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0); SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0); enable_size_and_color_controls (dialog, FALSE); } else { enable_size_and_color_controls (dialog, TRUE); } } else WINE_TRACE("copy operation failed\n"); } else WINE_TRACE("user cancelled\n"); }
// Loads the IShellLibrary interface for the specified item, calls the derived class to perform an operation on // the library, and commits/saves any changes as needed. HRESULT v_ExecuteCommand() { HRESULT hr; if (_fCreate) { // If we're in 'create' mode, instantiate a new IShellLibrary in memory. hr = SHCreateLibrary(IID_PPV_ARGS(&_plib)); } else { // Otherwise, load it from the specified IShellItem. const DWORD grfMode = _fReadOnly ? (STGM_READ | STGM_SHARE_DENY_WRITE) : (STGM_READWRITE | STGM_SHARE_EXCLUSIVE); hr = SHLoadLibraryFromItem(_psiLibrary, grfMode, IID_PPV_ARGS(&_plib)); } if (SUCCEEDED(hr)) { // Call the derived class to execute the operation on the library. hr = v_ExecuteLibCommand(); if (SUCCEEDED(hr) && !_fReadOnly) { if (_fCreate) { // We created a new library in memory; now save it to disk. // The IShellLibrary::Save API takes the destination in the form of the parent folder, and the name // of the library (without any file extension). However, the argument is in the form of a full file // system path, possibly including the extension. So, we need to parse it into that form. For example: // "C:\some\folder\stuff.library-ms" => "C:\some\folder", "stuff" PWSTR pszName = PathFindFileNameW(_pszSavePath); if (StrCmpICW(PathFindExtensionW(pszName), L".library-ms") == 0) { PathRemoveExtensionW(pszName); } PathRemoveFileSpec(_pszSavePath); // Save the library with the specified name in the specified folder. PWSTR pszSavedToPath; hr = SHSaveLibraryInFolderPath(_plib, _pszSavePath, pszName, _lsfSaveOptions, &pszSavedToPath); if (SUCCEEDED(hr)) { // The API returns the full file system path that the library was saved to. // (This may or may not match the original argument, depending on whether LSF_MAKEUNIQUENAME was specified.) Output(L"Library saved to path: %s\n", pszSavedToPath); CoTaskMemFree(pszSavedToPath); } else { RuntimeError(L"Error %#08x saving library to path: %s\\%s.library-ms\n", hr, _pszSavePath, pszName); } } else { // We're operating on an existing library; commit the changes to disk. hr = _plib->Commit(); if (SUCCEEDED(hr)) { Output(L"Changes successfully committed.\n"); } } } } else { RuntimeError(L"Error %#08x loading library from path: %s\n", hr, _pszSavePath); } return hr; }
/************************************************************************** * IQueryAssociations_GetString * * Get a file association string from the registry. * * PARAMS * cfFlags [I] ASSOCF_ flags from "shlwapi.h" * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h") * pszExtra [I] Extra information about the string location * pszOut [O] Destination for the association string * pcchOut [I/O] Length of pszOut * * RETURNS * Success: S_OK. pszOut contains the string, pcchOut contains its length. * Failure: An HRESULT error code indicating the error. */ HRESULT STDMETHODCALLTYPE CQueryAssociations::GetString( ASSOCF flags, ASSOCSTR str, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut) { const ASSOCF unimplemented_flags = ~ASSOCF_NOTRUNCATE; DWORD len = 0; HRESULT hr; WCHAR path[MAX_PATH]; TRACE("(%p)->(0x%08x, %u, %s, %p, %p)\n", this, flags, str, debugstr_w(pszExtra), pszOut, pcchOut); if (flags & unimplemented_flags) { FIXME("%08x: unimplemented flags\n", flags & unimplemented_flags); } if (!pcchOut) { return E_UNEXPECTED; } if (!this->hkeySource && !this->hkeyProgID) { return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION); } switch (str) { case ASSOCSTR_COMMAND: { WCHAR *command; hr = this->GetCommand(pszExtra, &command); if (SUCCEEDED(hr)) { hr = this->ReturnString(flags, pszOut, pcchOut, command, strlenW(command) + 1); HeapFree(GetProcessHeap(), 0, command); } return hr; } case ASSOCSTR_EXECUTABLE: { hr = this->GetExecutable(pszExtra, path, MAX_PATH, &len); if (FAILED(hr)) { return hr; } len++; return this->ReturnString(flags, pszOut, pcchOut, path, len); } case ASSOCSTR_FRIENDLYDOCNAME: { WCHAR *pszFileType; hr = this->GetValue(this->hkeySource, NULL, (void**)&pszFileType, NULL); if (FAILED(hr)) { return hr; } DWORD size = 0; DWORD ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, NULL, &size); if (ret == ERROR_SUCCESS) { WCHAR *docName = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, size)); if (docName) { ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size); if (ret == ERROR_SUCCESS) { hr = this->ReturnString(flags, pszOut, pcchOut, docName, strlenW(docName) + 1); } else { hr = HRESULT_FROM_WIN32(ret); } HeapFree(GetProcessHeap(), 0, docName); } else { hr = E_OUTOFMEMORY; } } else { hr = HRESULT_FROM_WIN32(ret); } HeapFree(GetProcessHeap(), 0, pszFileType); return hr; } case ASSOCSTR_FRIENDLYAPPNAME: { PVOID verinfoW = NULL; DWORD size, retval = 0; UINT flen; WCHAR *bufW; static const WCHAR translationW[] = L"\\VarFileInfo\\Translation"; static const WCHAR fileDescFmtW[] = L"\\StringFileInfo\\%04x%04x\\FileDescription"; WCHAR fileDescW[41]; hr = this->GetExecutable(pszExtra, path, MAX_PATH, &len); if (FAILED(hr)) { return hr; } retval = GetFileVersionInfoSizeW(path, &size); if (!retval) { goto get_friendly_name_fail; } verinfoW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval); if (!verinfoW) { return E_OUTOFMEMORY; } if (!GetFileVersionInfoW(path, 0, retval, verinfoW)) { goto get_friendly_name_fail; } if (VerQueryValueW(verinfoW, translationW, (LPVOID *)&bufW, &flen)) { UINT i; DWORD *langCodeDesc = (DWORD *)bufW; for (i = 0; i < flen / sizeof(DWORD); i++) { sprintfW(fileDescW, fileDescFmtW, LOWORD(langCodeDesc[i]), HIWORD(langCodeDesc[i])); if (VerQueryValueW(verinfoW, fileDescW, (LPVOID *)&bufW, &flen)) { /* Does strlenW(bufW) == 0 mean we use the filename? */ len = strlenW(bufW) + 1; TRACE("found FileDescription: %s\n", debugstr_w(bufW)); hr = this->ReturnString(flags, pszOut, pcchOut, bufW, len); HeapFree(GetProcessHeap(), 0, verinfoW); return hr; } } } get_friendly_name_fail: PathRemoveExtensionW(path); PathStripPathW(path); TRACE("using filename: %s\n", debugstr_w(path)); hr = this->ReturnString(flags, pszOut, pcchOut, path, strlenW(path) + 1); HeapFree(GetProcessHeap(), 0, verinfoW); return hr; } case ASSOCSTR_CONTENTTYPE: { static const WCHAR Content_TypeW[] = L"Content Type"; DWORD size = 0; DWORD ret = RegGetValueW(this->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, NULL, &size); if (ret != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(ret); } WCHAR *contentType = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, size)); if (contentType != NULL) { ret = RegGetValueW(this->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size); if (ret == ERROR_SUCCESS) { hr = this->ReturnString(flags, pszOut, pcchOut, contentType, strlenW(contentType) + 1); } else { hr = HRESULT_FROM_WIN32(ret); } HeapFree(GetProcessHeap(), 0, contentType); } else { hr = E_OUTOFMEMORY; } return hr; } case ASSOCSTR_DEFAULTICON: { static const WCHAR DefaultIconW[] = L"DefaultIcon"; DWORD ret; DWORD size = 0; ret = RegGetValueW(this->hkeyProgID, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size); if (ret == ERROR_SUCCESS) { WCHAR *icon = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, size)); if (icon) { ret = RegGetValueW(this->hkeyProgID, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size); if (ret == ERROR_SUCCESS) { hr = this->ReturnString(flags, pszOut, pcchOut, icon, strlenW(icon) + 1); } else { hr = HRESULT_FROM_WIN32(ret); } HeapFree(GetProcessHeap(), 0, icon); } else { hr = HRESULT_FROM_WIN32(ret); } } else { hr = HRESULT_FROM_WIN32(ret); } return hr; } case ASSOCSTR_SHELLEXTENSION: { static const WCHAR shellexW[] = L"ShellEx\\"; WCHAR keypath[sizeof(shellexW) / sizeof(shellexW[0]) + 39], guid[39]; CLSID clsid; HKEY hkey; hr = CLSIDFromString(pszExtra, &clsid); if (FAILED(hr)) { return hr; } strcpyW(keypath, shellexW); strcatW(keypath, pszExtra); LONG ret = RegOpenKeyExW(this->hkeySource, keypath, 0, KEY_READ, &hkey); if (ret) { return HRESULT_FROM_WIN32(ret); } DWORD size = sizeof(guid); ret = RegGetValueW(hkey, NULL, NULL, RRF_RT_REG_SZ, NULL, guid, &size); RegCloseKey(hkey); if (ret) { return HRESULT_FROM_WIN32(ret); } return this->ReturnString(flags, pszOut, pcchOut, guid, size / sizeof(WCHAR)); } default: { FIXME("assocstr %d unimplemented!\n", str); return E_NOTIMPL; } } }
/************************************************************************** * CAdminToolsFolder::GetDisplayNameOf * */ HRESULT WINAPI CAdminToolsFolder::GetDisplayNameOf(LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet) { HRESULT hr = S_OK; LPWSTR pszPath, pOffset; TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", this, pidl, dwFlags, strRet); pdump (pidl); if (!strRet) return E_INVALIDARG; pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); if (!pszPath) return E_OUTOFMEMORY; ZeroMemory(pszPath, (MAX_PATH + 1) * sizeof(WCHAR)); if (!pidl->mkid.cb) { if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) wcscpy(pszPath, szTarget); else if (!HCR_GetClassNameW(CLSID_AdminFolderShortcut, pszPath, MAX_PATH)) hr = E_FAIL; } else if (_ILIsPidlSimple(pidl)) { if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && szTarget) { wcscpy(pszPath, szTarget); pOffset = PathAddBackslashW(pszPath); if (pOffset) { if (!_ILSimpleGetTextW(pidl, pOffset, MAX_PATH + 1 - (pOffset - pszPath))) hr = E_FAIL; } else hr = E_FAIL; } else { if (_ILSimpleGetTextW(pidl, pszPath, MAX_PATH + 1)) { if (SHELL_FS_HideExtension(pszPath)) PathRemoveExtensionW(pszPath); } else hr = E_FAIL; } } else if (_ILIsSpecialFolder(pidl)) { BOOL bSimplePidl = _ILIsPidlSimple(pidl); if (bSimplePidl) { if (!_ILSimpleGetTextW(pidl, pszPath, MAX_PATH)) hr = E_FAIL; } else if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { int len = 0; wcscpy(pszPath, szTarget); PathAddBackslashW(pszPath); len = wcslen(pszPath); if (!SUCCEEDED(SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags | SHGDN_INFOLDER, pszPath + len, MAX_PATH + 1 - len))) { CoTaskMemFree(pszPath); return E_OUTOFMEMORY; } } } if (SUCCEEDED(hr)) { strRet->uType = STRRET_WSTR; strRet->pOleStr = pszPath; TRACE ("-- (%p)->(%s,0x%08x)\n", this, debugstr_w(strRet->pOleStr), hr); } else CoTaskMemFree(pszPath); return hr; }