[ZIPFLDR] Move CConfirmReplace to a new file
authorMark Jansen <mark.jansen@reactos.org>
Wed, 27 Feb 2019 21:18:32 +0000 (22:18 +0100)
committerMark Jansen <mark.jansen@reactos.org>
Wed, 6 Mar 2019 22:09:35 +0000 (23:09 +0100)
dll/shellext/zipfldr/CConfirmReplace.cpp [new file with mode: 0644]
dll/shellext/zipfldr/CMakeLists.txt
dll/shellext/zipfldr/CZipExtract.cpp

diff --git a/dll/shellext/zipfldr/CConfirmReplace.cpp b/dll/shellext/zipfldr/CConfirmReplace.cpp
new file mode 100644 (file)
index 0000000..93edf99
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * PROJECT:     ReactOS Zip Shell Extension
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     Ask the user to replace a file
+ * COPYRIGHT:   Copyright 2017-2019 Mark Jansen (mark.jansen@reactos.org)
+ */
+
+#include "precomp.h"
+
+class CConfirmReplace : public CDialogImpl<CConfirmReplace>
+{
+private:
+    CStringA m_Filename;
+public:
+
+    CConfirmReplace(const char* filename)
+    {
+        m_Filename = filename;
+    }
+
+    LRESULT OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+    {
+        CenterWindow(GetParent());
+
+        HICON hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
+        SendDlgItemMessage(IDC_EXCLAMATION_ICON, STM_SETICON, (WPARAM)hIcon);
+
+        /* Our CString does not support FormatMessage yet */
+        CStringA message(MAKEINTRESOURCE(IDS_OVERWRITEFILE_TEXT));
+        CHeapPtr<CHAR, CLocalAllocator> formatted;
+
+        DWORD_PTR args[2] =
+        {
+            (DWORD_PTR)m_Filename.GetString(),
+            NULL
+        };
+
+        ::FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
+                         message, 0, 0, (LPSTR)&formatted, 0, (va_list*)args);
+
+        ::SetDlgItemTextA(m_hWnd, IDC_MESSAGE, formatted);
+        return 0;
+    }
+
+    LRESULT OnButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
+    {
+        EndDialog(wID);
+        return 0;
+    }
+
+public:
+    enum { IDD = IDD_CONFIRM_FILE_REPLACE };
+
+    BEGIN_MSG_MAP(CConfirmReplace)
+        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
+        COMMAND_ID_HANDLER(IDYES, OnButton)
+        COMMAND_ID_HANDLER(IDYESALL, OnButton)
+        COMMAND_ID_HANDLER(IDNO, OnButton)
+        COMMAND_ID_HANDLER(IDCANCEL, OnButton)
+    END_MSG_MAP()
+};
+
+
+eZipConfirmResponse _CZipAskReplace(HWND hDlg, PCSTR FullPath)
+{
+    PCSTR Filename = PathFindFileNameA(FullPath);
+    CConfirmReplace confirm(Filename);
+    INT_PTR Result = confirm.DoModal(hDlg);
+    switch (Result)
+    {
+    case IDYES: return eYes;
+    case IDYESALL: return eYesToAll;
+    default:
+    case IDNO: return eNo;
+    case IDCANCEL: return eCancel;
+    }
+}
index d491f1d..86a1b9c 100644 (file)
@@ -24,6 +24,7 @@ list(APPEND SOURCE
     zippidl.cpp
     zippidl.hpp
     IZip.hpp
+    CConfirmReplace.cpp
     CExplorerCommand.cpp
     CEnumZipContents.cpp
     CFolderViewCB.cpp
index baa0b30..a95f8ba 100644 (file)
@@ -66,82 +66,6 @@ public:
         return uf;
     }
 
-    class CConfirmReplace : public CDialogImpl<CConfirmReplace>
-    {
-    private:
-        CStringA m_Filename;
-    public:
-        enum DialogResult
-        {
-            Yes,
-            YesToAll,
-            No,
-            Cancel
-        };
-
-        static DialogResult ShowDlg(HWND hDlg, PCSTR FullPath)
-        {
-            PCSTR Filename = PathFindFileNameA(FullPath);
-            CConfirmReplace confirm(Filename);
-            INT_PTR Result = confirm.DoModal(hDlg);
-            switch (Result)
-            {
-            case IDYES: return Yes;
-            case IDYESALL: return YesToAll;
-            default:
-            case IDNO: return No;
-            case IDCANCEL: return Cancel;
-            }
-        }
-
-        CConfirmReplace(const char* filename)
-        {
-            m_Filename = filename;
-        }
-
-        LRESULT OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-        {
-            CenterWindow(GetParent());
-
-            HICON hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
-            SendDlgItemMessage(IDC_EXCLAMATION_ICON, STM_SETICON, (WPARAM)hIcon);
-
-            /* Our CString does not support FormatMessage yet */
-            CStringA message(MAKEINTRESOURCE(IDS_OVERWRITEFILE_TEXT));
-            CHeapPtr<CHAR, CLocalAllocator> formatted;
-
-            DWORD_PTR args[2] =
-            {
-                (DWORD_PTR)m_Filename.GetString(),
-                NULL
-            };
-
-            ::FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
-                             message, 0, 0, (LPSTR)&formatted, 0, (va_list*)args);
-
-            ::SetDlgItemTextA(m_hWnd, IDC_MESSAGE, formatted);
-            return 0;
-        }
-
-        LRESULT OnButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
-        {
-            EndDialog(wID);
-            return 0;
-        }
-
-    public:
-        enum { IDD = IDD_CONFIRM_FILE_REPLACE };
-
-        BEGIN_MSG_MAP(CConfirmReplace)
-            MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
-            COMMAND_ID_HANDLER(IDYES, OnButton)
-            COMMAND_ID_HANDLER(IDYESALL, OnButton)
-            COMMAND_ID_HANDLER(IDNO, OnButton)
-            COMMAND_ID_HANDLER(IDCANCEL, OnButton)
-        END_MSG_MAP()
-    };
-
-
     class CExtractSettingsPage : public CPropertyPageImpl<CExtractSettingsPage>
     {
     private:
@@ -405,17 +329,17 @@ public:
                     bool bOverwrite = bOverwriteAll;
                     if (!bOverwriteAll)
                     {
-                        CConfirmReplace::DialogResult Result = CConfirmReplace::ShowDlg(hDlg, FullPath);
+                        eZipConfirmResponse Result = _CZipAskReplace(hDlg, FullPath);
                         switch (Result)
                         {
-                        case CConfirmReplace::YesToAll:
+                        case eYesToAll:
                             bOverwriteAll = true;
-                        case CConfirmReplace::Yes:
+                        case eYes:
                             bOverwrite = true;
                             break;
-                        case CConfirmReplace::No:
+                        case eNo:
                             break;
-                        case CConfirmReplace::Cancel:
+                        case eCancel:
                             unzCloseCurrentFile(uf);
                             Close();
                             return false;