[ZIPFLDR] Move CConfirmReplace to a new file
[reactos.git] / dll / shellext / zipfldr / CConfirmReplace.cpp
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 */
7
8 #include "precomp.h"
9
10 class CConfirmReplace : public CDialogImpl<CConfirmReplace>
11 {
12 private:
13 CStringA m_Filename;
14 public:
15
16 CConfirmReplace(const char* filename)
17 {
18 m_Filename = filename;
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 /* Our CString does not support FormatMessage yet */
29 CStringA message(MAKEINTRESOURCE(IDS_OVERWRITEFILE_TEXT));
30 CHeapPtr<CHAR, CLocalAllocator> formatted;
31
32 DWORD_PTR args[2] =
33 {
34 (DWORD_PTR)m_Filename.GetString(),
35 NULL
36 };
37
38 ::FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
39 message, 0, 0, (LPSTR)&formatted, 0, (va_list*)args);
40
41 ::SetDlgItemTextA(m_hWnd, IDC_MESSAGE, formatted);
42 return 0;
43 }
44
45 LRESULT OnButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
46 {
47 EndDialog(wID);
48 return 0;
49 }
50
51 public:
52 enum { IDD = IDD_CONFIRM_FILE_REPLACE };
53
54 BEGIN_MSG_MAP(CConfirmReplace)
55 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
56 COMMAND_ID_HANDLER(IDYES, OnButton)
57 COMMAND_ID_HANDLER(IDYESALL, OnButton)
58 COMMAND_ID_HANDLER(IDNO, OnButton)
59 COMMAND_ID_HANDLER(IDCANCEL, OnButton)
60 END_MSG_MAP()
61 };
62
63
64 eZipConfirmResponse _CZipAskReplace(HWND hDlg, PCSTR FullPath)
65 {
66 PCSTR Filename = PathFindFileNameA(FullPath);
67 CConfirmReplace confirm(Filename);
68 INT_PTR Result = confirm.DoModal(hDlg);
69 switch (Result)
70 {
71 case IDYES: return eYes;
72 case IDYESALL: return eYesToAll;
73 default:
74 case IDNO: return eNo;
75 case IDCANCEL: return eCancel;
76 }
77 }