1 // OverwriteDialog.cpp
2
3 #include "StdAfx.h"
4
5 #include "../../../Common/StringConvert.h"
6
7 #include "../../../Windows/PropVariantConv.h"
8 #include "../../../Windows/ResourceString.h"
9
10 #include "../../../Windows/Control/Static.h"
11
12 #include "FormatUtils.h"
13 #include "LangUtils.h"
14 #include "OverwriteDialog.h"
15
16 #include "PropertyNameRes.h"
17
18 using namespace NWindows;
19
20 #ifdef LANG
21 static const UInt32 kLangIDs[] =
22 {
23 IDT_OVERWRITE_HEADER,
24 IDT_OVERWRITE_QUESTION_BEGIN,
25 IDT_OVERWRITE_QUESTION_END,
26 IDB_YES_TO_ALL,
27 IDB_NO_TO_ALL,
28 IDB_AUTO_RENAME
29 };
30 #endif
31
32 static const unsigned kCurrentFileNameSizeLimit = 82;
33 static const unsigned kCurrentFileNameSizeLimit2 = 30;
34
ReduceString(UString & s)35 void COverwriteDialog::ReduceString(UString &s)
36 {
37 unsigned size = _isBig ? kCurrentFileNameSizeLimit : kCurrentFileNameSizeLimit2;
38 if (s.Len() > size)
39 {
40 s.Delete(size / 2, s.Len() - size);
41 s.Insert(size / 2, L" ... ");
42 }
43 if (!s.IsEmpty() && s.Back() == ' ')
44 {
45 // s += (wchar_t)(0x2423);
46 s.InsertAtFront(L'\"');
47 s += L'\"';
48 }
49 }
50
SetFileInfoControl(int textID,int iconID,const NOverwriteDialog::CFileInfo & fileInfo)51 void COverwriteDialog::SetFileInfoControl(int textID, int iconID,
52 const NOverwriteDialog::CFileInfo &fileInfo)
53 {
54 UString sizeString;
55 if (fileInfo.SizeIsDefined)
56 sizeString = MyFormatNew(IDS_FILE_SIZE, NumberToString(fileInfo.Size));
57
58 const UString &fileName = fileInfo.Name;
59 int slashPos = fileName.ReverseFind_PathSepar();
60 UString s1 = fileName.Left(slashPos + 1);
61 UString s2 = fileName.Ptr(slashPos + 1);
62
63 ReduceString(s1);
64 ReduceString(s2);
65
66 UString s = s1;
67 s.Add_LF();
68 s += s2;
69 s.Add_LF();
70 s += sizeString;
71 s.Add_LF();
72
73 if (fileInfo.TimeIsDefined)
74 {
75 AddLangString(s, IDS_PROP_MTIME);
76 s += ": ";
77 char t[32];
78 ConvertUtcFileTimeToString(fileInfo.Time, t);
79 s += t;
80 }
81
82 NControl::CDialogChildControl control;
83 control.Init(*this, textID);
84 control.SetText(s);
85
86 SHFILEINFO shellFileInfo;
87 if (::SHGetFileInfo(
88 GetSystemString(fileInfo.Name), FILE_ATTRIBUTE_NORMAL, &shellFileInfo,
89 sizeof(shellFileInfo), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_LARGEICON))
90 {
91 NControl::CStatic staticContol;
92 staticContol.Attach(GetItem(iconID));
93 staticContol.SetIcon(shellFileInfo.hIcon);
94 }
95 }
96
OnInit()97 bool COverwriteDialog::OnInit()
98 {
99 #ifdef LANG
100 LangSetWindowText(*this, IDD_OVERWRITE);
101 LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs));
102 #endif
103 SetFileInfoControl(IDT_OVERWRITE_OLD_FILE_SIZE_TIME, IDI_OVERWRITE_OLD_FILE, OldFileInfo);
104 SetFileInfoControl(IDT_OVERWRITE_NEW_FILE_SIZE_TIME, IDI_OVERWRITE_NEW_FILE, NewFileInfo);
105 NormalizePosition();
106 return CModalDialog::OnInit();
107 }
108
OnButtonClicked(int buttonID,HWND buttonHWND)109 bool COverwriteDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
110 {
111 switch (buttonID)
112 {
113 case IDYES:
114 case IDNO:
115 case IDB_YES_TO_ALL:
116 case IDB_NO_TO_ALL:
117 case IDB_AUTO_RENAME:
118 End(buttonID);
119 return true;
120 }
121 return CModalDialog::OnButtonClicked(buttonID, buttonHWND);
122 }
123