ReactOS 0.4.15-dev-5669-g09dde2c
fileextractdialog.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/fileextractdialog.c
5 * PURPOSE: File Extract Dialog
6 * COPYRIGHT: Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
7 */
8
9#include "precomp.h"
10
11#include <wingdi.h>
12#include <commdlg.h> // It needs stuff defined in wingdi.h ...
13#undef LF_FACESIZE // but wingdi.h defines LF_FACESIZE, and if LF_FACESIZE is defined ...
14#include <shlobj.h> // shlobj.h wants to define NT_CONSOLE_PROPS which needs COORD structure
15 // to be declared, this means, including wincon.h in a GUI app!!
16 // WTF!! I don't want that!!
17
18// #include <setupapi.h>
19#include "fileextractdialog.h"
20#include "comctl32supp.h"
21#include "utils.h"
22
23// #include "callbacks.h"
24
25// FIXME: This should be present in PSDK commdlg.h
26//
27// FlagsEx Values
28#if (_WIN32_WINNT >= 0x0500)
29#define OFN_EX_NOPLACESBAR 0x00000001
30#endif // (_WIN32_WINNT >= 0x0500)
31
32
33VOID
35 LPCWSTR lpszString)
36{
37 /* Try to find an already existing occurrence of the string in the list */
38 LRESULT hPos = ComboBox_FindStringExact(hWnd, -1, lpszString);
39
40 if (hPos == CB_ERR)
41 {
42 /* The string doesn't exist, so add it to the list and select it */
43 ComboBox_InsertString(hWnd, 0, lpszString);
45 }
46 else
47 {
48 /* The string exists, so select it */
50 }
51
52 return;
53}
54
60{
62
63 switch (message)
64 {
65 case WM_INITDIALOG:
66 return TRUE;
67
68 case WM_COMMAND:
69 {
70 switch (LOWORD(wParam))
71 {
72 case IDOK:
73 {
74 LPWSTR szCabPathFileName, szFileName, szDestDir;
75 size_t cabPathNum, fileNameNum, destDirNum;
76
77 cabPathNum = GetWindowTextLengthW(GetDlgItem(hDlg, IDC_DRP_CAB_FILE)) + 1;
78 szCabPathFileName = (LPWSTR)MemAlloc(0, cabPathNum * sizeof(WCHAR));
79 GetDlgItemText(hDlg, IDC_DRP_CAB_FILE, szCabPathFileName, (int)cabPathNum);
80
82 szFileName = (LPWSTR)MemAlloc(0, fileNameNum * sizeof(WCHAR));
83 GetDlgItemText(hDlg, IDC_TXT_FILE_TO_RESTORE, szFileName, (int)fileNameNum);
84
85 destDirNum = GetWindowTextLengthW(GetDlgItem(hDlg, IDC_DRP_DEST_DIR)) + 1;
86 szDestDir = (LPWSTR)MemAlloc(0, destDirNum * sizeof(WCHAR));
87 GetDlgItemText(hDlg, IDC_DRP_DEST_DIR, szDestDir, (int)destDirNum);
88
89#if 0
90 if (!ExtractFromCabinet(szCabPathFileName, szFileName, szDestDir))
91 {
92 MessageBoxW(NULL, L"An error has occurred!!", L"Error", MB_ICONERROR | MB_OK);
93 }
94 else
95 {
96 MessageBoxW(NULL, L"All the files were uncompressed successfully.", L"Info", MB_ICONINFORMATION | MB_OK);
97
98 // TODO: Save the extraction paths into the registry.
99
100 /* Quit */
101 EndDialog(hDlg, LOWORD(wParam));
102 }
103#else
104 MessageBoxW(NULL, L"File extraction is unimplemented!", L"Info", MB_ICONINFORMATION | MB_OK);
105#endif
106
107 MemFree(szDestDir);
108 MemFree(szFileName);
109 MemFree(szCabPathFileName);
110
111 return TRUE;
112 }
113
114 case IDCANCEL:
115 EndDialog(hDlg, LOWORD(wParam));
116 return TRUE;
117
119 {
120 unsigned int nMaxFilesNum = 255;
121 size_t newSize = (nMaxFilesNum * (MAX_PATH + 1)) + 1;
122 LPWSTR szPath = (LPWSTR)MemAlloc(HEAP_ZERO_MEMORY, newSize * sizeof(WCHAR));
124
125 SecureZeroMemory(&ofn, sizeof(ofn));
126 ofn.lStructSize = sizeof(ofn);
127 ofn.hwndOwner = hDlg;
128 ofn.lpstrTitle = L"Files to be restored"; // L"Fichiers à restaurer"; // FIXME: Localize!
130 // ofn.FlagsEx = OFN_EX_NOPLACESBAR;
131 ofn.lpstrFilter = L"All files (*.*)\0*.*\0";
132 ofn.nFilterIndex = 0;
134 ofn.nMaxFile = (DWORD)newSize; // TODO: size_t to DWORD conversion...
135
136 if (GetSaveFileName(&ofn))
137 {
138 if ( (ofn.Flags & OFN_EXPLORER) &&
139 (ofn.Flags & OFN_ALLOWMULTISELECT) ) // Must be always true...
140 {
141 LPWSTR lpszFiles = szPath + ofn.nFileOffset;
142 LPWSTR lpszFilePatterns = NULL;
143
144 LPWSTR lpszTmp = lpszFiles;
145 unsigned int n = 0;
146 size_t numOfChars = 0;
147
148 /* Truncate the path, if needed */
149 szPath[ofn.nFileOffset - 1] = L'\0';
150
151 while (*lpszTmp)
152 {
153 ++n;
154 numOfChars += wcslen(lpszTmp)+1 + 3; // 3 = 2 quotation marks + 1 space.
155 lpszTmp += wcslen(lpszTmp)+1;
156 }
157
158 lpszFilePatterns = (LPWSTR)MemAlloc(HEAP_ZERO_MEMORY, numOfChars*sizeof(WCHAR));
159
160 if (n >= 2)
161 {
162 while (*lpszFiles)
163 {
164 wcscat(lpszFilePatterns, L"\"");
165 wcscat(lpszFilePatterns, lpszFiles);
166 wcscat(lpszFilePatterns, L"\"");
167
168 lpszFiles += wcslen(lpszFiles)+1;
169 if (*lpszFiles)
170 wcscat(lpszFilePatterns, L" ");
171 }
172 }
173 else
174 {
175 wcscpy(lpszFilePatterns, lpszFiles);
176 }
177
178 Edit_SetText(GetDlgItem(hDlg, IDC_TXT_FILE_TO_RESTORE), lpszFilePatterns);
180
183
184 MemFree(lpszFilePatterns);
185 }
186 }
187
189
190 break;
191 }
192
194 {
196 WCHAR szPath[MAX_PATH] = L"";
197
198 SecureZeroMemory(&ofn, sizeof(ofn));
199 ofn.lStructSize = sizeof(ofn);
200 ofn.hwndOwner = hDlg;
201 ofn.lpstrTitle = L"Open an archive file"; // L"Ouvrir un fichier archive"; // FIXME: Localize!
203 // ofn.FlagsEx = OFN_EX_NOPLACESBAR;
204 ofn.lpstrFilter = L"Cabinet files (*.cab)\0*.cab\0";
205 ofn.lpstrDefExt = L"cab";
206 ofn.nFilterIndex = 0;
209
210 if (GetOpenFileName(&ofn))
211 {
214 }
215
216 break;
217 }
218
220 {
221 BROWSEINFOW bi;
222 WCHAR szPath[MAX_PATH] = L"";
223
224 SecureZeroMemory(&bi, sizeof(bi));
225 bi.hwndOwner = hDlg;
226 bi.pidlRoot = NULL;
227 bi.lpszTitle = L"Select the directory where the restored files should be stored:";
228 // L"Choisissez le répertoire dans lequel doivent être enregistrés les fichiers restaurés :"; // FIXME: Localize!
229 bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE | BIF_VALIDATE /* | BIF_BROWSEFILEJUNCTIONS <--- only in Windows 7+ */;
230
232 {
233 /*PIDLIST_ABSOLUTE*/ LPITEMIDLIST pidl = SHBrowseForFolderW(&bi);
234 if (SHGetPathFromIDListW(pidl, szPath))
235 {
238 }
239
240 CoTaskMemFree(pidl);
242 }
243
244 break;
245 }
246
247 default:
248 //break;
249 return FALSE;
250 }
251 }
252 }
253
254 return FALSE;
255}
HWND hWnd
Definition: settings.c:17
#define IDC_BTN_BROWSE_CAB_FILES
Definition: resource.h:93
#define IDC_BTN_BROWSE_ALL_FILES
Definition: resource.h:92
#define IDC_DRP_DEST_DIR
Definition: resource.h:97
#define IDC_TXT_FILE_TO_RESTORE
Definition: resource.h:95
#define IDC_DRP_CAB_FILE
Definition: resource.h:96
#define IDC_BTN_BROWSE_DIRS
Definition: resource.h:94
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define GetSaveFileName
Definition: commdlg.h:666
#define OFN_EXPLORER
Definition: commdlg.h:104
#define OFN_LONGNAMES
Definition: commdlg.h:108
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_ENABLESIZING
Definition: commdlg.h:101
#define OFN_READONLY
Definition: commdlg.h:118
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
#define GetOpenFileName
Definition: commdlg.h:665
#define OFN_ALLOWMULTISELECT
Definition: commdlg.h:96
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1406
VOID AddStringToComboList(HWND hWnd, LPCWSTR lpszString)
INT_PTR CALLBACK FileExtractDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
GLdouble n
Definition: glext.h:7729
OPENFILENAME ofn
Definition: main.cpp:37
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
LPCWSTR szPath
Definition: env.c:37
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define BIF_VALIDATE
Definition: shlobj.h:1149
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1144
#define BIF_USENEWUI
Definition: shlobj.h:1151
#define BIF_SHAREABLE
Definition: shlobj.h:1160
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
Definition: tftpd.h:60
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1128
UINT ulFlags
Definition: shlobj.h:1131
HWND hwndOwner
Definition: shlobj.h:1127
LPCWSTR lpszTitle
Definition: shlobj.h:1130
LPCSTR lpstrDefExt
Definition: commdlg.h:345
DWORD nFilterIndex
Definition: commdlg.h:335
HWND hwndOwner
Definition: commdlg.h:330
LPCSTR lpstrTitle
Definition: commdlg.h:341
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
WORD nFileOffset
Definition: commdlg.h:343
DWORD lStructSize
Definition: commdlg.h:329
LPCSTR lpstrFilter
Definition: commdlg.h:332
DWORD nMaxFile
Definition: commdlg.h:337
int32_t INT_PTR
Definition: typedefs.h:64
#define SecureZeroMemory
Definition: winbase.h:1671
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:66
#define ComboBox_InsertString(hwndCtl, index, lpsz)
Definition: windowsx.h:61
#define Edit_SetSel(hwndCtl, ichStart, ichEnd)
Definition: windowsx.h:110
#define Edit_SetText(hwndCtl, lpsz)
Definition: windowsx.h:112
#define ComboBox_FindStringExact(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:47
#define IDCANCEL
Definition: winuser.h:825
#define GetDlgItemText
Definition: winuser.h:5775
#define WM_COMMAND
Definition: winuser.h:1730
#define CB_ERR
Definition: winuser.h:2425
#define WM_INITDIALOG
Definition: winuser.h:1729
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:824
#define MB_ICONERROR
Definition: winuser.h:781
HWND WINAPI SetFocus(_In_opt_ HWND)
int WINAPI GetWindowTextLengthW(_In_ HWND)
#define MB_OK
Definition: winuser.h:784
#define MB_ICONINFORMATION
Definition: winuser.h:796
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185