1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#include "./uiUnitReady.h"
#include "./resource.h"
#include <strsafe.h>
#define TIMER_REFRESH_ID 1979
#define TIMER_REFRESH_INTERVAL 300
UnitReadyUI::UnitReadyUI(void)
{
hwnd = NULL;
drive = NULL;
primoSDK = NULL;
errPrimo = 0;
errReady = 0;
updateDlg = NULL;
}
UnitReadyUI::~UnitReadyUI(void)
{
if (updateDlg) delete(updateDlg);
updateDlg = NULL;
if (hwnd) DestroyWindow(hwnd);
}
DWORD UnitReadyUI::Check(obj_primo *primoSDK, DWORD *drive, BOOL showRetry, HWND ownerWnd)
{
if (!drive) return UNITREADYUI_DRIVENOTSET;
if (!primoSDK) return UNITREADYUI_PRIMOSDKNOTSET;
this->drive = drive;
this->primoSDK = primoSDK;
hwnd = NULL;
errPrimo = PRIMOSDK_OK;
errReady = UNITREADYUI_NOTREADY;
statSense = MAXDWORD;
statAsc = MAXDWORD;
statAscQ = MAXDWORD;
if (updateDlg) delete(updateDlg);
updateDlg = NULL;
Rescan();
if (UNITREADYUI_DRIVEREADY == errReady || UNITREADYUI_CANCELED == errReady || UNITREADYUI_PRIMOSDKERROR == errReady) return errReady;
LPCDLGTEMPLATE templ = NULL;
HRSRC hres = FindResourceExW(hResource, MAKEINTRESOURCEW(5), MAKEINTRESOURCEW(IDD_DLG_UNITNOTREADY), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
if (hres) templ = (LPCDLGTEMPLATE)LoadResource(hResource, hres);
HWND dlgWnd = CreateDialogIndirectParamW(dllInstance, templ, ownerWnd, (DLGPROC)WndProc, (LPARAM)this);
if (!dlgWnd) return UNITREADYUI_UNABLETOCREATEDIALOG;
wchar_t caption[64] = {0}, buffer[48] = {0};
LoadStringW(hResource, IDS_UNITNOTREADY, buffer, 48);
StringCchPrintfW(caption, 64, buffer, (char)*drive);
SetWindowTextW(GetDlgItem(hwnd, IDC_CAPTION), caption);
ShowWindow(GetDlgItem(hwnd, IDOK), showRetry);
MSG msg;
BOOL ret;
while( 0 != (ret = GetMessageW(&msg, NULL, 0, 0)))
{
if (ret == -1)
{
errReady = UNITREADYUI_MESSAGEPUMPERROR;
break;
}
if (IsDialogMessage(hwnd, &msg)) continue;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return errReady;
}
DWORD UnitReadyUI::Rescan(void)
{
if (!drive) return UNITREADYUI_DRIVENOTSET;
if (!primoSDK) return UNITREADYUI_PRIMOSDKNOTSET;
if (hwnd) KillTimer(hwnd, TIMER_REFRESH_ID);
errPrimo = primoSDK->UnitReady(drive);
switch(errPrimo)
{
case PRIMOSDK_NOTREADY:
if (hwnd)
{
DWORD cmd(0), sense(0), asc(0), ascq(0);
primoSDK->UnitStatus(drive, &cmd, &sense, &asc, &ascq);
if (sense != statSense || asc != statAsc || ascq != statAscQ)
{
statSense = sense;
statAsc = asc;
statAscQ = ascq;
if ((sense == 0x02 && asc == 0x04 && ascq == 0x01) ||
(sense == 0x06 && asc == 0x28 && ascq == 0x00))
{
if (!updateDlg)
{
// ShowWindow(hwnd, SW_HIDE);
UpdateWindow(GetParent(hwnd));
updateDlg = new UpdatingDataUI;
wchar_t buffer[64] = {0};
LoadStringW(hResource, IDS_WAITINGFORDRIVE, buffer, 64);
updateDlg->Show(0, buffer, TRUE, hwnd);
}
}
else
{
if(updateDlg)
{
updateDlg->Hide();
delete(updateDlg);
updateDlg = NULL;
}
wchar_t buffer[256] = {0}, pe[512] = {0};
StringCchPrintfW(buffer, 256, L"%s.", GetUnitStatusText(pe, 512, sense, asc, ascq));
SetWindowTextW(GetDlgItem(hwnd, IDC_LBL_REASON_VAL), buffer);
ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
BringWindowToTop(hwnd);
UpdateWindow(hwnd);
MessageBeep(MB_ICONEXCLAMATION);
}
}
}
errReady = UNITREADYUI_NOTREADY;
SetTimer(hwnd, TIMER_REFRESH_ID, TIMER_REFRESH_INTERVAL, NULL);
break;
case PRIMOSDK_OK:
if (updateDlg)
{
updateDlg->Hide();
delete(updateDlg);
updateDlg = NULL;
}
errReady = UNITREADYUI_DRIVEREADY;
if(hwnd) PostMessage(hwnd, WM_DESTROY, 0, 0);
break;
default:
if (updateDlg)
{
updateDlg->Hide();
delete(updateDlg);
updateDlg = NULL;
}
errReady = UNITREADYUI_PRIMOSDKERROR;
if(hwnd) PostMessage(hwnd, WM_DESTROY, 0, 0);
hwnd = NULL;
}
return errReady;
}
void UnitReadyUI::OnInitDialog(HWND hwndDlg)
{
hwnd = hwndDlg;
HANDLE hImage =LoadBitmapW(hResource, MAKEINTRESOURCEW(IDB_DRIVE1));
if(hImage==NULL){
hImage = LoadBitmapW(dllInstance, MAKEINTRESOURCEW(IDB_DRIVE1));
}
SendDlgItemMessage(hwnd, IDC_PIC, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hImage);
Rescan();
}
void UnitReadyUI::OnCancel(void)
{
KillTimer(hwnd, TIMER_REFRESH_ID);
wchar_t msg[256] = {0}, caption[64] = {0};
LoadStringW(hResource, IDS_MB_CANCELOPERATION, msg, 256);
LoadStringW(hResource, IDS_CONFIRMATION, caption, 64);
if (MessageBoxW(hwnd, msg, caption, MB_YESNO | MB_ICONQUESTION) == IDYES)
{
errReady = UNITREADYUI_CANCELED;
if(hwnd) DestroyWindow(hwnd);
hwnd = NULL;
}
else
{
SetTimer(hwnd, TIMER_REFRESH_ID, TIMER_REFRESH_INTERVAL, NULL);
}
}
void UnitReadyUI::OnDestroy(void)
{
ShowWindow(hwnd, SW_HIDE);
hwnd = NULL;
drive = NULL;
primoSDK = NULL;
}
LRESULT UnitReadyUI::WndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static UnitReadyUI *object = NULL;
switch(uMsg)
{
case WM_INITDIALOG:
object = (UnitReadyUI*)lParam;
object->OnInitDialog(hwndDlg);
break;
case WM_DESTROY:
object->OnDestroy();
PostQuitMessage(object->errReady);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
object->Rescan();
break;
case IDCANCEL:
object->OnCancel();
break;
}
break;
case WM_TIMER:
switch(wParam)
{
case TIMER_REFRESH_ID:
object->Rescan();
break;
}
break;
}
return 0;
}
|