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
18using namespace NWindows;
19
20#ifdef LANG
21static 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
32static const unsigned kCurrentFileNameSizeLimit = 82;
33static const unsigned kCurrentFileNameSizeLimit2 = 30;
34
35void 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}
44
45void COverwriteDialog::SetFileInfoControl(int textID, int iconID,
46    const NOverwriteDialog::CFileInfo &fileInfo)
47{
48  UString sizeString;
49  if (fileInfo.SizeIsDefined)
50    sizeString = MyFormatNew(IDS_FILE_SIZE, NumberToString(fileInfo.Size));
51
52  const UString &fileName = fileInfo.Name;
53  int slashPos = fileName.ReverseFind(WCHAR_PATH_SEPARATOR);
54  UString s1 = fileName.Left(slashPos + 1);
55  UString s2 = fileName.Ptr(slashPos + 1);
56
57  ReduceString(s1);
58  ReduceString(s2);
59
60  UString s = s1;
61  s += L'\n';
62  s += s2;
63  s += L'\n';
64  s += sizeString;
65  s += L'\n';
66
67  if (fileInfo.TimeIsDefined)
68  {
69    FILETIME localFileTime;
70    if (!FileTimeToLocalFileTime(&fileInfo.Time, &localFileTime))
71      throw 4190402;
72    s += LangString(IDS_PROP_MTIME);
73    s += L": ";
74    wchar_t t[32];
75    ConvertFileTimeToString(localFileTime, t);
76    s += t;
77  }
78
79  NControl::CDialogChildControl control;
80  control.Init(*this, textID);
81  control.SetText(s);
82
83  SHFILEINFO shellFileInfo;
84  if (::SHGetFileInfo(
85      GetSystemString(fileInfo.Name), FILE_ATTRIBUTE_NORMAL, &shellFileInfo,
86      sizeof(shellFileInfo), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_LARGEICON))
87  {
88    NControl::CStatic staticContol;
89    staticContol.Attach(GetItem(iconID));
90    staticContol.SetIcon(shellFileInfo.hIcon);
91  }
92}
93
94bool COverwriteDialog::OnInit()
95{
96  #ifdef LANG
97  LangSetWindowText(*this, IDD_OVERWRITE);
98  LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs));
99  #endif
100  SetFileInfoControl(IDT_OVERWRITE_OLD_FILE_SIZE_TIME, IDI_OVERWRITE_OLD_FILE, OldFileInfo);
101  SetFileInfoControl(IDT_OVERWRITE_NEW_FILE_SIZE_TIME, IDI_OVERWRITE_NEW_FILE, NewFileInfo);
102  NormalizePosition();
103  return CModalDialog::OnInit();
104}
105
106bool COverwriteDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
107{
108  switch (buttonID)
109  {
110    case IDYES:
111    case IDNO:
112    case IDB_YES_TO_ALL:
113    case IDB_NO_TO_ALL:
114    case IDB_AUTO_RENAME:
115      End(buttonID);
116      return true;
117  }
118  return CModalDialog::OnButtonClicked(buttonID, buttonHWND);
119}
120