winefile: copy and delete

Martin Fuchs martin-fuchs at gmx.net
Sun May 29 16:31:24 CDT 2005


Changelog:
- implement commands 'copy' and 'delete'
- fix 'move' command for the left pane


Index: winefile.c
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.c,v
retrieving revision 1.45
diff -u -p -d -r1.45 winefile.c
--- winefile.c	29 May 2005 20:17:05 -0000	1.45
+++ winefile.c	29 May 2005 21:26:39 -0000
@@ -3747,6 +3747,55 @@ static void update_view_menu(ChildWnd* c
 }
 
 
+static BOOL is_directory(LPCTSTR target)
+{
+	/*TODO correctly handle UNIX paths */
+	DWORD target_attr = GetFileAttributes(target);
+
+	if (target_attr == INVALID_FILE_ATTRIBUTES)
+		return FALSE;
+
+	return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
+}
+	
+static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
+{
+	TCHAR path[MAX_PATH];
+	int len;
+
+	get_path(pane->cur, path);
+
+	if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
+		return FALSE;
+
+	get_path(pane->cur, source);
+
+	/* convert relative targets to absolute paths */
+	if (path[0]!='/' && path[1]!=':') {
+		get_path(pane->cur->up, target);
+		len = lstrlen(target);
+
+		if (target[len-1]!='\\' && target[len-1]!='/')
+			target[len++] = '/';
+
+		lstrcpy(target+len, path);
+	} else
+		lstrcpy(target, path);
+
+	/* If the target already exists as directory, create a new target below this. */
+	if (is_directory(path)) {
+		TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
+		const static TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
+
+		_tsplitpath(source, NULL, NULL, fname, ext);
+
+		wsprintf(target, sAppend, path, fname, ext);
+	}
+
+	return TRUE;
+}
+
+
 static IContextMenu2* s_pctxmenu2 = NULL;
 static IContextMenu3* s_pctxmenu3 = NULL;
 
@@ -4023,39 +4072,43 @@ LRESULT CALLBACK ChildWndProc(HWND hwnd,
 					break;
 
 				case ID_FILE_MOVE: {
-					TCHAR new_name[BUFFER_LEN], old_name[BUFFER_LEN];
-					int len, ret;
+					TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
 
-					get_path(pane->cur, new_name);
+					if (prompt_target(pane, source, target)) {
+						SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
 
-					ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, DestinationDlgProc, (LPARAM)new_name);
-					if (ret != IDOK)
-						break;
+						source[lstrlen(source)+1] = '\0';
+						target[lstrlen(target)+1] = '\0';
 
-					if (new_name[0]!='/' && new_name[1]!=':') {
-						get_path(pane->cur->up, old_name);
-						len = lstrlen(old_name);
+						if (!SHFileOperation(&shfo))
+							refresh_child(child);
+					}
+					break;}
 
-						if (old_name[len-1]!='\\' && old_name[len-1]!='/')
-							old_name[len++] = '/';
+				case ID_FILE_COPY: {
+					TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
 
-						lstrcpy(old_name+len, new_name);
-						lstrcpy(new_name, old_name);
-					}
+					if (prompt_target(pane, source, target)) {
+						SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
 
-					get_path(pane->cur, old_name);
+						source[lstrlen(source)+1] = '\0';
+						target[lstrlen(target)+1] = '\0';
 
-					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
+						if (!SHFileOperation(&shfo))
 							refresh_child(child);
 					}
-					else
-						display_error(hwnd, GetLastError());
+					break;}
+
+				case ID_FILE_DELETE: {
+					TCHAR path[BUFFER_LEN];
+					SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
+
+					get_path(pane->cur, path);
+
+					path[lstrlen(path)+1] = '\0';
+
+					if (!SHFileOperation(&shfo))
+						refresh_child(child);
 					break;}
 
 				case ID_VIEW_SORT_NAME:
Index: resource.h
===================================================================
RCS file: /home/wine/wine/programs/winefile/resource.h,v
retrieving revision 1.14
diff -u -p -d -r1.14 resource.h
--- resource.h	29 May 2005 20:05:29 -0000	1.14
+++ resource.h	29 May 2005 21:26:37 -0000
@@ -41,6 +41,8 @@
 #define	ID_ACTIVATE					101
 #define	ID_EXECUTE					105
 #define ID_FILE_MOVE					106
+#define	ID_FILE_COPY					107
+#define	ID_FILE_DELETE					108
 #define	ID_FILE_EXIT					115
 #define	ID_FORMAT_DISK					203
 #define	ID_CONNECT_NETWORK_DRIVE			252
Index: resource.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/resource.rc,v
retrieving revision 1.5
diff -u -p -d -r1.5 resource.rc
--- resource.rc	14 May 2005 18:50:30 -0000	1.5
+++ resource.rc	29 May 2005 21:26:37 -0000
@@ -21,6 +21,8 @@ IDA_WINEFILE ACCELERATORS DISCARDABLE
 	VK_F1, ID_HELP, VIRTKEY, NOINVERT
 	VK_F5, ID_REFRESH, VIRTKEY, NOINVERT
 	VK_F7, ID_FILE_MOVE, VIRTKEY, NOINVERT
+	VK_F8, ID_FILE_COPY, VIRTKEY, NOINVERT
+	VK_DELETE, ID_FILE_DELETE, VIRTKEY, NOINVERT
 	VK_RETURN, ID_ACTIVATE, VIRTKEY, NOINVERT
 #ifndef _NO_EXTENSIONS
 	"X", ID_FILE_EXIT, VIRTKEY, ALT, NOINVERT
Index: Cs.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Cs.rc,v
retrieving revision 1.6
diff -u -p -d -r1.6 Cs.rc
--- Cs.rc	29 May 2005 20:05:29 -0000	1.6
+++ Cs.rc	29 May 2005 21:26:36 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Soubor"  {
 		MENUITEM "&Otevøít\tEnter" ,			ID_ACTIVATE
 		MENUITEM "Pøe&sunout...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Kopírovat...\tF8" ,			107
+		MENUITEM "&Kopírovat...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&Do schránky...\tF9" ,		118
-		MENUITEM "&Smazat\tDel" ,			108
+		MENUITEM "&Smazat\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Pøejme&novat..." ,			109
 		MENUITEM "Vlastnost&i...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: De.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/De.rc,v
retrieving revision 1.12
diff -u -p -d -r1.12 De.rc
--- De.rc	29 May 2005 20:05:29 -0000	1.12
+++ De.rc	29 May 2005 21:26:36 -0000
@@ -30,9 +30,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Datei"  {
 		MENUITEM "Ö&ffnen\tEingabetaste" ,		ID_ACTIVATE
 		MENUITEM "&Verschieben...\tF7" , 		ID_FILE_MOVE
-		MENUITEM "&Kopieren...\tF8" ,			107
+		MENUITEM "&Kopieren...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&In Zwischenablage...\tF9" ,		118
-		MENUITEM "&Löschen\tEntf" ,			108
+		MENUITEM "&Löschen\tEntf" ,			ID_FILE_DELETE
 		MENUITEM "&Umbenennen..." ,			109
 		MENUITEM "&Eigenschaften...\tAlt+Eingabetaste" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: En.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/En.rc,v
retrieving revision 1.17
diff -u -p -d -r1.17 En.rc
--- En.rc	29 May 2005 20:05:29 -0000	1.17
+++ En.rc	29 May 2005 21:26:36 -0000
@@ -30,9 +30,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&File"  {
 		MENUITEM "&Open\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Move...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copy...\tF8" ,			107
+		MENUITEM "&Copy...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&In Clipboard...\tF9" ,		118
-		MENUITEM "&Delete\tDel" ,			108
+		MENUITEM "&Delete\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Re&name..." ,			109
 		MENUITEM "Propert&ies...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Es.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Es.rc,v
retrieving revision 1.10
diff -u -p -d -r1.10 Es.rc
--- Es.rc	29 May 2005 20:05:29 -0000	1.10
+++ Es.rc	29 May 2005 21:26:36 -0000
@@ -28,9 +28,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Archivo"  {
 		MENUITEM "&Abrir\tEnter" ,			ID_ACTIVATE
 		MENUITEM "Mo&ver...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copiar...\tF8" ,			107
+		MENUITEM "&Copiar...\tF8" ,			ID_FILE_COPY
 		MENUITEM "E&n portapapeles...\tF9" ,		118
-		MENUITEM "&Eliminar\tDel" ,			108
+		MENUITEM "&Eliminar\tDel" ,			ID_FILE_DELETE
 		MENUITEM "&Renombrar..." ,			109
 		MENUITEM "&Propiedades...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Fr.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Fr.rc,v
retrieving revision 1.10
diff -u -p -d -r1.10 Fr.rc
--- Fr.rc	29 May 2005 20:05:29 -0000	1.10
+++ Fr.rc	29 May 2005 21:26:36 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Fichier"  {
 		MENUITEM "&Ouvrir\tEntrée" ,			ID_ACTIVATE
 		MENUITEM "&Déplacer...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copier...\tF8" ,			107
+		MENUITEM "&Copier...\tF8" ,			ID_FILE_COPY
 		MENUITEM "P&resse-Papiers...\tF9" ,		118
-		MENUITEM "&Effacer\tDel" ,			108
+		MENUITEM "&Effacer\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Re&nommer..." ,			109
 		MENUITEM "&Propriétés...\tAlt+Entree" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Hu.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Hu.rc,v
retrieving revision 1.8
diff -u -p -d -r1.8 Hu.rc
--- Hu.rc	29 May 2005 20:05:29 -0000	1.8
+++ Hu.rc	29 May 2005 21:26:37 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Fájl"  {
 		MENUITEM "&Megynitás\tEnter" ,			ID_ACTIVATE
 		MENUITEM "Át&helyezés...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Másolás...\tF8" ,			107
+		MENUITEM "&Másolás...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&Vágólapon...\tF9" ,		118
-		MENUITEM "&Törlés\tDel" ,			108
+		MENUITEM "&Törlés\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Át&nevezés..." ,			109
 		MENUITEM "T&ulajdonságok...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: It.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/It.rc,v
retrieving revision 1.11
diff -u -p -d -r1.11 It.rc
--- It.rc	29 May 2005 20:05:29 -0000	1.11
+++ It.rc	29 May 2005 21:26:37 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&File"  {
 		MENUITEM "&Apri\tInvio" ,			ID_ACTIVATE
 		MENUITEM "&Sposta...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copia...\tF8" ,			107
+		MENUITEM "&Copia...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&Negli Appunti...\tF9" ,		118
-		MENUITEM "&Cancella\tDel" ,			108
+		MENUITEM "&Cancella\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Ri&nomina..." ,			109
 		MENUITEM "Propri&età...\tAlt+Invio" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Nl.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Nl.rc,v
retrieving revision 1.8
diff -u -p -d -r1.8 Nl.rc
--- Nl.rc	29 May 2005 20:05:29 -0000	1.8
+++ Nl.rc	29 May 2005 21:26:37 -0000
@@ -27,9 +27,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Bestand"  {
 		MENUITEM "&Openen\tEnter" ,               ID_ACTIVATE
 		MENUITEM "&Verplaatsen...\tF7" ,          ID_FILE_MOVE
-		MENUITEM "&Kopiëren...\tF8" ,             107
+		MENUITEM "&Kopiëren...\tF8" ,             ID_FILE_COPY
 		MENUITEM "Naar &klembord...\tF9" ,        118
-		MENUITEM "Ver&wijderen\tDel" ,            108
+		MENUITEM "Ver&wijderen\tDel" ,            ID_FILE_DELETE
 		MENUITEM "&Naam wijzigen..." ,            109
 		MENUITEM "&Eigenschappen...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Pl.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Pl.rc,v
retrieving revision 1.9
diff -u -p -d -r1.9 Pl.rc
--- Pl.rc	29 May 2005 20:05:29 -0000	1.9
+++ Pl.rc	29 May 2005 21:26:37 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Plik"  {
 		MENUITEM "&Otwórz\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Przenieœ...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Kopiuj...\tF8" ,			107
+		MENUITEM "&Kopiuj...\tF8" ,			ID_FILE_COPY
 		MENUITEM "W s&chowku...\tF9" ,		118
-		MENUITEM "&Usuñ\tDel" ,			108
+		MENUITEM "&Usuñ\tDel" ,			ID_FILE_DELETE
 		MENUITEM "&Zmieñ nazwê..." ,			109
 		MENUITEM "Ustawie&nia...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Pt.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Pt.rc,v
retrieving revision 1.10
diff -u -p -d -r1.10 Pt.rc
--- Pt.rc	29 May 2005 20:05:29 -0000	1.10
+++ Pt.rc	29 May 2005 21:26:37 -0000
@@ -30,9 +30,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Arquivo"  {
 		MENUITEM "A&brir\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Mover...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copiar...\tF8" ,			107
+		MENUITEM "&Copiar...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&In Clipboard...\tF9" ,		118
-		MENUITEM "E&xcluir\tDel" ,			108
+		MENUITEM "E&xcluir\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Re&nomear..." ,			109
 		MENUITEM "&Propriedades...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
@@ -157,9 +157,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Ficheiro"  {
 		MENUITEM "A&brir\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Mover...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copiar...\tF8" ,			107
+		MENUITEM "&Copiar...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&Na Area de Transferencia...\tF9" ,		118
-		MENUITEM "E&xcluir\tDel" ,			108
+		MENUITEM "E&xcluir\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Re&nomear..." ,			109
 		MENUITEM "&Propriedades...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Ru.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Ru.rc,v
retrieving revision 1.8
diff -u -p -d -r1.8 Ru.rc
--- Ru.rc	29 May 2005 20:05:29 -0000	1.8
+++ Ru.rc	29 May 2005 21:26:37 -0000
@@ -27,9 +27,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Ôàéë"  {
 		MENUITEM "&Îòêðûòü\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Ïåðåìåñòèòü...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Êîïèðîâàòü...\tF8" ,			107
+		MENUITEM "&Êîïèðîâàòü...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&Â áóôåð îáìåíà...\tF9" ,		118
-		MENUITEM "&Óäàëèòü\tDel" ,			108
+		MENUITEM "&Óäàëèòü\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Ïåðåèìåíîâàòü..." ,			109
 		MENUITEM "Ñâîéñòâà...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Si.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Si.rc,v
retrieving revision 1.8
diff -u -p -d -r1.8 Si.rc
--- Si.rc	29 May 2005 20:05:29 -0000	1.8
+++ Si.rc	29 May 2005 21:26:37 -0000
@@ -28,9 +28,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&File"  {
 		MENUITEM "&Open\tEnter" ,			ID_ACTIVATE
 		MENUITEM "&Move...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "&Copy...\tF8" ,			107
+		MENUITEM "&Copy...\tF8" ,			ID_FILE_COPY
 		MENUITEM "&In Clipboard...\tF9" ,		118
-		MENUITEM "&Delete\tDel" ,			108
+		MENUITEM "&Delete\tDel" ,			ID_FILE_DELETE
 		MENUITEM "Re&name..." ,			109
 		MENUITEM "Propert&ies...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR
Index: Sv.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Sv.rc,v
retrieving revision 1.4
diff -u -p -d -r1.4 Sv.rc
--- Sv.rc	29 May 2005 20:05:29 -0000	1.4
+++ Sv.rc	29 May 2005 21:26:37 -0000
@@ -31,9 +31,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "&Arkiv"  {
         MENUITEM "&Öppna\tEnter",                ID_ACTIVATE
         MENUITEM "&Flytta...\tF7",                ID_FILE_MOVE
-        MENUITEM "&Kopiera...\tF8",                107
+        MENUITEM "&Kopiera...\tF8",                ID_FILE_COPY
         MENUITEM "&I urklipp...\tF9",        118
-        MENUITEM "&Ta bort\tDel",                108
+        MENUITEM "&Ta bort\tDel",                ID_FILE_DELETE
         MENUITEM "&Byt namn...",                  109
         MENUITEM "&Egenskaper...\tAlt+Enter",   ID_EDIT_PROPERTIES
         MENUITEM SEPARATOR
Index: Zh.rc
===================================================================
RCS file: /home/wine/wine/programs/winefile/Zh.rc,v
retrieving revision 1.8
diff -u -p -d -r1.8 Zh.rc
--- Zh.rc	29 May 2005 20:05:29 -0000	1.8
+++ Zh.rc	29 May 2005 21:26:37 -0000
@@ -28,9 +28,9 @@ IDM_WINEFILE MENU FIXED IMPURE
 	POPUP "Îļþ£¨&F£©"  {
 		MENUITEM "´ò¿ª£¨&O£©\tEnter" ,			ID_ACTIVATE
 		MENUITEM "Òƶ¯£¨&M£©...\tF7" , 			ID_FILE_MOVE
-		MENUITEM "¸´ÖÆ£¨&C£©...\tF8" ,			107
+		MENUITEM "¸´ÖÆ£¨&C£©...\tF8" ,			ID_FILE_COPY
 		MENUITEM "λÓÚ¼ôÌù°å£¨&I£©...\tF9" ,		118
-		MENUITEM "ɾ³ý£¨&D£©\tDel" ,			108
+		MENUITEM "ɾ³ý£¨&D£©\tDel" ,			ID_FILE_DELETE
 		MENUITEM "¸ÄÃû£¨&N£©..." ,			109
 		MENUITEM "ÊôÐÔ£¨&I£©...\tAlt+Enter" , ID_EDIT_PROPERTIES
 		MENUITEM SEPARATOR





More information about the wine-patches mailing list