1 /*
2  * PROJECT:     ReactOS Zip Shell Extension
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Ask the user to replace a file
5  * COPYRIGHT:   Copyright 2017-2019 Mark Jansen (mark.jansen@reactos.org)
6  *              Copyright 2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 
9 #include "precomp.h"
10 
11 class CConfirmReplace : public CDialogImpl<CConfirmReplace>
12 {
13 private:
14     CStringW m_Filename;
15 public:
16     CConfirmReplace(PCWSTR filename)
17         : m_Filename(filename)
18     {
19     }
20 
21     LRESULT OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
22     {
23         CenterWindow(GetParent());
24 
25         HICON hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
26         SendDlgItemMessage(IDC_EXCLAMATION_ICON, STM_SETICON, (WPARAM)hIcon);
27 
28         CStringW message;
29         message.FormatMessage(IDS_OVERWRITEFILE_TEXT, m_Filename.GetString());
30         ::SetDlgItemTextW(m_hWnd, IDC_MESSAGE, message);
31 
32         return TRUE;
33     }
34 
35     LRESULT OnButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
36     {
37         EndDialog(wID);
38         return 0;
39     }
40 
41 public:
42     enum { IDD = IDD_CONFIRM_FILE_REPLACE };
43 
44     BEGIN_MSG_MAP(CConfirmReplace)
45         MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
46         COMMAND_ID_HANDLER(IDYES, OnButton)
47         COMMAND_ID_HANDLER(IDYESALL, OnButton)
48         COMMAND_ID_HANDLER(IDNO, OnButton)
49         COMMAND_ID_HANDLER(IDCANCEL, OnButton)
50     END_MSG_MAP()
51 };
52 
53 eZipConfirmResponse _CZipAskReplace(HWND hDlg, PCWSTR FullPath)
54 {
55     PCWSTR Filename = PathFindFileNameW(FullPath);
56     CConfirmReplace confirm(Filename);
57     INT_PTR Result = confirm.DoModal(hDlg);
58     switch (Result)
59     {
60     case IDYES: return eYes;
61     case IDYESALL: return eYesToAll;
62     default:
63     case IDNO: return eNo;
64     case IDCANCEL: return eCancel;
65     }
66 }
67