Winefile: fix "move file" implementation

Martin Fuchs martin-fuchs at gmx.net
Wed Oct 6 04:15:38 CDT 2004


Changelog:
fix "move file" implementation, in detail:
- use TCHAR to make the code UNICODE compatible
- pass return string buffer to the dialog procedure
- call display_error() in case of errors to display the WIN32 error message
- use slash instead of back slash for unix file system compatibility
- format the code equally to the remaining winefile code


Index: winefile.c
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.c,v
retrieving revision 1.20
diff -u -p -d -r1.20 winefile.c
--- winefile.c	27 Sep 2004 20:35:53 -0000	1.20
+++ winefile.c	6 Oct 2004 09:06:25 -0000
@@ -1543,28 +1543,38 @@ static BOOL CALLBACK ExecuteDialogWndPro
 	return 0;
 }
 
-static BOOL CALLBACK sDestinationWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
-{
-	switch(nmsg) {
-		case WM_INITDIALOG:
-			return 1;
-
-		case WM_COMMAND:{
-			int id = (int)wparam;
-			if (id == IDOK) {
-				char *dest;
-				dest = malloc(MAX_PATH);
-				GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
-				EndDialog(hwnd, (int)dest);
-			}
-			else if (id == IDCANCEL) EndDialog(hwnd, id);
-			else if (id == 254) MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
-			return 1;
-			}
-	}
-
-	return 0;
-}
+static BOOL CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
+{
+	switch(nmsg) {
+		case WM_INITDIALOG:
+			SetWindowLong(hwnd, GWL_USERDATA, lparam);
+			return 1;
+
+		case WM_COMMAND: {
+			int id = (int)wparam;
+
+			switch(id) {
+			  case IDOK: {
+				LPTSTR dest = (LPTSTR) GetWindowLong(hwnd, GWL_USERDATA);
+				GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
+				EndDialog(hwnd, id);
+				break;}
+
+			  case IDCANCEL:
+				EndDialog(hwnd, id);
+				break;
+
+			  case 254:
+				MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
+				break;
+			}
+
+			return 1;
+		}
+	}
+
+	return 0;
+}
 
 
 #ifndef _NO_EXTENSIONS
@@ -3518,38 +3528,41 @@ LRESULT CALLBACK ChildWndProc(HWND hwnd,
 					activate_entry(child, pane, hwnd);
 					break;
 
-				case ID_FILE_MOVE: {
-					char *new_name,*old_name;
-					int len;
-					if((int)(new_name=(char *)DialogBox(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, sDestinationWndProc))==1|| (int)new_name==IDCANCEL) break;
-					old_name = malloc(MAX_PATH);
-					if(new_name[1]!=':' && new_name[0]!='/') {
-						get_path(pane->cur->up, old_name);
-						len = strlen(old_name);
-						if(old_name[len-1]!='\\') {
-							old_name[len]='\\';
-							len++;
-							old_name[len]='\n';
-						}
-						strcpy(&old_name[len], new_name);
-						strcpy(new_name, old_name);
-					}
-					get_path(pane->cur, old_name);
-					if(MoveFileEx(old_name,new_name,MOVEFILE_COPY_ALLOWED)) {
-						if(pane->treePane) {
-							pane->root->scanned=FALSE;
-							pane->cur=pane->root;
-							activate_entry(child, pane, hwnd);
-						}
-						else scan_entry(child, pane->root, hwnd);
-					}
-					else {
-						LoadString(Globals.hInstance, IDS_FILE_MOVE_ERROR, old_name, MAX_PATH);
-						MessageBox(hwnd, old_name, "WineFile", MB_OK);
-					}
-					free(old_name);
-					free(new_name);
-					break;}
+				case ID_FILE_MOVE: {
+					TCHAR new_name[BUFFER_LEN], old_name[BUFFER_LEN];
+					int len;
+
+					int ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, DestinationDlgProc, (LPARAM)new_name);
+					if (ret != IDOK)
+						break;
+
+					if (new_name[0]!='/' && new_name[1]!=':') {
+						get_path(pane->cur->up, old_name);
+						len = lstrlen(old_name);
+
+						if (old_name[len-1]!='\\' && old_name[len-1]!='/') {
+							old_name[len++] = '/';
+							old_name[len] = '\n';
+						}
+
+						lstrcpy(&old_name[len], new_name);
+						lstrcpy(new_name, old_name);
+					}
+
+					get_path(pane->cur, old_name);
+
+					if (MoveFileEx(old_name, new_name, MOVEFILE_COPY_ALLOWED)) {
+						if (pane->treePane) {
+							pane->root->scanned = FALSE;
+							pane->cur = pane->root;
+							activate_entry(child, pane, hwnd);
+						}
+						else
+							scan_entry(child, pane->root, hwnd);
+					}
+					else
+						display_error(hwnd, GetLastError());
+					break;}
 
 				default:
 					return pane_command(pane, LOWORD(wparam));





More information about the wine-patches mailing list