[SHELL32]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Sat, 30 Apr 2016 14:05:10 +0000 (14:05 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Sat, 30 Apr 2016 14:05:10 +0000 (14:05 +0000)
- Add an overload of SHSetStrRet which loads strings by default from shell32.
- Remove some dead code fomr CDrivesFolder.

svn path=/trunk/; revision=71213

reactos/dll/win32/shell32/folders/CDesktopFolder.cpp
reactos/dll/win32/shell32/folders/CDrivesFolder.cpp
reactos/dll/win32/shell32/folders/CDrivesFolder.h
reactos/dll/win32/shell32/folders/CFSFolder.cpp
reactos/dll/win32/shell32/folders/CNetFolder.cpp
reactos/dll/win32/shell32/folders/CPrinterFolder.cpp
reactos/dll/win32/shell32/folders/CRecycleBin.cpp
reactos/dll/win32/shell32/shfldr.h

index 737c75f..cd336ce 100644 (file)
@@ -889,10 +889,7 @@ HRESULT WINAPI CDesktopFolder::GetDetailsOf(
     {
         psd->fmt = DesktopSFHeader[iColumn].fmt;
         psd->cxChar = DesktopSFHeader[iColumn].cxChar;
-        psd->str.uType = STRRET_CSTR;
-        LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
-                     psd->str.cStr, MAX_PATH);
-        return S_OK;
+        return SHSetStrRet(&psd->str, DesktopSFHeader[iColumn].colnameid);
     }
     else if (_ILIsSpecialFolder(pidl))
     {
index 45f175e..f1bf2fa 100644 (file)
@@ -164,7 +164,6 @@ BOOL CDrivesFolderEnum::CreateMyCompEnumList(DWORD dwFlags)
 CDrivesFolder::CDrivesFolder()
 {
     pidlRoot = NULL;
-    sName = NULL;
 }
 
 CDrivesFolder::~CDrivesFolder()
@@ -175,26 +174,10 @@ CDrivesFolder::~CDrivesFolder()
 
 HRESULT WINAPI CDrivesFolder::FinalConstruct()
 {
-    DWORD dwSize;
-    WCHAR szName[MAX_PATH];
-    WCHAR wszMyCompKey[256];
-    INT i;
-
     pidlRoot = _ILCreateMyComputer();    /* my qualified pidl */
     if (pidlRoot == NULL)
         return E_OUTOFMEMORY;
 
-    i = swprintf(wszMyCompKey, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\");
-    StringFromGUID2(CLSID_MyComputer, wszMyCompKey + i, sizeof(wszMyCompKey) / sizeof(wszMyCompKey[0]) - i);
-    dwSize = sizeof(szName);
-    if (RegGetValueW(HKEY_CURRENT_USER, wszMyCompKey,
-                     NULL, RRF_RT_REG_SZ, NULL, szName, &dwSize) == ERROR_SUCCESS)
-    {
-        sName = (LPWSTR)SHAlloc((wcslen(szName) + 1) * sizeof(WCHAR));
-        if (sName)
-            wcscpy(sName, szName);
-        TRACE("sName %s\n", debugstr_w(sName));
-    }
     return S_OK;
 }
 
@@ -696,10 +679,7 @@ HRESULT WINAPI CDrivesFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, S
     {
         psd->fmt = MyComputerSFHeader[iColumn].fmt;
         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
-        psd->str.uType = STRRET_CSTR;
-        LoadStringA(shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
-                    psd->str.cStr, MAX_PATH);
-        return S_OK;
+        return SHSetStrRet(&psd->str, MyComputerSFHeader[iColumn].colnameid);
     }
     else if (_ILIsSpecialFolder(pidl))
     {
index d03dc6c..769de23 100644 (file)
@@ -32,7 +32,6 @@ class CDrivesFolder :
     private:
         /* both paths are parsible from the desktop */
         LPITEMIDLIST pidlRoot;    /* absolute pidl */
-        LPWSTR sName;
     public:
         CDrivesFolder();
         ~CDrivesFolder();
index d32a42e..4a76d0a 100644 (file)
@@ -813,10 +813,7 @@ HRESULT WINAPI CFSFolder::GetDetailsOf(PCUITEMID_CHILD pidl,
         /* the header titles */
         psd->fmt = GenericSFHeader[iColumn].fmt;
         psd->cxChar = GenericSFHeader[iColumn].cxChar;
-        psd->str.uType = STRRET_CSTR;
-        LoadStringA(shell32_hInstance, GenericSFHeader[iColumn].colnameid,
-                    psd->str.cStr, MAX_PATH);
-        return S_OK;
+        return SHSetStrRet(&psd->str, GenericSFHeader[iColumn].colnameid);
     }
     else
     {
index 6b3ceae..a31d8bc 100644 (file)
@@ -464,43 +464,14 @@ HRESULT WINAPI CNetFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CH
 */
 HRESULT WINAPI CNetFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
 {
-    LPWSTR pszName;
-
-    TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", this, pidl, dwFlags, strRet);
-    pdump (pidl);
-
     if (!strRet)
         return E_INVALIDARG;
 
     if (!pidl->mkid.cb)
-    {
-        pszName = (LPWSTR)CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
-        if (!pszName)
-            return E_OUTOFMEMORY;
-
-        if (LoadStringW(shell32_hInstance, IDS_NETWORKPLACE, pszName, MAX_PATH))
-        {
-            pszName[MAX_PATH-1] = L'\0';
-            strRet->uType = STRRET_WSTR;
-            strRet->pOleStr = pszName;
-            return S_OK;
-        }
-        CoTaskMemFree(pszName);
-        return E_FAIL;
-    }
+        return SHSetStrRet(strRet, IDS_NETWORKPLACE);
 #ifdef HACKY_UNC_PATHS
     else
-    {
-        LPCWSTR pstr = (LPCWSTR)pidl->mkid.abID;
-        pszName = (LPWSTR)CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
-        if (!pszName)
-            return E_OUTOFMEMORY;
-
-        wcscpy(pszName, pstr);
-        strRet->pOleStr = pszName;
-        strRet->uType = STRRET_WSTR;
-        return S_OK;
-    }
+        return SHSetStrRet(strRet, (LPCWSTR)pidl->mkid.abID);
 #endif
     return E_NOTIMPL;
 }
@@ -568,7 +539,6 @@ HRESULT WINAPI CNetFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *
 HRESULT WINAPI CNetFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
 {
     WCHAR buffer[MAX_PATH] = {0};
-    HRESULT hr = E_FAIL;
 
     if (iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
         return E_FAIL;
@@ -576,13 +546,7 @@ HRESULT WINAPI CNetFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHEL
     psd->fmt = NetworkPlacesSFHeader[iColumn].fmt;
     psd->cxChar = NetworkPlacesSFHeader[iColumn].cxChar;
     if (pidl == NULL)
-    {
-        psd->str.uType = STRRET_WSTR;
-        if (LoadStringW(shell32_hInstance, NetworkPlacesSFHeader[iColumn].colnameid, buffer, _countof(buffer)))
-            hr = SHStrDupW(buffer, &psd->str.pOleStr);
-
-        return hr;
-    }
+        return SHSetStrRet(&psd->str, NetworkPlacesSFHeader[iColumn].colnameid);
 
     if (iColumn == COLUMN_NAME)
         return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
index 7176383..a4ddaaf 100644 (file)
@@ -492,7 +492,6 @@ HRESULT WINAPI CPrinterFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMI
  */
 HRESULT WINAPI CPrinterFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
 {
-    LPWSTR pszName;
     PIDLPrinterStruct * p;
 
     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", this, pidl, dwFlags, strRet);
@@ -505,21 +504,7 @@ HRESULT WINAPI CPrinterFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFl
     }
 
     if (!pidl->mkid.cb)
-    {
-        pszName = (LPWSTR)CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
-        if (!pszName)
-            return E_OUTOFMEMORY;
-
-        if (LoadStringW(shell32_hInstance, IDS_PRINTERS, pszName, MAX_PATH))
-        {
-            pszName[MAX_PATH-1] = L'\0';
-            strRet->uType = STRRET_WSTR;
-            strRet->pOleStr = pszName;
-            return S_OK;
-        }
-        CoTaskMemFree(pszName);
-        return E_FAIL;
-    }
+        return SHSetStrRet(strRet, IDS_PRINTERS);
 
     p = _ILGetPrinterStruct(pidl);
     if (!p)
@@ -527,14 +512,8 @@ HRESULT WINAPI CPrinterFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFl
         WARN("no printer struct\n");
         return E_INVALIDARG;
     }
-    strRet->pOleStr = (LPWSTR)SHAlloc(p->offsServer * sizeof(WCHAR));
-    if (!strRet->pOleStr)
-        return E_OUTOFMEMORY;
-
-    memcpy((LPVOID)strRet->pOleStr, (LPVOID)p->szName, p->offsServer * sizeof(WCHAR));
-    TRACE("ret %s\n", debugstr_w(strRet->pOleStr));
 
-    return S_OK;
+    return SHSetStrRet(strRet, p->szName);
 }
 
 /**************************************************************************
@@ -599,7 +578,6 @@ HRESULT WINAPI CPrinterFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMN
 HRESULT WINAPI CPrinterFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
 {
     WCHAR buffer[MAX_PATH] = {0};
-    HRESULT hr = E_FAIL;
 
     TRACE("(%p)->(%p %i %p): stub\n", this, pidl, iColumn, psd);
 
@@ -609,19 +587,10 @@ HRESULT WINAPI CPrinterFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn,
     psd->fmt = PrinterSFHeader[iColumn].fmt;
     psd->cxChar = PrinterSFHeader[iColumn].cxChar;
     if (pidl == NULL)
-    {
-        psd->str.uType = STRRET_WSTR;
-        if (LoadStringW(shell32_hInstance, PrinterSFHeader[iColumn].colnameid, buffer, MAX_PATH))
-            hr = SHStrDupW(buffer, &psd->str.pOleStr);
-
-        return hr;
-    }
+        return SHSetStrRet(&psd->str, PrinterSFHeader[iColumn].colnameid);
 
     if (iColumn == COLUMN_NAME)
-    {
-        psd->str.uType = STRRET_WSTR;
         return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
-    }
 
     psd->str.uType = STRRET_CSTR;
     psd->str.cStr[0] = '\0';
index 4f901ce..b11dae4 100644 (file)
@@ -740,11 +740,7 @@ HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPS
     pDetails->fmt = RecycleBinColumns[iColumn].fmt;
     pDetails->cxChar = RecycleBinColumns[iColumn].cxChars;
     if (pidl == NULL)
-    {
-        pDetails->str.uType = STRRET_WSTR;
-        LoadStringW(shell32_hInstance, RecycleBinColumns[iColumn].column_name_id, buffer, MAX_PATH);
-        return SHStrDupW(buffer, &pDetails->str.pOleStr);
-    }
+        return SHSetStrRet(&pDetails->str, RecycleBinColumns[iColumn].column_name_id);
 
     if (iColumn == COLUMN_NAME)
         return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);
@@ -780,15 +776,12 @@ HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPS
                 if (LoadStringW(shell32_hInstance, IDS_SHV_COLUMN1, &szTypeName[Length], (sizeof(szTypeName) / sizeof(WCHAR)) - Length))
                     szTypeName[(sizeof(szTypeName)/sizeof(WCHAR))-1] = L'\0';
             }
-            pDetails->str.uType = STRRET_WSTR;
-            return SHStrDupW(szTypeName, &pDetails->str.pOleStr);
-            break;
+            return SHSetStrRet(&pDetails->str, szTypeName);
         default:
             return E_FAIL;
     }
 
-    pDetails->str.uType = STRRET_WSTR;
-    return SHStrDupW(buffer, &pDetails->str.pOleStr);
+    return SHSetStrRet(&pDetails->str, buffer);
 }
 
 HRESULT WINAPI CRecycleBin::MapColumnToSCID(UINT iColumn, SHCOLUMNID *pscid)
index b496b08..5aaa88c 100644 (file)
@@ -104,4 +104,13 @@ static __inline int SHELL32_GUIDToStringW (REFGUID guid, LPWSTR str)
 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath, DWORD dwFlags);
 BOOL SHELL_FS_HideExtension(LPWSTR pwszPath);
 
+#ifdef __cplusplus
+
+HRESULT inline SHSetStrRet(LPSTRRET pStrRet, DWORD resId)
+{
+    return SHSetStrRet(pStrRet, shell32_hInstance, resId);
+}
+
+#endif
+
 #endif /* _SHFLDR_H_ */