2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: DiscBrowse.cxx,v 1.7 2003/09/03 22:58:37 douglas Exp $ |
5 |
> |
// $Id: DiscBrowse.cxx,v 1.12 2003/09/12 04:26:54 douglas Exp $ |
6 |
|
|
7 |
|
#include "DiscBrowse.h" |
8 |
|
|
151 |
|
{ |
152 |
|
HKEY key; |
153 |
|
|
154 |
< |
if (RegCreateKeyEx(HKEY_CURRENT_USER, |
154 |
> |
if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER, |
155 |
|
"Software\\DouglasThrift\\VTBFileUtil2", 0, NULL, |
156 |
|
REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key, |
157 |
|
NULL) == ERROR_SUCCESS) |
172 |
|
|
173 |
|
if (discDir != data || type != REG_SZ) |
174 |
|
{ |
175 |
< |
if (RegSetValueEx(key, "DiscDir", 0, REG_SZ, |
175 |
> |
if (code = RegSetValueEx(key, "DiscDir", 0, REG_SZ, |
176 |
|
LPBYTE(discDir.c_str()), discDir.length() + 1) != |
177 |
|
ERROR_SUCCESS) |
178 |
|
{ |
179 |
< |
error(); |
179 |
> |
error(NULL, code); |
180 |
|
} |
181 |
|
} |
182 |
|
|
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
< |
error(); |
187 |
> |
error(NULL, code); |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
|
void DiscBrowse::setDiscDir(HWND parent) |
192 |
|
{ |
193 |
+ |
char buffer[MAX_PATH]; |
194 |
+ |
|
195 |
+ |
SHGetFolderPath(parent, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL, |
196 |
+ |
0, buffer); |
197 |
+ |
|
198 |
|
BROWSEINFO info; |
199 |
|
|
200 |
|
info.hwndOwner = parent; |
215 |
|
char folder[MAX_PATH]; |
216 |
|
|
217 |
|
if (SHGetPathFromIDList(id, folder)) discDir = tail(folder); |
213 |
– |
} |
218 |
|
|
219 |
< |
LPMALLOC destruct; |
219 |
> |
LPMALLOC destruct; |
220 |
|
|
221 |
< |
SHGetMalloc(&destruct); |
222 |
< |
destruct->Free(id); |
223 |
< |
destruct->Release(); |
221 |
> |
SHGetMalloc(&destruct); |
222 |
> |
destruct->Free(id); |
223 |
> |
destruct->Release(); |
224 |
> |
} |
225 |
|
|
226 |
|
if (discDir == "") |
227 |
|
{ |
267 |
|
|
268 |
|
FindClose(finder); |
269 |
|
} |
265 |
– |
else |
266 |
– |
{ |
267 |
– |
error(parent); |
268 |
– |
} |
270 |
|
|
271 |
|
if (clients.empty()) |
272 |
|
{ |
277 |
|
} |
278 |
|
while (clients.empty()); |
279 |
|
|
280 |
< |
if (!clients.empty()) |
280 |
> |
if (clients.empty()) |
281 |
> |
{ |
282 |
> |
PropSheet_PressButton(GetParent(parent), PSBTN_BACK); |
283 |
> |
} |
284 |
> |
else |
285 |
|
{ |
286 |
|
SHFILEINFO info; |
287 |
|
HIMAGELIST icons = |
312 |
|
DWORD bytes = GetFileSize(fileSize, NULL); |
313 |
|
|
314 |
|
CloseHandle(fileSize); |
315 |
< |
sprintf(clientFile, "%s", client.getFile().c_str()); |
316 |
< |
sprintf(clientNumber, "%u", client.getNumber()); |
317 |
< |
sprintf(clientName, "%s", client.getName().c_str()); |
318 |
< |
sprintf(clientSize, "%.2f MB", FLOAT(bytes) / FLOAT(1024 * 1024)); |
315 |
> |
StringCchPrintf(clientFile, MAX_PATH, "%s", |
316 |
> |
client.getFile().c_str()); |
317 |
> |
StringCchPrintf(clientNumber, MAX_PATH, "%u", client.getNumber()); |
318 |
> |
StringCchPrintf(clientName, MAX_PATH, "%s", |
319 |
> |
client.getName().c_str()); |
320 |
> |
StringCchPrintf(clientSize, MAX_PATH, "%.2f MB", FLOAT(bytes) / |
321 |
> |
FLOAT(1024 * 1024)); |
322 |
|
|
323 |
|
LVITEM number, name, file, size; |
324 |
|
|
393 |
|
SendMessage(dialog, BFFM_SETOKTEXT, 0, |
394 |
|
LPARAM(toWide("&Select").c_str())); |
395 |
|
SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES); |
396 |
< |
SendMessage(dialog, BFFM_SETSELECTION, TRUE, |
397 |
< |
LPARAM(data->discDir.c_str())); |
396 |
> |
|
397 |
> |
if (data->discDir != "") |
398 |
> |
{ |
399 |
> |
IShellFolder* desktop; |
400 |
> |
LPWSTR path = new WCHAR[data->discDir.length() + 1]; |
401 |
> |
LPITEMIDLIST id; |
402 |
> |
|
403 |
> |
StringCchPrintfW(path, data->discDir.length() + 1, L"%s", |
404 |
> |
toWide(data->discDir).c_str()); |
405 |
> |
|
406 |
> |
if (debug) cerr << "path = " << toAnsi(path) << "\n"; |
407 |
> |
|
408 |
> |
SHGetDesktopFolder(&desktop); |
409 |
> |
desktop->ParseDisplayName(dialog, NULL, path, NULL, &id, NULL); |
410 |
> |
|
411 |
> |
if (id != NULL) |
412 |
> |
{ |
413 |
> |
SendMessage(dialog, BFFM_SETSELECTION, FALSE, LPARAM(id)); |
414 |
> |
|
415 |
> |
LPMALLOC destruct; |
416 |
> |
|
417 |
> |
SHGetMalloc(&destruct); |
418 |
> |
destruct->Free(id); |
419 |
> |
destruct->Release(); |
420 |
> |
} |
421 |
> |
|
422 |
> |
desktop->Release(); |
423 |
> |
} |
424 |
|
break; |
425 |
|
case BFFM_SELCHANGED: |
426 |
|
{ |
607 |
|
INT_PTR DiscBrowse::browse(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
608 |
|
{ |
609 |
|
DiscBrowse* data = which(dialog); |
610 |
+ |
int previous = -1; |
611 |
|
|
612 |
|
switch (msg) |
613 |
|
{ |
648 |
|
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 3, |
649 |
|
&size); |
650 |
|
} |
651 |
+ |
|
652 |
+ |
{ |
653 |
+ |
int columns[4]; |
654 |
+ |
|
655 |
+ |
columns[0] = 1; |
656 |
+ |
columns[1] = 2; |
657 |
+ |
columns[2] = 0; |
658 |
+ |
columns[3] = 3; |
659 |
+ |
|
660 |
+ |
ListView_SetColumnOrderArray(GetDlgItem(dialog, IDC_BROWSE_DISC), |
661 |
+ |
4, columns); |
662 |
+ |
} |
663 |
|
break; |
664 |
|
case WM_NOTIFY: |
665 |
|
if (w == IDC_BROWSE_DISC) |
706 |
|
} |
707 |
|
} |
708 |
|
break; |
709 |
+ |
case LVN_ITEMCHANGED: |
710 |
+ |
if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC), |
711 |
+ |
-1, LVNI_SELECTED) != -1) |
712 |
+ |
{ |
713 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), TRUE); |
714 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), TRUE); |
715 |
+ |
} |
716 |
+ |
else |
717 |
+ |
{ |
718 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
719 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
720 |
+ |
} |
721 |
+ |
break; |
722 |
|
case NM_DBLCLK: |
723 |
|
if (ni->iItem != -1) |
724 |
|
{ |
725 |
< |
// |
725 |
> |
char scan[MAX_PATH]; |
726 |
> |
|
727 |
> |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
728 |
> |
ni->iItem, 0, scan, MAX_PATH); |
729 |
> |
ShellExecute(dialog, NULL, scan, NULL, NULL, |
730 |
> |
SW_SHOWDEFAULT); |
731 |
|
} |
732 |
|
break; |
733 |
|
} |
767 |
|
} |
768 |
|
break; |
769 |
|
case PSN_WIZBACK: |
770 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
771 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
772 |
|
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC)); |
773 |
|
break; |
774 |
|
} |
775 |
|
} |
776 |
+ |
break; |
777 |
+ |
case WM_COMMAND: |
778 |
+ |
switch (LOWORD(w)) |
779 |
+ |
{ |
780 |
+ |
case IDC_BROWSE_REFRESH: |
781 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
782 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
783 |
+ |
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC)); |
784 |
+ |
data->populate(dialog); |
785 |
+ |
|
786 |
+ |
{ |
787 |
+ |
SHFILEINFO info; |
788 |
+ |
|
789 |
+ |
SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info), |
790 |
+ |
SHGFI_ICONLOCATION); |
791 |
+ |
|
792 |
+ |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
793 |
+ |
info.iIcon); |
794 |
+ |
|
795 |
+ |
SendDlgItemMessage(dialog, IDC_BROWSE_ICON, STM_SETIMAGE, |
796 |
+ |
IMAGE_ICON, LPARAM(icon)); |
797 |
+ |
} |
798 |
+ |
|
799 |
+ |
{ |
800 |
+ |
SHFILEINFO info; |
801 |
+ |
|
802 |
+ |
SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info), |
803 |
+ |
SHGFI_DISPLAYNAME); |
804 |
+ |
|
805 |
+ |
SetDlgItemText(dialog, IDC_BROWSE_TEXT, info.szDisplayName); |
806 |
+ |
} |
807 |
+ |
break; |
808 |
+ |
case IDC_BROWSE_OPEN: |
809 |
+ |
do |
810 |
+ |
{ |
811 |
+ |
char scan[MAX_PATH]; |
812 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
813 |
+ |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
814 |
+ |
|
815 |
+ |
previous = index; |
816 |
+ |
|
817 |
+ |
if (previous == -1) continue; |
818 |
+ |
|
819 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
820 |
+ |
index, 0, scan, MAX_PATH); |
821 |
+ |
ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT); |
822 |
+ |
} |
823 |
+ |
while (previous != -1); |
824 |
+ |
break; |
825 |
+ |
case IDC_BROWSE_PROP: |
826 |
+ |
do |
827 |
+ |
{ |
828 |
+ |
char scan[MAX_PATH]; |
829 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
830 |
+ |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
831 |
+ |
|
832 |
+ |
previous = index; |
833 |
+ |
|
834 |
+ |
if (previous == -1) continue; |
835 |
+ |
|
836 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
837 |
+ |
index, 0, scan, MAX_PATH); |
838 |
+ |
|
839 |
+ |
SHELLEXECUTEINFO info; |
840 |
+ |
|
841 |
+ |
info.cbSize = sizeof(info); |
842 |
+ |
info.fMask = SEE_MASK_INVOKEIDLIST; |
843 |
+ |
info.hwnd = dialog; |
844 |
+ |
info.lpVerb = "properties"; |
845 |
+ |
info.lpFile = scan; |
846 |
+ |
info.lpParameters = NULL; |
847 |
+ |
info.lpDirectory = NULL; |
848 |
+ |
info.nShow = SW_SHOWDEFAULT; |
849 |
+ |
info.lpIDList = NULL; |
850 |
+ |
|
851 |
+ |
ShellExecuteEx(&info); |
852 |
+ |
} |
853 |
+ |
while (previous != -1); |
854 |
+ |
break; |
855 |
+ |
} |
856 |
+ |
break; |
857 |
+ |
case WM_CONTEXTMENU: |
858 |
+ |
if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC), -1, |
859 |
+ |
LVNI_SELECTED) != -1) |
860 |
+ |
{ |
861 |
+ |
POINT spot; |
862 |
+ |
LVHITTESTINFO test; |
863 |
+ |
|
864 |
+ |
test.pt.x = GET_X_LPARAM(l); |
865 |
+ |
test.pt.y = GET_Y_LPARAM(l); |
866 |
+ |
|
867 |
+ |
ScreenToClient(GetDlgItem(dialog, IDC_BROWSE_DISC), &test.pt); |
868 |
+ |
ListView_HitTest(GetDlgItem(dialog, IDC_BROWSE_DISC), &test); |
869 |
+ |
|
870 |
+ |
if (test.iItem != -1) |
871 |
+ |
{ |
872 |
+ |
spot.x = test.pt.x; |
873 |
+ |
spot.y = test.pt.y; |
874 |
+ |
} |
875 |
+ |
else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1) |
876 |
+ |
{ |
877 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
878 |
+ |
IDC_BROWSE_DISC), -1, LVNI_SELECTED); |
879 |
+ |
RECT rect; |
880 |
+ |
|
881 |
+ |
ListView_EnsureVisible(GetDlgItem(dialog, IDC_BROWSE_DISC), |
882 |
+ |
index, FALSE); |
883 |
+ |
ListView_GetItemRect(GetDlgItem(dialog, IDC_BROWSE_DISC), |
884 |
+ |
index, &rect, LVIR_SELECTBOUNDS); |
885 |
+ |
|
886 |
+ |
spot.x = rect.left; |
887 |
+ |
spot.y = rect.top; |
888 |
+ |
} |
889 |
+ |
|
890 |
+ |
ClientToScreen(GetDlgItem(dialog, IDC_BROWSE_DISC), &spot); |
891 |
+ |
|
892 |
+ |
int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN | |
893 |
+ |
TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, |
894 |
+ |
spot.x, spot.y, GetDlgItem(dialog, IDC_BROWSE_DISC), NULL); |
895 |
+ |
|
896 |
+ |
switch (code) |
897 |
+ |
{ |
898 |
+ |
case 1: |
899 |
+ |
do |
900 |
+ |
{ |
901 |
+ |
char scan[MAX_PATH]; |
902 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
903 |
+ |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
904 |
+ |
|
905 |
+ |
previous = index; |
906 |
+ |
|
907 |
+ |
if (previous == -1) continue; |
908 |
+ |
|
909 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
910 |
+ |
index, 0, scan, MAX_PATH); |
911 |
+ |
ShellExecute(dialog, NULL, scan, NULL, NULL, |
912 |
+ |
SW_SHOWDEFAULT); |
913 |
+ |
} |
914 |
+ |
while (previous != -1); |
915 |
+ |
break; |
916 |
+ |
case 2: |
917 |
+ |
do |
918 |
+ |
{ |
919 |
+ |
char scan[MAX_PATH]; |
920 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
921 |
+ |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
922 |
+ |
|
923 |
+ |
previous = index; |
924 |
+ |
|
925 |
+ |
if (previous == -1) continue; |
926 |
+ |
|
927 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
928 |
+ |
index, 0, scan, MAX_PATH); |
929 |
+ |
|
930 |
+ |
SHELLEXECUTEINFO info; |
931 |
+ |
|
932 |
+ |
info.cbSize = sizeof(info); |
933 |
+ |
info.fMask = SEE_MASK_INVOKEIDLIST; |
934 |
+ |
info.hwnd = dialog; |
935 |
+ |
info.lpVerb = "properties"; |
936 |
+ |
info.lpFile = scan; |
937 |
+ |
info.lpParameters = NULL; |
938 |
+ |
info.lpDirectory = NULL; |
939 |
+ |
info.nShow = SW_SHOWDEFAULT; |
940 |
+ |
info.lpIDList = NULL; |
941 |
+ |
|
942 |
+ |
ShellExecuteEx(&info); |
943 |
+ |
} |
944 |
+ |
while (previous != -1); |
945 |
+ |
break; |
946 |
+ |
} |
947 |
+ |
} |
948 |
|
break; |
949 |
|
} |
950 |
|
|