-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchoosediskdlg.c
247 lines (220 loc) · 6.53 KB
/
choosediskdlg.c
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//----------------------------------------------------------------------------
// EnsoniqFS plugin for TotalCommander
//
// OPTIONS DIALOG
//----------------------------------------------------------------------------
//
// (c) 2006 Thoralt Franz
//
// This source code was written using Dev-Cpp 4.9.9.2
// If you want to compile it, get Dev-Cpp. Normally the code should compile
// with other IDEs/compilers too (with small modifications), but I did not
// test it.
//
//----------------------------------------------------------------------------
// License
//----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
// Alternatively, download a copy of the license here:
// http://www.gnu.org/licenses/gpl.txt
//----------------------------------------------------------------------------
#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <commctrl.h>
#include "fsplugin.h"
#include "disk.h"
#include "choosediskdlg.h"
#include "log.h"
#include "error.h"
#include "resource.h"
#include "ini.h"
#include "EnsoniqFS.h"
//----------------------------------------------------------------------------
// global flags and variables
//----------------------------------------------------------------------------
extern HINSTANCE g_hInst;
extern DISK *g_pDiskListRoot;
DISK **m_pResult;
DISK *m_pCurrentDisk;
//----------------------------------------------------------------------------
// ChooseDiskDlg_OnCancel
//
// Gets called when the Cancel button was clicked, ends the dialog handling
//
// -> hWnd = window handle
// <- --
//----------------------------------------------------------------------------
void ChooseDiskDlg_OnCancel(HWND hWnd)
{
LOG("ChooseDiskDlg_OnCancel()\n");
*m_pResult = NULL;
EndDialog(hWnd, IDCANCEL);
}
//----------------------------------------------------------------------------
// ChooseDiskDlg_OnOK
//
// Gets called when the OK button was clicked
//
// -> hWnd = window handle
// <- --
//----------------------------------------------------------------------------
void ChooseDiskDlg_OnOK(HWND hWnd)
{
int i, iSelection;
// get combo box selection
iSelection = SendMessage(GetDlgItem(hWnd, IDC_COMBO_DISK),
(UINT)CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
LOG("ChooseDiskDlg_OnOK(): Selection = %d\n", iSelection);
if(CB_ERR==iSelection)
{
EndDialog(hWnd, IDCANCEL);
}
// iterate through list to find selected disk
DISK *pDisk = g_pDiskListRoot; i = 0;
while(pDisk)
{
if(pDisk->iIsEnsoniq)
{
if(i==iSelection)
{
*m_pResult = pDisk;
break;
}
i++;
}
pDisk = pDisk->pNext;
}
EndDialog(hWnd, IDOK);
}
//----------------------------------------------------------------------------
// WM_INITDIALOG
//
// Set up dialog, fill dropdown list
//
// -> hWnd = window handle
// <- --
//----------------------------------------------------------------------------
void ChooseDiskDlg_OnInitDialog(HWND hWnd)
{
LOG("ChooseDiskDlg_OnInitDialog()\n");
DISK *pDisk;
char cLine[1024];
int i = 0;
// clear combo box
SendMessage(GetDlgItem(hWnd, IDC_COMBO_DISK),
(UINT)CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
// iterate through all available disks and add them to the combo box
pDisk = g_pDiskListRoot;
while(pDisk)
{
if(pDisk->iIsEnsoniq)
{
strcpy(cLine, pDisk->cMsDosName);
strcat(cLine, " [");
strcat(cLine, pDisk->cDiskLabel);
strcat(cLine, "]");
// add a line to the combo box
SendMessage(GetDlgItem(hWnd, IDC_COMBO_DISK),
(UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)cLine);
if(pDisk == m_pCurrentDisk)
{
LOG("Selecting index %d from combo box\n", i);
SendMessage(GetDlgItem(hWnd, IDC_COMBO_DISK),
(UINT)CB_SETCURSEL, (WPARAM)i, (LPARAM)0);
}
i++;
}
pDisk = pDisk->pNext;
}
}
//----------------------------------------------------------------------------
// ChooseDiskDlgProc
//
// This is the message processing function for the dialog thread
//
// -> --
// <- TRUE, if the message was processed
// FALSE, if not
//----------------------------------------------------------------------------
INT_PTR CALLBACK ChooseDiskDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
int iRetVal = FALSE;
// process messages
switch(uMsg)
{
case WM_INITDIALOG:
ChooseDiskDlg_OnInitDialog(hwndDlg);
iRetVal = TRUE;
break;
case WM_CLOSE:
EndDialog(hwndDlg, IDCANCEL);
iRetVal = TRUE;
break;
case WM_COMMAND:
switch(wParam)
{
case IDC_BTN_DISK_OK:
ChooseDiskDlg_OnOK(hwndDlg);
iRetVal = TRUE;
break;
case IDC_BTN_DISK_CANCEL:
ChooseDiskDlg_OnCancel(hwndDlg);
iRetVal = TRUE;
break;
}
break;
default:
break;
}
return iRetVal;
lParam=lParam; // just to satisfy "unused parameter lParam" warning
}
//----------------------------------------------------------------------------
// CreateChooseDiskDialogModal
//
// Create a modal dialog
//
// -> --
// <- ERR_OK
// ERR_CREATE_DLG
//----------------------------------------------------------------------------
int CreateChooseDiskDialogModal(HWND hParent, DISK **pResult, DISK *pCurrent)
{
int iResult;
LOG("CreateChooseDiskDialogModal(): ");
m_pResult = pResult;
*m_pResult = NULL;
m_pCurrentDisk = pCurrent;
// create dialog from template
HRSRC hrsrc = FindResource(g_hInst, MAKEINTRESOURCE(IDD_DIALOG_DISK),
RT_DIALOG);
HGLOBAL hglobal = LoadResource(g_hInst, hrsrc);
iResult = DialogBoxIndirectParam(g_hInst, (LPCDLGTEMPLATE)hglobal, hParent,
ChooseDiskDlgProc, 0);
if(0==iResult)
{
LOG("DialogBoxIndirectParam() failed.\n");
return ERR_CREATE_DLG;
}
else
{
LOG("Dialog closed, return value=%d.\n", iResult);
}
return ERR_OK;
}