OSDN Git Service

Fix a rare crash when decompressing a compressed file
[winmerge-jp/winmerge-jp.git] / Src / JumpList.cpp
index e26cabe..c99fae3 100644 (file)
@@ -4,10 +4,13 @@
  * @brief Implementation file for JumpList helper functions.
  *
  */
+#include "pch.h"
 #include "JumpList.h"
 #include <vector>
-#include <ObjBase.h>
-#include <ShlObj.h>
+#pragma warning (push)                 // prevent "warning C4091: 'typedef ': ignored on left of 'tagGPFIDL_FLAGS' when no variable is declared"
+#pragma warning (disable:4091) // VC bug when using XP enabled toolsets.
+#include <shlobj.h>
+#pragma warning (pop)
 #include <propvarutil.h>
 #include <propkey.h>
 #include "unicoder.h"
@@ -20,16 +23,16 @@ wchar_t g_exe_path[260];
 
 IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& params, const std::wstring& title, const std::wstring& desc, int icon_index)
 {
-       IShellLinkW *pShellLink = NULL;
-       if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+       IShellLinkW *pShellLink = nullptr;
+       if (FAILED(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
                                    IID_IShellLinkW, (void **)&pShellLink)))
-               return NULL;
+               return nullptr;
 
        std::wstring app_path2(app_path);
        if (app_path.empty())
        {
                if (g_exe_path[0] == '\0')
-                       GetModuleFileNameW(NULL, g_exe_path, sizeof(g_exe_path)/sizeof(g_exe_path[0]));
+                       GetModuleFileNameW(nullptr, g_exe_path, sizeof(g_exe_path)/sizeof(g_exe_path[0]));
                app_path2 = g_exe_path;
        }
        pShellLink->SetPath(app_path2.c_str());
@@ -37,7 +40,7 @@ IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& p
        pShellLink->SetArguments(params.c_str());
        pShellLink->SetDescription(desc.c_str());
 
-       IPropertyStore *pPS = NULL;
+       IPropertyStore *pPS = nullptr;
        if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
        {
                PROPVARIANT pv;
@@ -62,11 +65,11 @@ bool SetCurrentProcessExplicitAppUserModelID(const std::wstring& appid)
 {
        g_appid = appid;
        HMODULE hLibrary = GetModuleHandle(_T("shell32.dll"));
-       if (!hLibrary)
+       if (hLibrary == nullptr)
                return false;
        HRESULT (__stdcall *pfnSetCurrentProcessExplicitAppUserModelID)(PCWSTR AppID) = 
                (HRESULT (__stdcall *)(PCWSTR))GetProcAddress(hLibrary, "SetCurrentProcessExplicitAppUserModelID");
-       if (!pfnSetCurrentProcessExplicitAppUserModelID)
+       if (pfnSetCurrentProcessExplicitAppUserModelID == nullptr)
                return false;
        return pfnSetCurrentProcessExplicitAppUserModelID(appid.c_str()) == S_OK;
 }
@@ -75,12 +78,8 @@ bool AddToRecentDocs(const String& app_path, const String& params, const String&
 {
        SHARDAPPIDINFOLINK saiil;
        saiil.pszAppID = g_appid.c_str();
-#ifdef _UNICODE
        saiil.psl = CreateShellLink(app_path, params, title, desc, icon_index);
-#else
-       saiil.psl = (IShellLink *)CreateShellLink(ucr::toUTF16(app_path), ucr::toUTF16(params), ucr::toUTF16(title), ucr::toUTF16(desc), icon_index);
-#endif
-       if (!saiil.psl)
+       if (saiil.psl == nullptr)
                return false;
        SHAddToRecentDocs(SHARD_APPIDINFOLINK, &saiil);
        saiil.psl->Release();
@@ -90,8 +89,8 @@ bool AddToRecentDocs(const String& app_path, const String& params, const String&
 std::vector<Item> GetRecentDocs(size_t nMaxItems)
 {
        std::vector<Item> list;
-       IApplicationDocumentLists *pDocumentLists = NULL;
-       if (FAILED(CoCreateInstance(CLSID_ApplicationDocumentLists, NULL, CLSCTX_INPROC_SERVER,
+       IApplicationDocumentLists *pDocumentLists = nullptr;
+       if (FAILED(CoCreateInstance(CLSID_ApplicationDocumentLists, nullptr, CLSCTX_INPROC_SERVER,
                                    IID_IApplicationDocumentLists, (void **)&pDocumentLists)))
                return list;
        pDocumentLists->SetAppID(g_appid.c_str());
@@ -110,13 +109,14 @@ std::vector<Item> GetRecentDocs(size_t nMaxItems)
                                        wchar_t szPath[MAX_PATH];
                                        wchar_t szDescription[MAX_PATH];
                                        wchar_t szArguments[MAX_PATH * 6];
-                                       pShellLink->GetPath(szPath, sizeof(szPath) / sizeof(szPath[0]), NULL, SLGP_RAWPATH);
+                                       pShellLink->GetPath(szPath, sizeof(szPath) / sizeof(szPath[0]), nullptr, SLGP_RAWPATH);
                                        pShellLink->GetDescription(szDescription, sizeof(szDescription) / sizeof(szDescription[0]));
                                        pShellLink->GetArguments(szArguments, sizeof(szArguments) / sizeof(szArguments[0]));
-                                       IPropertyStore *pPS = NULL;
+                                       IPropertyStore *pPS = nullptr;
                                        if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
                                        {
                                                PROPVARIANT pv;
+                                               PropVariantInit(&pv);
                                                if (SUCCEEDED(pPS->GetValue(PKEY_Title, &pv)))
                                                {
                                                        list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));