Updated with progress. Still far to go....
[reactos.git] / rosapps / winfile / dialogs.c
1 /*
2 * ReactOS winfile
3 *
4 * dialogs.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include <shellapi.h>
38 //#include <winspool.h>
39 #include <windowsx.h>
40 #include <shellapi.h>
41 #include <ctype.h>
42 #include <assert.h>
43 #define ASSERT assert
44
45 #include "main.h"
46 #include "about.h"
47 #include "dialogs.h"
48 #include "settings.h"
49 #include "utils.h"
50 #include "debug.h"
51
52
53 BOOL CALLBACK ExecuteDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
54 {
55 static struct ExecuteDialog* dlg;
56
57 switch(message) {
58 case WM_INITDIALOG:
59 dlg = (struct ExecuteDialog*) lParam;
60 return 1;
61
62 case WM_COMMAND: {
63 int id = (int)wParam;
64
65 if (id == IDOK) {
66 GetWindowText(GetDlgItem(hDlg, 201), dlg->cmd, MAX_PATH);
67 dlg->cmdshow = Button_GetState(GetDlgItem(hDlg,214))&BST_CHECKED?
68 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
69 EndDialog(hDlg, id);
70 } else if (id == IDCANCEL)
71 EndDialog(hDlg, id);
72
73 return 1;}
74 }
75
76 return 0;
77 }
78
79
80 BOOL CALLBACK OptionsConfirmationWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
81 {
82 static struct ExecuteDialog* dlg;
83 int id;
84
85 switch (message) {
86 case WM_INITDIALOG:
87 dlg = (struct ExecuteDialog*) lParam;
88 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_FILE_DELETE), Confirmation & CONFIRM_FILE_DELETE ? BST_CHECKED : BST_UNCHECKED);
89 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_DIR_DELETE), Confirmation & CONFIRM_DIR_DELETE ? BST_CHECKED : BST_UNCHECKED);
90 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_FILE_REPLACE), Confirmation & CONFIRM_FILE_REPLACE ? BST_CHECKED : BST_UNCHECKED);
91 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_MOUSE_ACTIONS), Confirmation & CONFIRM_MOUSE_ACTIONS ? BST_CHECKED : BST_UNCHECKED);
92 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_DISK_COMMANDS), Confirmation & CONFIRM_DISK_COMMANDS ? BST_CHECKED : BST_UNCHECKED);
93 Button_SetCheck(GetDlgItem(hDlg,IDC_CONFIRMATION_MODIFY_SYSTEM), Confirmation & CONFIRM_MODIFY_SYSTEM ? BST_CHECKED : BST_UNCHECKED);
94 return 1;
95 case WM_COMMAND:
96 id = (int)wParam;
97 if (id == IDOK) {
98 GetWindowText(GetDlgItem(hDlg, 201), dlg->cmd, MAX_PATH);
99 dlg->cmdshow = Button_GetState(GetDlgItem(hDlg,214))&BST_CHECKED?SW_SHOWMINIMIZED: SW_SHOWNORMAL;
100
101 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_FILE_DELETE)) & BST_CHECKED)
102 Confirmation |= CONFIRM_FILE_DELETE;
103 else Confirmation &= ~CONFIRM_FILE_DELETE;
104 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_DIR_DELETE)) & BST_CHECKED)
105 Confirmation |= CONFIRM_DIR_DELETE;
106 else Confirmation &= ~CONFIRM_DIR_DELETE;
107 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_FILE_REPLACE)) & BST_CHECKED)
108 Confirmation |= CONFIRM_FILE_REPLACE;
109 else Confirmation &= ~CONFIRM_FILE_REPLACE;
110 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_MOUSE_ACTIONS)) & BST_CHECKED)
111 Confirmation |= CONFIRM_MOUSE_ACTIONS;
112 else Confirmation &= ~CONFIRM_MOUSE_ACTIONS;
113 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_DISK_COMMANDS)) & BST_CHECKED)
114 Confirmation |= CONFIRM_DISK_COMMANDS;
115 else Confirmation &= ~CONFIRM_DISK_COMMANDS;
116 if (Button_GetState(GetDlgItem(hDlg,IDC_CONFIRMATION_MODIFY_SYSTEM)) & BST_CHECKED)
117 Confirmation |= CONFIRM_MODIFY_SYSTEM;
118 else Confirmation &= ~CONFIRM_MODIFY_SYSTEM;
119
120 EndDialog(hDlg, id);
121 } else if (id == IDCANCEL)
122 EndDialog(hDlg, id);
123 return 1;
124 }
125 return 0;
126 }
127
128
129 BOOL CALLBACK ViewFileTypeWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
130 {
131 static struct ExecuteDialog* dlg;
132 int id;
133
134 switch (message) {
135 case WM_INITDIALOG:
136 dlg = (struct ExecuteDialog*)lParam;
137 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_DIRECTORIES), ViewType & VIEW_DIRECTORIES ? BST_CHECKED : BST_UNCHECKED);
138 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_PROGRAMS), ViewType & VIEW_PROGRAMS ? BST_CHECKED : BST_UNCHECKED);
139 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_DOCUMENTS), ViewType & VIEW_DOCUMENTS ? BST_CHECKED : BST_UNCHECKED);
140 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_OTHERS), ViewType & VIEW_OTHER ? BST_CHECKED : BST_UNCHECKED);
141 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_SYSFILES), ViewType & VIEW_SYSTEM ? BST_CHECKED : BST_UNCHECKED);
142 return 1;
143 case WM_COMMAND:
144 id = (int)wParam;
145 if (id == IDOK) {
146 GetWindowText(GetDlgItem(hDlg, 201), dlg->cmd, MAX_PATH);
147 dlg->cmdshow = Button_GetState(GetDlgItem(hDlg,214))&BST_CHECKED?SW_SHOWMINIMIZED: SW_SHOWNORMAL;
148
149 if (Button_GetState(GetDlgItem(hDlg,IDC_VIEW_TYPE_DIRECTORIES)) & BST_CHECKED)
150 ViewType |= VIEW_DIRECTORIES;
151 else ViewType &= ~VIEW_DIRECTORIES;
152 if (Button_GetState(GetDlgItem(hDlg,IDC_VIEW_TYPE_PROGRAMS)) & BST_CHECKED)
153 ViewType |= VIEW_PROGRAMS;
154 else ViewType &= ~VIEW_PROGRAMS;
155 if (Button_GetState(GetDlgItem(hDlg,IDC_VIEW_TYPE_DOCUMENTS)) & BST_CHECKED)
156 ViewType |= VIEW_DOCUMENTS;
157 else ViewType &= ~VIEW_DOCUMENTS;
158 if (Button_GetState(GetDlgItem(hDlg,IDC_VIEW_TYPE_OTHERS)) & BST_CHECKED)
159 ViewType |= VIEW_OTHER;
160 else ViewType &= ~VIEW_OTHER;
161 if (Button_GetState(GetDlgItem(hDlg,IDC_VIEW_TYPE_SYSFILES)) & BST_CHECKED)
162 ViewType |= VIEW_SYSTEM;
163 else ViewType &= ~VIEW_SYSTEM;
164 EndDialog(hDlg, id);
165 } else if (id == IDCANCEL)
166 EndDialog(hDlg, id);
167 return 1;
168 }
169 return 0;
170 }
171
172 ////////////////////////////////////////////////////////////////////////////////
173 /*
174 TotalFileSize
175 [in] Specifies the total size of the file, in bytes.
176 TotalBytesTransferred
177 [in] Specifies the total number of bytes transferred from the source file to the destination file since the copy operation began.
178 StreamSize
179 [in] Specifies the total size of the current file stream, in bytes.
180 StreamBytesTransferred
181 [in] Specifies the total number of bytes in the current stream that have been transferred from the source file to the destination file since the copy operation began.
182 dwStreamNumber
183 [in] Handle to the current stream. The stream number is 1 the first time CopyProgressRoutine is called.
184 dwCallbackReason
185 [in] Specifies the reason that CopyProgressRoutine was called. This parameter can be one of the following values. Value Meaning
186 CALLBACK_CHUNK_FINISHED Another part of the data file was copied.
187 CALLBACK_STREAM_SWITCH Another stream was created and is about to be copied. This is the callback reason given when the callback routine is first invoked.
188
189
190 hSourceFile
191 [in] Handle to the source file.
192 hDestinationFile
193 [in] Handle to the destination file
194 lpData
195 [in] The argument passed to CopyProgressRoutine by the CopyFileEx or MoveFileWithProgress function.
196 Return Values
197 The CopyProgressRoutine function should return one of the following values.
198
199 Value Meaning
200 PROGRESS_CONTINUE Continue the copy operation.
201 PROGRESS_CANCEL Cancel the copy operation and delete the destination file.
202 PROGRESS_STOP Stop the copy operation. It can be restarted at a later time.
203 PROGRESS_QUIET Continue the copy operation, but stop invoking CopyProgressRoutine to report progress.
204 */
205 DWORD CALLBACK CopyProgressRoutine(
206 LARGE_INTEGER TotalFileSize, // file size
207 LARGE_INTEGER TotalBytesTransferred, // bytes transferred
208 LARGE_INTEGER StreamSize, // bytes in stream
209 LARGE_INTEGER StreamBytesTransferred, // bytes transferred for stream
210 DWORD dwStreamNumber, // current stream
211 DWORD dwCallbackReason, // callback reason
212 HANDLE hSourceFile, // handle to source file
213 HANDLE hDestinationFile, // handle to destination file
214 LPVOID lpData // from CopyFileEx
215 )
216 {
217 return 0L;
218 }
219
220 BOOL CALLBACK MoveFileWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
221 {
222 static struct ExecuteDialog* dlg;
223 int id;
224 TCHAR buffer_from[1000];
225 TCHAR buffer_to[1000];
226
227 switch (message) {
228 case WM_INITDIALOG:
229 dlg = (struct ExecuteDialog*)lParam;
230
231 _tcscpy(buffer_from, _T("C:\\TEMP\\API_SPY\\TEMP\\foobar.txt"));
232 SetDlgItemText(hDlg, IDC_FILE_MOVE_FROM, buffer_from);
233 _tcscpy(buffer_to, _T("C:\\TEMP\\API_SPY\\TEMP\\foobar2.txt"));
234 SetDlgItemText(hDlg, IDC_FILE_MOVE_TO, buffer_to);
235 /*
236 Button_SetCheck(GetDlgItem(hDlg,IDC_VIEW_TYPE_DIRECTORIES), ViewType & VIEW_DIRECTORIES ? BST_CHECKED : BST_UNCHECKED);
237 */
238 return 1;
239 case WM_COMMAND:
240 id = (int)wParam;
241 if (id == IDOK) {
242 LPVOID lpData = NULL; // parameter for callback
243 DWORD dwFlags = MOVEFILE_COPY_ALLOWED; // move options
244
245 GetDlgItemText(hDlg, IDC_FILE_MOVE_FROM, buffer_from, sizeof(buffer_from));
246 GetDlgItemText(hDlg, IDC_FILE_MOVE_TO, buffer_to, sizeof(buffer_to));
247 /*
248 BOOL MoveFileWithProgress(
249 LPCTSTR lpExistingFileName, // file name
250 LPCTSTR lpNewFileName, // new file name
251 LPPROGRESS_ROUTINE lpProgressRoutine, // callback function
252 LPVOID lpData, // parameter for callback
253 DWORD dwFlags // move options
254 );
255 DWORD FormatMessage(
256 DWORD dwFlags, // source and processing options
257 LPCVOID lpSource, // message source
258 DWORD dwMessageId, // message identifier
259 DWORD dwLanguageId, // language identifier
260 LPTSTR lpBuffer, // message buffer
261 DWORD nSize, // maximum size of message buffer
262 va_list *Arguments // array of message inserts
263 );
264 */
265 // if (!MoveFileWithProgress(buffer_from, buffer_to, &CopyProgressRoutine, lpData, dwFlags)) {
266 if (!MoveFileEx(buffer_from, buffer_to, dwFlags)) {
267 DWORD err = GetLastError();
268 HLOCAL hMem;
269 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (LPTSTR)&hMem, 10, NULL)) {
270 MessageBox(hDlg, hMem, szTitle, MB_OK);
271 LocalFree(hMem);
272 } else {
273 MessageBox(hDlg, _T("Unknown Error"), szTitle, MB_OK);
274 }
275 }
276
277 EndDialog(hDlg, id);
278 } else if (id == IDCANCEL)
279 EndDialog(hDlg, id);
280 return 1;
281 }
282 return 0;
283 }
284
285
286 /*
287 extern TCHAR ViewTypeMaskStr[MAX_TYPE_MASK_LEN];
288 */
289