• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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((unsigned)(slashPos + 1));
61   UString s2 = fileName.Ptr((unsigned)(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 
107   if (!ShowExtraButtons)
108   {
109     HideItem(IDB_YES_TO_ALL);
110     HideItem(IDB_NO_TO_ALL);
111     HideItem(IDB_AUTO_RENAME);
112   }
113 
114   if (DefaultButton_is_NO)
115   {
116     PostMsg(DM_SETDEFID, IDNO);
117     HWND h = GetItem(IDNO);
118     PostMsg(WM_NEXTDLGCTL, (WPARAM)h, TRUE);
119     // ::SetFocus(h);
120   }
121 
122   return CModalDialog::OnInit();
123 }
124 
OnButtonClicked(int buttonID,HWND buttonHWND)125 bool COverwriteDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
126 {
127   switch (buttonID)
128   {
129     case IDYES:
130     case IDNO:
131     case IDB_YES_TO_ALL:
132     case IDB_NO_TO_ALL:
133     case IDB_AUTO_RENAME:
134       End(buttonID);
135       return true;
136   }
137   return CModalDialog::OnButtonClicked(buttonID, buttonHWND);
138 }
139