1 // MemDialog.cpp
2
3 #include "StdAfx.h"
4
5 #include <CommCtrl.h>
6
7 #include "MemDialog.h"
8
9 #include "../../../Common/StringToInt.h"
10 #include "../../../Windows/System.h"
11 #include "../../../Windows/ErrorMsg.h"
12
13 #include "../Explorer/MyMessages.h"
14 #include "../GUI/ExtractRes.h"
15
16 #include "resourceGui.h"
17
18 #ifdef Z7_LANG
19 #include "LangUtils.h"
20 #endif
21
22 #ifdef Z7_LANG
23 static const UInt32 kLangIDs[] =
24 {
25 IDX_MEM_SAVE_LIMIT,
26 IDX_MEM_REMEMBER,
27 IDG_MEM_ACTION,
28 IDR_MEM_ACTION_ALLOW,
29 IDR_MEM_ACTION_SKIP_ARC
30 // , IDR_MEM_SKIP_FILE
31 };
32 #endif
33
34 static const unsigned k_Action_Buttons[] =
35 {
36 IDR_MEM_ACTION_ALLOW,
37 IDR_MEM_ACTION_SKIP_ARC
38 // , IDR_MEM_SKIP_FILE
39 };
40
41
EnableSpin(bool enable)42 void CMemDialog::EnableSpin(bool enable)
43 {
44 EnableItem(IDC_MEM_SPIN, enable);
45 EnableItem(IDE_MEM_SPIN_EDIT, enable);
46 }
47
48
AddSize_GB(UString & s,UInt32 size_GB,UInt32 id)49 static void AddSize_GB(UString &s, UInt32 size_GB, UInt32 id)
50 {
51 s.Add_LF();
52 s += " ";
53 s.Add_UInt32(size_GB);
54 s += " GB : ";
55 AddLangString(s, id);
56 }
57
AddInfoMessage_To_String(UString & s,const UInt32 * ramSize_GB)58 void CMemDialog::AddInfoMessage_To_String(UString &s, const UInt32 *ramSize_GB)
59 {
60 AddLangString(s, IDS_MEM_REQUIRES_BIG_MEM);
61 AddSize_GB(s, Required_GB, IDS_MEM_REQUIRED_MEM_SIZE);
62 AddSize_GB(s, Limit_GB, IDS_MEM_CURRENT_MEM_LIMIT);
63 if (ramSize_GB)
64 AddSize_GB(s, *ramSize_GB, IDS_MEM_RAM_SIZE);
65 if (!FilePath.IsEmpty())
66 {
67 s.Add_LF();
68 s += "File: ";
69 s += FilePath;
70 }
71 }
72
73 /*
74 int CMemDialog::AddAction(UINT id)
75 {
76 const int index = (int)m_Action.AddString(LangString(id));
77 m_Action.SetItemData(index, (LPARAM)id);
78 return index;
79 }
80 */
81
OnInit()82 bool CMemDialog::OnInit()
83 {
84 #ifdef Z7_LANG
85 LangSetWindowText(*this, IDD_MEM);
86 LangSetDlgItems(*this, kLangIDs, Z7_ARRAY_SIZE(kLangIDs));
87 #endif
88
89 // m_Action.Attach(GetItem(IDC_MEM_ACTION));
90
91 size_t ramSize = (size_t)sizeof(size_t) << 29;
92 const bool ramSize_defined = NWindows::NSystem::GetRamSize(ramSize);
93 // ramSize *= 10; // for debug
94
95 UInt32 ramSize_GB = (UInt32)(((UInt64)ramSize + (1u << 29)) >> 30);
96 if (ramSize_GB == 0)
97 ramSize_GB = 1;
98
99 const bool is_Allowed = (!ramSize_defined || ramSize > ((UInt64)Required_GB << 30));
100 {
101 UString s;
102 if (!is_Allowed)
103 {
104 AddLangString(s, IDS_MEM_ERROR);
105 s.Add_LF();
106 }
107 AddInfoMessage_To_String(s, is_Allowed ? NULL : &ramSize_GB);
108 if (!ArcPath.IsEmpty())
109 // for (int i = 0; i < 10; i++)
110 {
111 s.Add_LF();
112 AddLangString(s, TestMode ?
113 IDS_PROGRESS_TESTING :
114 IDS_PROGRESS_EXTRACTING);
115 s += ": ";
116 s += ArcPath;
117 }
118 SetItemText(IDT_MEM_MESSAGE, s);
119
120 s = "GB";
121 if (ramSize_defined)
122 {
123 s += " / ";
124 s.Add_UInt32(ramSize_GB);
125 s += " GB (RAM)";
126 }
127 SetItemText(IDT_MEM_GB, s);
128 }
129 const UINT valMin = 1;
130 UINT valMax = 64; // 64GB for RAR7
131 if (ramSize_defined /* && ramSize_GB > valMax */)
132 {
133 const UINT k_max_val = 1u << 14;
134 if (ramSize_GB >= k_max_val)
135 valMax = k_max_val;
136 else if (ramSize_GB > 1)
137 valMax = (UINT)ramSize_GB - 1;
138 else
139 valMax = 1;
140 }
141
142 SendItemMessage(IDC_MEM_SPIN, UDM_SETRANGE, 0, MAKELPARAM(valMax, valMin)); // Sets the controls direction
143 // UDM_SETPOS doesn't set value larger than max value (valMax) of range:
144 SendItemMessage(IDC_MEM_SPIN, UDM_SETPOS, 0, Required_GB);
145 {
146 UString s;
147 s.Add_UInt32(Required_GB);
148 SetItemText(IDE_MEM_SPIN_EDIT, s);
149 }
150
151 EnableSpin(false);
152
153 /*
154 AddAction(IDB_ALLOW_OPERATION);
155 m_Action.SetCurSel(0);
156 AddAction(IDB_MEM_SKIP_ARC);
157 AddAction(IDB_MEM_SKIP_FILE);
158 */
159
160 const UINT buttonId = is_Allowed ?
161 IDR_MEM_ACTION_ALLOW :
162 IDR_MEM_ACTION_SKIP_ARC;
163
164 CheckRadioButton(
165 k_Action_Buttons[0],
166 k_Action_Buttons[Z7_ARRAY_SIZE(k_Action_Buttons) - 1],
167 buttonId);
168 /*
169 if (!ShowSkipFile)
170 HideItem(IDR_MEM_SKIP_FILE);
171 */
172 if (!ShowRemember)
173 HideItem(IDX_MEM_REMEMBER);
174 return CModalDialog::OnInit();
175 }
176
177
OnButtonClicked(unsigned buttonID,HWND buttonHWND)178 bool CMemDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
179 {
180 if (buttonID == IDX_MEM_SAVE_LIMIT)
181 {
182 EnableSpin(IsButtonCheckedBool(IDX_MEM_SAVE_LIMIT));
183 return true;
184 }
185 return CDialog::OnButtonClicked(buttonID, buttonHWND);
186 }
187
188
OnContinue()189 void CMemDialog::OnContinue()
190 {
191 Remember = IsButtonCheckedBool(IDX_MEM_REMEMBER);
192 NeedSave = IsButtonCheckedBool(IDX_MEM_SAVE_LIMIT);
193 SkipArc = IsButtonCheckedBool(IDR_MEM_ACTION_SKIP_ARC);
194 if (NeedSave)
195 {
196 #if 0
197 // UDM_GETPOS doesn't support value outside of range that was set:
198 LRESULT lresult = SendItemMessage(IDC_MEM_SPIN, UDM_GETPOS, 0, 0);
199 const UInt32 val = LOWORD(lresult);
200 if (HIWORD(lresult) != 0) // the value outside of allowed range
201 #else
202 UString s;
203 GetItemText(IDE_MEM_SPIN_EDIT, s);
204 const wchar_t *end;
205 const UInt32 val = ConvertStringToUInt32(s.Ptr(), &end);
206 if (s.IsEmpty() || *end != 0 || val > (1u << 30))
207 #endif
208 {
209 ShowErrorMessage(*this,
210 NWindows::NError::MyFormatMessage(E_INVALIDARG)
211 // L"Incorrect value"
212 );
213 return;
214 }
215 Limit_GB = val;
216 }
217 CModalDialog::OnContinue();
218 }
219