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>
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!!
18 // #include <setupapi.h>
19 #include "fileextractdialog.h"
20 #include "comctl32supp.h"
23 // #include "callbacks.h"
25 // FIXME: This should be present in PSDK commdlg.h
28 #if (_WIN32_WINNT >= 0x0500)
29 #define OFN_EX_NOPLACESBAR 0x00000001
30 #endif // (_WIN32_WINNT >= 0x0500)
34 AddStringToComboList(HWND hWnd
,
37 /* Try to find an already existing occurrence of the string in the list */
38 LRESULT hPos
= ComboBox_FindStringExact(hWnd
, -1, lpszString
);
42 /* The string doesn't exist, so add it to the list and select it */
43 ComboBox_InsertString(hWnd
, 0, lpszString
);
44 ComboBox_SetCurSel(hWnd
, 0);
48 /* The string exists, so select it */
49 ComboBox_SetCurSel(hWnd
, hPos
);
56 FileExtractDialogWndProc(HWND hDlg
,
61 UNREFERENCED_PARAMETER(lParam
);
70 switch (LOWORD(wParam
))
74 LPWSTR szCabPathFileName
, szFileName
, szDestDir
;
75 size_t cabPathNum
, fileNameNum
, destDirNum
;
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
);
81 fileNameNum
= GetWindowTextLengthW(GetDlgItem(hDlg
, IDC_TXT_FILE_TO_RESTORE
)) + 1;
82 szFileName
= (LPWSTR
)MemAlloc(0, fileNameNum
* sizeof(WCHAR
));
83 GetDlgItemText(hDlg
, IDC_TXT_FILE_TO_RESTORE
, szFileName
, (int)fileNameNum
);
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
);
90 if (!ExtractFromCabinet(szCabPathFileName
, szFileName
, szDestDir
))
92 MessageBoxW(NULL
, L
"An error has occurred!!", L
"Error", MB_ICONERROR
| MB_OK
);
96 MessageBoxW(NULL
, L
"All the files were uncompressed successfully.", L
"Info", MB_ICONINFORMATION
| MB_OK
);
98 // TODO: Save the extraction paths into the registry.
101 EndDialog(hDlg
, LOWORD(wParam
));
104 MessageBoxW(NULL
, L
"File extraction is unimplemented!", L
"Info", MB_ICONINFORMATION
| MB_OK
);
109 MemFree(szCabPathFileName
);
115 EndDialog(hDlg
, LOWORD(wParam
));
118 case IDC_BTN_BROWSE_ALL_FILES
:
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
));
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!
129 ofn
.Flags
= OFN_ALLOWMULTISELECT
| OFN_EXPLORER
| OFN_ENABLESIZING
| OFN_HIDEREADONLY
| OFN_LONGNAMES
;
130 // ofn.FlagsEx = OFN_EX_NOPLACESBAR;
131 ofn
.lpstrFilter
= L
"All files (*.*)\0*.*\0";
132 ofn
.nFilterIndex
= 0;
133 ofn
.lpstrFile
= szPath
;
134 ofn
.nMaxFile
= (DWORD
)newSize
; // TODO: size_t to DWORD conversion...
136 if (GetSaveFileName(&ofn
))
138 if ( (ofn
.Flags
& OFN_EXPLORER
) &&
139 (ofn
.Flags
& OFN_ALLOWMULTISELECT
) ) // Must be always true...
141 LPWSTR lpszFiles
= szPath
+ ofn
.nFileOffset
;
142 LPWSTR lpszFilePatterns
= NULL
;
144 LPWSTR lpszTmp
= lpszFiles
;
146 size_t numOfChars
= 0;
148 /* Truncate the path, if needed */
149 szPath
[ofn
.nFileOffset
- 1] = L
'\0';
154 numOfChars
+= wcslen(lpszTmp
)+1 + 3; // 3 = 2 quotation marks + 1 space.
155 lpszTmp
+= wcslen(lpszTmp
)+1;
158 lpszFilePatterns
= (LPWSTR
)MemAlloc(HEAP_ZERO_MEMORY
, numOfChars
*sizeof(WCHAR
));
164 wcscat(lpszFilePatterns
, L
"\"");
165 wcscat(lpszFilePatterns
, lpszFiles
);
166 wcscat(lpszFilePatterns
, L
"\"");
168 lpszFiles
+= wcslen(lpszFiles
)+1;
170 wcscat(lpszFilePatterns
, L
" ");
175 wcscpy(lpszFilePatterns
, lpszFiles
);
178 Edit_SetText(GetDlgItem(hDlg
, IDC_TXT_FILE_TO_RESTORE
), lpszFilePatterns
);
179 AddStringToComboList(GetDlgItem(hDlg
, IDC_DRP_DEST_DIR
), szPath
);
181 SetFocus(GetDlgItem(hDlg
, IDC_TXT_FILE_TO_RESTORE
));
182 Edit_SetSel(GetDlgItem(hDlg
, IDC_TXT_FILE_TO_RESTORE
), 0, -1);
184 MemFree(lpszFilePatterns
);
193 case IDC_BTN_BROWSE_CAB_FILES
:
196 WCHAR szPath
[MAX_PATH
] = L
"";
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!
202 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLESIZING
| OFN_HIDEREADONLY
| OFN_LONGNAMES
| OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_READONLY
;
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;
207 ofn
.lpstrFile
= szPath
;
208 ofn
.nMaxFile
= ARRAYSIZE(szPath
);
210 if (GetOpenFileName(&ofn
))
212 AddStringToComboList(GetDlgItem(hDlg
, IDC_DRP_CAB_FILE
), szPath
);
213 SetFocus(GetDlgItem(hDlg
, IDC_DRP_CAB_FILE
));
219 case IDC_BTN_BROWSE_DIRS
:
222 WCHAR szPath
[MAX_PATH
] = L
"";
224 SecureZeroMemory(&bi
, sizeof(bi
));
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+ */;
231 if (SUCCEEDED(CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
)))
233 /*PIDLIST_ABSOLUTE*/ LPITEMIDLIST pidl
= SHBrowseForFolderW(&bi
);
234 if (SHGetPathFromIDListW(pidl
, szPath
))
236 AddStringToComboList(GetDlgItem(hDlg
, IDC_DRP_DEST_DIR
), szPath
);
237 SetFocus(GetDlgItem(hDlg
, IDC_DRP_DEST_DIR
));