[shell32.dll]

[FORMATTING]
- Format the code to a more acceptable level. This is just for my sanity while sifting through it.

svn path=/branches/shell32_new-bringup/; revision=53537
This commit is contained in:
Claudiu Mihail 2011-09-03 00:08:11 +00:00
parent 5beaebef93
commit b815342563
2 changed files with 334 additions and 272 deletions

View file

@ -101,7 +101,8 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
/* space */ /* space */
argc++; argc++;
/* skip the remaining spaces */ /* skip the remaining spaces */
while (*cs==0x0009 || *cs==0x0020) { while (*cs==0x0009 || *cs==0x0020)
{
cs++; cs++;
} }
if (*cs==0) if (*cs==0)
@ -131,9 +132,11 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
* This way the caller can make a single GlobalFree call to free both, as per MSDN. * This way the caller can make a single GlobalFree call to free both, as per MSDN.
*/ */
argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR)); argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
if (!argv)
if (!argv)
return NULL; return NULL;
cmdline=(LPWSTR)(argv+argc);
cmdline=(LPWSTR)(argv+argc);
wcscpy(cmdline, lpCmdline); wcscpy(cmdline, lpCmdline);
argc=0; argc=0;
@ -238,15 +241,18 @@ static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET ); SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
ReadFile( hfile, magic, sizeof(magic), &len, NULL ); ReadFile( hfile, magic, sizeof(magic), &len, NULL );
if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
{ {
SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET ); SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
ReadFile( hfile, &nt, sizeof(nt), &len, NULL ); ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
CloseHandle( hfile ); CloseHandle( hfile );
/* DLL files are not executable and should return 0 */
/* DLL files are not executable and should return 0 */
if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL) if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
return 0; return 0;
if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
{ {
return IMAGE_NT_SIGNATURE | return IMAGE_NT_SIGNATURE |
(nt.OptionalHeader.MajorSubsystemVersion << 24) | (nt.OptionalHeader.MajorSubsystemVersion << 24) |
@ -260,7 +266,8 @@ static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET ); SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
ReadFile( hfile, &ne, sizeof(ne), &len, NULL ); ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
CloseHandle( hfile ); CloseHandle( hfile );
if (ne.ne_exetyp == 2)
if (ne.ne_exetyp == 2)
return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16); return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
return 0; return 0;
} }
@ -582,7 +589,8 @@ DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
GetSystemMetrics( SM_CXICON), GetSystemMetrics( SM_CXICON),
GetSystemMetrics( SM_CYICON), GetSystemMetrics( SM_CYICON),
&psfi->hIcon, 0, 1, 0); &psfi->hIcon, 0, 1, 0);
if (ret != 0 && ret != 0xFFFFFFFF)
if (ret != 0 && ret != 0xFFFFFFFF)
{ {
IconNotYetLoaded=FALSE; IconNotYetLoaded=FALSE;
psfi->iIcon = icon_idx; psfi->iIcon = icon_idx;
@ -849,41 +857,51 @@ UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
switch (msg) switch (msg)
{ {
case ABM_GETSTATE: case ABM_GETSTATE:
return ABS_ALWAYSONTOP | ABS_AUTOHIDE; return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
case ABM_GETTASKBARPOS:
GetWindowRect(data->hWnd, &rec); case ABM_GETTASKBARPOS:
data->rc=rec; GetWindowRect(data->hWnd, &rec);
return TRUE; data->rc=rec;
case ABM_ACTIVATE: return TRUE;
SetActiveWindow(data->hWnd);
return TRUE; case ABM_ACTIVATE:
case ABM_GETAUTOHIDEBAR: SetActiveWindow(data->hWnd);
return 0; /* pretend there is no autohide bar */ return TRUE;
case ABM_NEW:
/* cbSize, hWnd, and uCallbackMessage are used. All other ignored */ case ABM_GETAUTOHIDEBAR:
SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE); return 0; /* pretend there is no autohide bar */
return TRUE;
case ABM_QUERYPOS: case ABM_NEW:
GetWindowRect(data->hWnd, &(data->rc)); /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
return TRUE; SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
case ABM_REMOVE: return TRUE;
FIXME("ABM_REMOVE broken\n");
/* FIXME: this is wrong; should it be DestroyWindow instead? */ case ABM_QUERYPOS:
/*CloseHandle(data->hWnd);*/ GetWindowRect(data->hWnd, &(data->rc));
return TRUE; return TRUE;
case ABM_SETAUTOHIDEBAR:
SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top, case ABM_REMOVE:
width,height,SWP_SHOWWINDOW); FIXME("ABM_REMOVE broken\n");
return TRUE; /* FIXME: this is wrong; should it be DestroyWindow instead? */
case ABM_SETPOS: /*CloseHandle(data->hWnd);*/
data->uEdge=(ABE_RIGHT | ABE_LEFT); return TRUE;
SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
width,height,SWP_SHOWWINDOW); case ABM_SETAUTOHIDEBAR:
return TRUE; SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
case ABM_WINDOWPOSCHANGED: width,height,SWP_SHOWWINDOW);
return TRUE; return TRUE;
case ABM_SETPOS:
data->uEdge=(ABE_RIGHT | ABE_LEFT);
SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
width,height,SWP_SHOWWINDOW);
return TRUE;
case ABM_WINDOWPOSCHANGED:
return TRUE;
} }
return FALSE; return FALSE;
} }
@ -1076,7 +1094,9 @@ INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
} }
// We need the decimal point of the current locale to display the RAM size correctly // We need the decimal point of the current locale to display the RAM size correctly
if( GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szDecimalSeparator, sizeof(szDecimalSeparator) / sizeof(WCHAR)) > 0) if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL,
szDecimalSeparator,
sizeof(szDecimalSeparator) / sizeof(WCHAR)) > 0)
{ {
UCHAR uDecimals; UCHAR uDecimals;
UINT uIntegral; UINT uIntegral;
@ -1127,11 +1147,10 @@ INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
} }
}; break;
break;
}
case WM_COMMAND: case WM_COMMAND:
{
switch(wParam) switch(wParam)
{ {
case IDOK: case IDOK:
@ -1160,7 +1179,7 @@ INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
return TRUE; return TRUE;
} }
} }
break; }; break;
case WM_CLOSE: case WM_CLOSE:
EndDialog(hWnd, TRUE); EndDialog(hWnd, TRUE);

View file

@ -107,7 +107,8 @@ static void confirm_msg_move_button(HWND hDlg, INT iId, INT *xPos, INT yOffset,
HWND hButton = GetDlgItem(hDlg, iId); HWND hButton = GetDlgItem(hDlg, iId);
RECT r; RECT r;
if (bShow) { if (bShow)
{
POINT pt; POINT pt;
int width; int width;
@ -143,7 +144,8 @@ static INT_PTR ConfirmMsgBox_Paint(HWND hDlg)
DrawTextW(hdc, (LPWSTR)GetPropW(hDlg, CONFIRM_MSG_PROP), -1, &r, DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_WORDBREAK); DrawTextW(hdc, (LPWSTR)GetPropW(hDlg, CONFIRM_MSG_PROP), -1, &r, DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_WORDBREAK);
SelectObject(hdc, hOldFont); SelectObject(hdc, hOldFont);
EndPaint(hDlg, &ps); EndPaint(hDlg, &ps);
return TRUE;
return TRUE;
} }
static INT_PTR ConfirmMsgBox_Init(HWND hDlg, LPARAM lParam) static INT_PTR ConfirmMsgBox_Init(HWND hDlg, LPARAM lParam)
@ -183,6 +185,7 @@ static INT_PTR ConfirmMsgBox_Init(HWND hDlg, LPARAM lParam)
confirm_msg_move_button(hDlg, IDNO, &xPos, yOffset, TRUE); confirm_msg_move_button(hDlg, IDNO, &xPos, yOffset, TRUE);
confirm_msg_move_button(hDlg, IDD_YESTOALL, &xPos, yOffset, info->bYesToAll); confirm_msg_move_button(hDlg, IDD_YESTOALL, &xPos, yOffset, info->bYesToAll);
confirm_msg_move_button(hDlg, IDYES, &xPos, yOffset, TRUE); confirm_msg_move_button(hDlg, IDYES, &xPos, yOffset, TRUE);
return TRUE; return TRUE;
} }
@ -219,69 +222,80 @@ int SHELL_ConfirmMsgBox(HWND hWnd, LPWSTR lpszText, LPWSTR lpszCaption, HICON hI
/* confirmation dialogs content */ /* confirmation dialogs content */
typedef struct typedef struct
{ {
HINSTANCE hIconInstance; HINSTANCE hIconInstance;
UINT icon_resource_id; UINT icon_resource_id;
UINT caption_resource_id, text_resource_id; UINT caption_resource_id, text_resource_id;
} SHELL_ConfirmIDstruc; } SHELL_ConfirmIDstruc;
static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids) static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids)
{ {
ids->hIconInstance = shell32_hInstance; ids->hIconInstance = shell32_hInstance;
switch (nKindOfDialog) { switch (nKindOfDialog)
case ASK_DELETE_FILE: {
case ASK_DELETE_FILE:
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
ids->text_resource_id = IDS_DELETEITEM_TEXT;
return TRUE;
case ASK_DELETE_FOLDER:
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION; ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
ids->text_resource_id = IDS_DELETEITEM_TEXT; ids->text_resource_id = IDS_DELETEITEM_TEXT;
return TRUE; return TRUE;
case ASK_DELETE_FOLDER:
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; case ASK_DELETE_MULTIPLE_ITEM:
ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->text_resource_id = IDS_DELETEITEM_TEXT; ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
return TRUE; ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT;
case ASK_DELETE_MULTIPLE_ITEM: return TRUE;
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION; case ASK_TRASH_FILE:
ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT; ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
return TRUE; ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
case ASK_TRASH_FILE: ids->text_resource_id = IDS_TRASHITEM_TEXT;
ids->icon_resource_id = IDI_SHELL_TRASH_FILE; return TRUE;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
ids->text_resource_id = IDS_TRASHITEM_TEXT; case ASK_TRASH_FOLDER:
return TRUE; ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
case ASK_TRASH_FOLDER: ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
ids->icon_resource_id = IDI_SHELL_TRASH_FILE; ids->text_resource_id = IDS_TRASHFOLDER_TEXT;
ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION; return TRUE;
ids->text_resource_id = IDS_TRASHFOLDER_TEXT;
return TRUE; case ASK_TRASH_MULTIPLE_ITEM:
case ASK_TRASH_MULTIPLE_ITEM: ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
ids->icon_resource_id = IDI_SHELL_TRASH_FILE; ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION; ids->text_resource_id = IDS_TRASHMULTIPLE_TEXT;
ids->text_resource_id = IDS_TRASHMULTIPLE_TEXT; return TRUE;
return TRUE;
case ASK_CANT_TRASH_ITEM: case ASK_CANT_TRASH_ITEM:
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_DELETEITEM_CAPTION; ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
ids->text_resource_id = IDS_CANTTRASH_TEXT; ids->text_resource_id = IDS_CANTTRASH_TEXT;
return TRUE; return TRUE;
case ASK_DELETE_SELECTED:
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; case ASK_DELETE_SELECTED:
ids->caption_resource_id = IDS_DELETEITEM_CAPTION; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->text_resource_id = IDS_DELETESELECTED_TEXT; ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
return TRUE; ids->text_resource_id = IDS_DELETESELECTED_TEXT;
return TRUE;
case ASK_OVERWRITE_FILE: case ASK_OVERWRITE_FILE:
ids->hIconInstance = NULL; ids->hIconInstance = NULL;
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION; ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
ids->text_resource_id = IDS_OVERWRITEFILE_TEXT; ids->text_resource_id = IDS_OVERWRITEFILE_TEXT;
return TRUE; return TRUE;
case ASK_OVERWRITE_FOLDER: case ASK_OVERWRITE_FOLDER:
ids->hIconInstance = NULL; ids->hIconInstance = NULL;
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE; ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION; ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
ids->text_resource_id = IDS_OVERWRITEFOLDER_TEXT; ids->text_resource_id = IDS_OVERWRITEFOLDER_TEXT;
return TRUE; return TRUE;
default:
FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog); default:
FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
} }
return FALSE; return FALSE;
} }
@ -294,11 +308,13 @@ static BOOL SHELL_ConfirmDialogW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir, FI
HICON hIcon; HICON hIcon;
int ret; int ret;
assert(nKindOfDialog >= 0 && nKindOfDialog < 32); DbgPrint("[shell32, SHELL_ConfirmDialogW] Called\n");
if (op && (op->dwYesToAllMask & (1 << nKindOfDialog)))
return TRUE;
if (!SHELL_ConfirmIDs(nKindOfDialog, &ids)) return FALSE; assert(nKindOfDialog >= 0 && nKindOfDialog < 32);
if (op && (op->dwYesToAllMask & (1 << nKindOfDialog)))
return TRUE;
if (!SHELL_ConfirmIDs(nKindOfDialog, &ids)) return FALSE;
LoadStringW(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption)/sizeof(WCHAR)); LoadStringW(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption)/sizeof(WCHAR));
LoadStringW(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText)/sizeof(WCHAR)); LoadStringW(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText)/sizeof(WCHAR));
@ -306,20 +322,22 @@ static BOOL SHELL_ConfirmDialogW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir, FI
args[0] = (DWORD_PTR)szDir; args[0] = (DWORD_PTR)szDir;
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)args); szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)args);
hIcon = LoadIconW(ids.hIconInstance, (LPWSTR)MAKEINTRESOURCE(ids.icon_resource_id)); hIcon = LoadIconW(ids.hIconInstance, (LPWSTR)MAKEINTRESOURCE(ids.icon_resource_id));
ret = SHELL_ConfirmMsgBox(hWnd, szBuffer, szCaption, hIcon, op && op->bManyItems); ret = SHELL_ConfirmMsgBox(hWnd, szBuffer, szCaption, hIcon, op && op->bManyItems);
if (op) { if (op)
if (ret == IDD_YESTOALL) { {
op->dwYesToAllMask |= (1 << nKindOfDialog); if (ret == IDD_YESTOALL)
ret = IDYES; {
} op->dwYesToAllMask |= (1 << nKindOfDialog);
if (ret == IDCANCEL) ret = IDYES;
op->bCancelled = TRUE;
if (ret != IDYES)
op->req->fAnyOperationsAborted = TRUE;
} }
return ret == IDYES; if (ret == IDCANCEL)
op->bCancelled = TRUE;
if (ret != IDYES)
op->req->fAnyOperationsAborted = TRUE;
}
return ret == IDYES;
} }
BOOL SHELL_ConfirmYesNoW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir) BOOL SHELL_ConfirmYesNoW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir)
@ -375,20 +393,20 @@ BOOL SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL))) if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
{ {
do do
{ {
if (IsDotDir(wfd.cFileName)) if (IsDotDir(wfd.cFileName))
continue; continue;
PathCombineW(szTemp, pszDir, wfd.cFileName); PathCombineW(szTemp, pszDir, wfd.cFileName);
if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
ret = SHELL_DeleteDirectoryW(hwnd, szTemp, FALSE); ret = SHELL_DeleteDirectoryW(hwnd, szTemp, FALSE);
else else
ret = (SHNotifyDeleteFileW(szTemp) == ERROR_SUCCESS); ret = (SHNotifyDeleteFileW(szTemp) == ERROR_SUCCESS);
} while (ret && FindNextFileW(hFind, &wfd)); } while (ret && FindNextFileW(hFind, &wfd));
} }
FindClose(hFind); FindClose(hFind);
if (ret) if (ret)
ret = (SHNotifyRemoveDirectoryW(pszDir) == ERROR_SUCCESS); ret = (SHNotifyRemoveDirectoryW(pszDir) == ERROR_SUCCESS);
return ret; return ret;
} }
@ -486,13 +504,13 @@ static DWORD SHNotifyDeleteFileW(LPCWSTR path)
/* File may be write protected or a system file */ /* File may be write protected or a system file */
DWORD dwAttr = GetFileAttributesW(path); DWORD dwAttr = GetFileAttributesW(path);
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)) if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))) if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
ret = DeleteFileW(path); ret = DeleteFileW(path);
} }
if (ret) if (ret)
{ {
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL); SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
return GetLastError(); return GetLastError();
} }
@ -536,16 +554,16 @@ static DWORD SHNotifyMoveFileW(LPCWSTR src, LPCWSTR dest)
if (INVALID_FILE_ATTRIBUTES == dwAttr) if (INVALID_FILE_ATTRIBUTES == dwAttr)
{ {
/* Source file may be write protected or a system file */ /* Source file may be write protected or a system file */
dwAttr = GetFileAttributesW(src); dwAttr = GetFileAttributesW(src);
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)) if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
if (SetFileAttributesW(src, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))) if (SetFileAttributesW(src, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
ret = MoveFileW(src, dest); ret = MoveFileW(src, dest);
} }
} }
if (ret) if (ret)
{ {
SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_PATHW, src, dest); SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_PATHW, src, dest);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
return GetLastError(); return GetLastError();
} }
@ -623,51 +641,52 @@ static INT_PTR CALLBACK SHOperationDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam
switch(uMsg) switch(uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)lParam); SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)lParam);
/* get context */ /* get context */
Context = (FILE_OPERATION_CONTEXT*)lParam; Context = (FILE_OPERATION_CONTEXT*)lParam;
/* store progress bar handle */ /* store progress bar handle */
Context->hDlgCtrl = GetDlgItem(hwndDlg, 14000); Context->hDlgCtrl = GetDlgItem(hwndDlg, 14000);
/* store window handle */ /* store window handle */
Context->hwndDlg = hwndDlg; Context->hwndDlg = hwndDlg;
/* set progress bar range */ /* set progress bar range */
(void)SendMessageW(Context->hDlgCtrl, (UINT) PBM_SETRANGE, 0, MAKELPARAM(0, 100)); (void)SendMessageW(Context->hDlgCtrl, (UINT) PBM_SETRANGE, 0, MAKELPARAM(0, 100));
/* start file queueing */ /* start file queueing */
SetTimer(hwndDlg, TIMER_ID, 1000, NULL); SetTimer(hwndDlg, TIMER_ID, 1000, NULL);
//QueueFile(Context); //QueueFile(Context);
return TRUE; return TRUE;
case WM_CLOSE: case WM_CLOSE:
Context->op->bCancelled = TRUE; Context->op->bCancelled = TRUE;
EndDialog(hwndDlg, Context->op->bCancelled); EndDialog(hwndDlg, Context->op->bCancelled);
return TRUE; return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == 14002) case WM_COMMAND:
{ if (LOWORD(wParam) == 14002)
Context->op->bCancelled = TRUE; {
EndDialog(hwndDlg, Context->op->bCancelled); Context->op->bCancelled = TRUE;
return TRUE; EndDialog(hwndDlg, Context->op->bCancelled);
} return TRUE;
break; }; break;
case WM_TIMER:
if (wParam == TIMER_ID) case WM_TIMER:
{ if (wParam == TIMER_ID)
QueueFile(Context); {
KillTimer(hwndDlg, TIMER_ID); QueueFile(Context);
} KillTimer(hwndDlg, TIMER_ID);
break; }; break;
case WM_FILE:
if (!QueueFile(Context)) case WM_FILE:
EndDialog(hwndDlg, Context->op->bCancelled); if (!QueueFile(Context))
default: EndDialog(hwndDlg, Context->op->bCancelled);
break; default:
break;
} }
return FALSE; return FALSE;
} }
@ -726,18 +745,30 @@ static DWORD SHNotifyCopyFileW(LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists)
BOOL ret; BOOL ret;
DWORD attribs; DWORD attribs;
DbgPrint("[shell32, SHNotifyCopyFileW] Called\n");
TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : ""); TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : "");
/* Destination file may already exist with read only attribute */ /* Destination file may already exist with read only attribute */
attribs = GetFileAttributesW(dest); attribs = GetFileAttributesW(dest);
if (IsAttrib(attribs, FILE_ATTRIBUTE_READONLY)) if (IsAttrib(attribs, FILE_ATTRIBUTE_READONLY))
SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY); SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY);
if (GetFileAttributesW(dest) & FILE_ATTRIBUTE_READONLY)
{
SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY);
DbgPrint("[shell32, SHNotifyCopyFileW] Something went really WRONG...%ls, we still have FILE_ATTRIBUTE_READONLY\n", dest);
if (GetFileAttributesW(dest) & FILE_ATTRIBUTE_READONLY)
{
DbgPrint("[shell32, SHNotifyCopyFileW] STILL SHIT\n");
}
}
ret = CopyFileW(src, dest, bFailIfExists); ret = CopyFileW(src, dest, bFailIfExists);
if (ret) if (ret)
{ {
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL); SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
return GetLastError(); return GetLastError();
@ -815,8 +846,8 @@ int WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES se
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0); retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
if (!retCode) if (!retCode)
{ {
retCode = SHCreateDirectoryExW(hWnd, wPath, sec); retCode = SHCreateDirectoryExW(hWnd, wPath, sec);
SHELL32_FreeUnicodeBuf(wPath); SHELL32_FreeUnicodeBuf(wPath);
} }
return retCode; return retCode;
} }
@ -837,39 +868,40 @@ int WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES s
} }
else else
{ {
ret = SHNotifyCreateDirectoryW(path, sec); ret = SHNotifyCreateDirectoryW(path, sec);
/* Refuse to work on certain error codes before trying to create directories recursively */ /* Refuse to work on certain error codes before trying to create directories recursively */
if (ret != ERROR_SUCCESS && if (ret != ERROR_SUCCESS &&
ret != ERROR_FILE_EXISTS && ret != ERROR_FILE_EXISTS &&
ret != ERROR_ALREADY_EXISTS && ret != ERROR_ALREADY_EXISTS &&
ret != ERROR_FILENAME_EXCED_RANGE) ret != ERROR_FILENAME_EXCED_RANGE)
{ {
WCHAR *pEnd, *pSlash, szTemp[MAX_PATH + 1]; /* extra for PathAddBackslash() */ WCHAR *pEnd, *pSlash, szTemp[MAX_PATH + 1]; /* extra for PathAddBackslash() */
lstrcpynW(szTemp, path, MAX_PATH); lstrcpynW(szTemp, path, MAX_PATH);
pEnd = PathAddBackslashW(szTemp); pEnd = PathAddBackslashW(szTemp);
pSlash = szTemp + 3; pSlash = szTemp + 3;
while (*pSlash) while (*pSlash)
{ {
while (*pSlash && *pSlash != '\\') pSlash++; while (*pSlash && *pSlash != '\\') pSlash++;
if (*pSlash) if (*pSlash)
{ {
*pSlash = 0; /* terminate path at separator */ *pSlash = 0; /* terminate path at separator */
ret = SHNotifyCreateDirectoryW(szTemp, pSlash + 1 == pEnd ? sec : NULL); ret = SHNotifyCreateDirectoryW(szTemp, pSlash + 1 == pEnd ? sec : NULL);
} }
*pSlash++ = '\\'; /* put the separator back */ *pSlash++ = '\\'; /* put the separator back */
} }
} }
if (ret && hWnd && (ERROR_CANCELLED != ret)) if (ret && hWnd && (ERROR_CANCELLED != ret))
{ {
/* We failed and should show a dialog box */ /* We failed and should show a dialog box */
FIXME("Show system error message, creating path %s, failed with error %d\n", debugstr_w(path), ret); FIXME("Show system error message, creating path %s, failed with error %d\n", debugstr_w(path), ret);
ret = ERROR_CANCELLED; /* Error has been already presented to user (not really yet!) */ ret = ERROR_CANCELLED; /* Error has been already presented to user (not really yet!) */
} }
} }
return ret; return ret;
} }
@ -898,14 +930,14 @@ static DWORD SHFindAttrW(LPCWSTR pName, BOOL fileOnly)
TRACE("%s %d\n", debugstr_w(pName), fileOnly); TRACE("%s %d\n", debugstr_w(pName), fileOnly);
if (INVALID_HANDLE_VALUE != hFind) if (INVALID_HANDLE_VALUE != hFind)
{ {
do do
{ {
if (b_FileMask && IsAttribDir(wfd.dwFileAttributes)) if (b_FileMask && IsAttribDir(wfd.dwFileAttributes))
continue; continue;
dwAttr = wfd.dwFileAttributes; dwAttr = wfd.dwFileAttributes;
break; break;
} } while (FindNextFileW(hFind, &wfd));
while (FindNextFileW(hFind, &wfd));
FindClose(hFind); FindClose(hFind);
} }
return dwAttr; return dwAttr;
@ -927,20 +959,21 @@ static DWORD SHNameTranslate(LPWSTR* wString, LPCWSTR* pWToFrom, BOOL more)
if (aString) if (aString)
{ {
do do
{ {
size = lstrlenA(aString) + 1; size = lstrlenA(aString) + 1;
aSize += size; aSize += size;
aString += size; aString += size;
} while ((size != 1) && more); } while ((size != 1) && more);
/* The two sizes might be different in the case of multibyte chars */
size = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*pWToFrom, aSize, *wString, 0); /* The two sizes might be different in the case of multibyte chars */
if (*wString) /* only in the second loop */ size = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*pWToFrom, aSize, *wString, 0);
{ if (*wString) /* only in the second loop */
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*pWToFrom, aSize, *wString, size); {
*pWToFrom = *wString; MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*pWToFrom, aSize, *wString, size);
*wString += size; *pWToFrom = *wString;
} *wString += size;
}
} }
return size; return size;
} }
@ -970,30 +1003,30 @@ int WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
TRACE("\n"); TRACE("\n");
if (FO_DELETE == (nFileOp.wFunc & FO_MASK)) if (FO_DELETE == (nFileOp.wFunc & FO_MASK))
nFileOp.pTo = NULL; /* we need a NULL or a valid pointer for translation */ nFileOp.pTo = NULL; /* we need a NULL or a valid pointer for translation */
if (!(nFileOp.fFlags & FOF_SIMPLEPROGRESS)) if (!(nFileOp.fFlags & FOF_SIMPLEPROGRESS))
nFileOp.lpszProgressTitle = NULL; /* we need a NULL or a valid pointer for translation */ nFileOp.lpszProgressTitle = NULL; /* we need a NULL or a valid pointer for translation */
while (1) /* every loop calculate size, second translate also, if we have storage for this */ while (1) /* every loop calculate size, second translate also, if we have storage for this */
{ {
size = SHNameTranslate(&wString, &nFileOp.lpszProgressTitle, FALSE); /* no loop */ size = SHNameTranslate(&wString, &nFileOp.lpszProgressTitle, FALSE); /* no loop */
size += SHNameTranslate(&wString, &nFileOp.pFrom, TRUE); /* internal loop */ size += SHNameTranslate(&wString, &nFileOp.pFrom, TRUE); /* internal loop */
size += SHNameTranslate(&wString, &nFileOp.pTo, TRUE); /* internal loop */ size += SHNameTranslate(&wString, &nFileOp.pTo, TRUE); /* internal loop */
if (ForFree) if (ForFree)
{ {
retCode = SHFileOperationW(&nFileOp); retCode = SHFileOperationW(&nFileOp);
HeapFree(GetProcessHeap(), 0, ForFree); /* we cannot use wString, it was changed */ HeapFree(GetProcessHeap(), 0, ForFree); /* we cannot use wString, it was changed */
break; break;
} }
else else
{ {
wString = ForFree = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); wString = ForFree = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
if (ForFree) continue; if (ForFree) continue;
retCode = ERROR_OUTOFMEMORY; retCode = ERROR_OUTOFMEMORY;
nFileOp.fAnyOperationsAborted = TRUE; nFileOp.fAnyOperationsAborted = TRUE;
SetLastError(retCode); SetLastError(retCode);
return retCode; return retCode;
} }
} }
lpFileOp->hNameMappings = nFileOp.hNameMappings; lpFileOp->hNameMappings = nFileOp.hNameMappings;
@ -1063,15 +1096,22 @@ static void parse_wildcard_files(FILE_LIST *flList, LPCWSTR szFile, LPDWORD pdwL
for (res = TRUE; res; res = FindNextFileW(hFile, &wfd)) for (res = TRUE; res; res = FindNextFileW(hFile, &wfd))
{ {
if (IsDotDir(wfd.cFileName)) continue; if (IsDotDir(wfd.cFileName))
if (*pdwListIndex >= flList->num_alloc) grow_list( flList ); continue;
szFullPath = wildcard_to_file(szFile, wfd.cFileName);
if (*pdwListIndex >= flList->num_alloc)
grow_list( flList );
szFullPath = wildcard_to_file(szFile, wfd.cFileName);
file = &flList->feFiles[(*pdwListIndex)++]; file = &flList->feFiles[(*pdwListIndex)++];
add_file_to_entry(file, szFullPath); add_file_to_entry(file, szFullPath);
file->bFromWildcard = TRUE; file->bFromWildcard = TRUE;
file->attributes = wfd.dwFileAttributes; file->attributes = wfd.dwFileAttributes;
if (IsAttribDir(file->attributes)) flList->bAnyDirectories = TRUE;
HeapFree(GetProcessHeap(), 0, szFullPath); if (IsAttribDir(file->attributes))
flList->bAnyDirectories = TRUE;
HeapFree(GetProcessHeap(), 0, szFullPath);
} }
FindClose(hFile); FindClose(hFile);
@ -1180,7 +1220,8 @@ static void copy_dir_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, LPCWST
else else
lstrcpyW(szTo, szDestPath); lstrcpyW(szTo, szDestPath);
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo)) { if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
{
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FOLDER, feFrom->szFilename, op)) if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FOLDER, feFrom->szFilename, op))
{ {
/* Vista returns an ERROR_CANCELLED even if user pressed "No" */ /* Vista returns an ERROR_CANCELLED even if user pressed "No" */
@ -1367,6 +1408,7 @@ static HRESULT copy_files(FILE_OPERATION *op, const FILE_LIST *flFrom, FILE_LIST
{ {
if (!copy_file_to_file(op, entryToCopy->szFullPath, fileDest->szFullPath)) if (!copy_file_to_file(op, entryToCopy->szFullPath, fileDest->szFullPath))
{ {
DbgPrint("[shell32, copy_files] copy_file_to_file failed\n");
op->req->fAnyOperationsAborted = TRUE; op->req->fAnyOperationsAborted = TRUE;
return ERROR_CANCELLED; return ERROR_CANCELLED;
} }
@ -1671,16 +1713,16 @@ void WINAPI SHFreeNameMappings(HANDLE hNameMapping)
{ {
if (hNameMapping) if (hNameMapping)
{ {
int i = SHDSA_GetItemCount((HDSA)hNameMapping) - 1; int i = SHDSA_GetItemCount((HDSA)hNameMapping) - 1;
for (; i>= 0; i--) for (; i>= 0; i--)
{ {
LPSHNAMEMAPPINGW lp = (SHNAMEMAPPINGW *)DSA_GetItemPtr((HDSA)hNameMapping, i); LPSHNAMEMAPPINGW lp = (SHNAMEMAPPINGW *)DSA_GetItemPtr((HDSA)hNameMapping, i);
SHFree(lp->pszOldPath); SHFree(lp->pszOldPath);
SHFree(lp->pszNewPath); SHFree(lp->pszNewPath);
} }
DSA_Destroy((HDSA)hNameMapping); DSA_Destroy((HDSA)hNameMapping);
} }
} }
@ -1736,7 +1778,8 @@ EXTERN_C DWORD WINAPI SheGetDirW(DWORD drive, LPWSTR buffer)
char drv_path[3]; char drv_path[3];
/* change current directory to the specified drive */ /* change current directory to the specified drive */
if (drive) { if (drive)
{
strcpy(drv_path, "A:"); strcpy(drv_path, "A:");
drv_path[0] += (char)drive-1; drv_path[0] += (char)drive-1;