[SHELL32] Code formatting only.
[reactos.git] / dll / win32 / shell32 / CShellLink.cpp
index 67da3ed..d6d12ef 100644 (file)
@@ -349,14 +349,10 @@ HRESULT STDMETHODCALLTYPE CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember
 
         if (SUCCEEDED(hr))
         {
-            if (pszFileName != m_sLinkPath)
-            {
-                if (m_sLinkPath)
-                    HeapFree(GetProcessHeap(), 0, m_sLinkPath);
-
-                m_sLinkPath = strdupW(pszFileName);
-            }
+            if (m_sLinkPath)
+                HeapFree(GetProcessHeap(), 0, m_sLinkPath);
 
+            m_sLinkPath = strdupW(pszFileName);
             m_bDirty = FALSE;
         }
         else
@@ -1204,7 +1200,6 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetArguments(LPCSTR pszArgs)
         if (!m_sArgs)
             return E_OUTOFMEMORY;
     }
-
     m_bDirty = TRUE;
 
     return S_OK;
@@ -1403,7 +1398,6 @@ HRESULT STDMETHODCALLTYPE CShellLink::Resolve(HWND hwnd, DWORD fFlags)
 
         /* Clear the cached path */
         HeapFree(GetProcessHeap(), 0, m_sPath);
-        m_sPath = NULL;
         m_sPath = shelllink_get_msi_component_path(component);
         if (!m_sPath)
             return E_FAIL;
@@ -1416,12 +1410,9 @@ HRESULT STDMETHODCALLTYPE CShellLink::Resolve(HWND hwnd, DWORD fFlags)
         bSuccess = SHGetPathFromIDListW(m_pPidl, buffer);
         if (bSuccess && *buffer)
         {
-            if (buffer != m_sPath)
-            {
-                m_sPath = strdupW(buffer);
-                if (!m_sPath)
-                    return E_OUTOFMEMORY;
-            }
+            m_sPath = strdupW(buffer);
+            if (!m_sPath)
+                return E_OUTOFMEMORY;
 
             m_bDirty = TRUE;
         }
@@ -1434,12 +1425,9 @@ HRESULT STDMETHODCALLTYPE CShellLink::Resolve(HWND hwnd, DWORD fFlags)
     // FIXME: Strange to do that here...
     if (!m_sIcoPath && m_sPath)
     {
-        if (m_sIcoPath != m_sPath)
-        {
-            m_sIcoPath = strdupW(m_sPath);
-            if (!m_sIcoPath)
-                return E_OUTOFMEMORY;
-        }
+        m_sIcoPath = strdupW(m_sPath);
+        if (!m_sIcoPath)
+            return E_OUTOFMEMORY;
 
         m_Header.nIconIndex = 0;
 
@@ -1563,18 +1551,14 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetDescription(LPCWSTR pszName)
     TRACE("(%p)->(desc=%s)\n", this, debugstr_w(pszName));
 
     HeapFree(GetProcessHeap(), 0, m_sDescription);
+    m_sDescription = NULL;
+
     if (pszName)
     {
-        if (m_sDescription != pszName)
-        {
-            m_sDescription = strdupW(pszName);
-            if (!m_sDescription)
-                return E_OUTOFMEMORY;
-        }
+        m_sDescription = strdupW(pszName);
+        if (!m_sDescription)
+            return E_OUTOFMEMORY;
     }
-    else
-        m_sDescription = NULL;
-
     m_bDirty = TRUE;
 
     return S_OK;
@@ -1598,18 +1582,14 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetWorkingDirectory(LPCWSTR pszDir)
     TRACE("(%p)->(dir=%s)\n", this, debugstr_w(pszDir));
 
     HeapFree(GetProcessHeap(), 0, m_sWorkDir);
+    m_sWorkDir = NULL;
+
     if (pszDir)
     {
-        if (m_sWorkDir != pszDir)
-        {
-            m_sWorkDir = strdupW(pszDir);
-            if (!m_sWorkDir)
-                return E_OUTOFMEMORY;
-        }
+        m_sWorkDir = strdupW(pszDir);
+        if (!m_sWorkDir)
+            return E_OUTOFMEMORY;
     }
-    else
-        m_sWorkDir = NULL;
-
     m_bDirty = TRUE;
 
     return S_OK;
@@ -1633,18 +1613,14 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetArguments(LPCWSTR pszArgs)
     TRACE("(%p)->(args=%s)\n", this, debugstr_w(pszArgs));
 
     HeapFree(GetProcessHeap(), 0, m_sArgs);
+    m_sArgs = NULL;
+
     if (pszArgs)
     {
-        if (m_sArgs != pszArgs)
-        {
-            m_sArgs = strdupW(pszArgs);
-            if (!m_sArgs)
-                return E_OUTOFMEMORY;
-        }
+        m_sArgs = strdupW(pszArgs);
+        if (!m_sArgs)
+            return E_OUTOFMEMORY;
     }
-    else
-        m_sArgs = NULL;
-
     m_bDirty = TRUE;
 
     return S_OK;
@@ -1669,18 +1645,14 @@ HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cc
         pInfo = (LPEXP_SZ_LINK)SHFindDataBlock(m_pDBList, EXP_SZ_ICON_SIG);
         if (pInfo && (pInfo->cbSize == sizeof(*pInfo)))
         {
+            SHExpandEnvironmentStringsW(pInfo->szwTarget, szPath, _countof(szPath));
+
             m_Header.dwFlags &= ~SLDF_HAS_ICONLOCATION;
             HeapFree(GetProcessHeap(), 0, m_sIcoPath);
-            m_sIcoPath = NULL;
-
-            SHExpandEnvironmentStringsW(pInfo->szwTarget, szPath, _countof(szPath));
 
-            if (m_sIcoPath != szPath)
-            {
-                m_sIcoPath = strdupW(szPath);
-                if (!m_sIcoPath)
-                    return E_OUTOFMEMORY;
-            }
+            m_sIcoPath = strdupW(szPath);
+            if (!m_sIcoPath)
+                return E_OUTOFMEMORY;
 
             m_Header.dwFlags |= SLDF_HAS_ICONLOCATION;
 
@@ -1878,6 +1850,7 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT i
 {
     HRESULT hr = E_FAIL;
     WCHAR szUnExpIconPath[MAX_PATH];
+    BOOL bSuccess;
 
     TRACE("(%p)->(path=%s iicon=%u)\n", this, debugstr_w(pszIconPath), iIcon);
 
@@ -1897,8 +1870,8 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT i
          */
         // FIXME: http://stackoverflow.com/questions/2976489/ishelllinkseticonlocation-translates-my-icon-path-into-program-files-which-i
         // if (PathFullyUnExpandEnvStringsW(pszIconPath, szUnExpIconPath, _countof(szUnExpIconPath)))
-        PathUnExpandEnvStringsW(pszIconPath, szUnExpIconPath, _countof(szUnExpIconPath));
-        if (wcscmp(pszIconPath, szUnExpIconPath) != 0)
+        bSuccess = PathUnExpandEnvStringsW(pszIconPath, szUnExpIconPath, _countof(szUnExpIconPath));
+        if (bSuccess && wcscmp(pszIconPath, szUnExpIconPath) != 0)
         {
             /* Unexpansion succeeded, so we need an icon environment block */
             EXP_SZ_LINK buffer;
@@ -1952,14 +1925,10 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT i
     {
         m_Header.dwFlags &= ~SLDF_HAS_ICONLOCATION;
         HeapFree(GetProcessHeap(), 0, m_sIcoPath);
-        m_sIcoPath = NULL;
 
-        if (m_sIcoPath != pszIconPath)
-        {
-            m_sIcoPath = strdupW(pszIconPath);
-            if (!m_sIcoPath)
-                return E_OUTOFMEMORY;
-        }
+        m_sIcoPath = strdupW(pszIconPath);
+        if (!m_sIcoPath)
+            return E_OUTOFMEMORY;
 
         m_Header.dwFlags |= SLDF_HAS_ICONLOCATION;
     }
@@ -1977,18 +1946,14 @@ HRESULT STDMETHODCALLTYPE CShellLink::SetRelativePath(LPCWSTR pszPathRel, DWORD
     TRACE("(%p)->(path=%s %x)\n", this, debugstr_w(pszPathRel), dwReserved);
 
     HeapFree(GetProcessHeap(), 0, m_sPathRel);
+    m_sPathRel = NULL;
+
     if (pszPathRel)
     {
-        if (m_sPathRel != pszPathRel)
-        {
-            m_sPathRel = strdupW(pszPathRel);
-            if (!m_sPathRel)
-                return E_OUTOFMEMORY;
-        }
+        m_sPathRel = strdupW(pszPathRel);
+        if (!m_sPathRel)
+            return E_OUTOFMEMORY;
     }
-    else
-        m_sPathRel = NULL;
-
     m_bDirty = TRUE;
 
     return ShellLink_UpdatePath(m_sPathRel, m_sPath, m_sWorkDir, &m_sPath);
@@ -2327,12 +2292,12 @@ HRESULT CShellLink::SetTargetFromPIDLOrPath(LPCITEMIDLIST pidl, LPCWSTR pszFile)
     /* Update the cached path (for link info) */
     ShellLink_GetVolumeInfo(pszFile, &volume);
 
-    if (m_sPath != pszFile)
-    {
-        m_sPath = strdupW(pszFile);
-        if (!m_sPath)
-            return E_OUTOFMEMORY;
-    }
+    if (m_sPath)
+        HeapFree(GetProcessHeap(), 0, m_sPath);
+
+    m_sPath = strdupW(pszFile);
+    if (!m_sPath)
+        return E_OUTOFMEMORY;
 
     m_bDirty = TRUE;
     return hr;