unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Toru TSUNEYOSHI" <t_tuneyosi@hotmail.com>
To: <emacs-devel@gnu.org>
Subject: Re: patch about moving file (or directory) to the Recycle Bin on Windows NT series
Date: Tue, 22 Apr 2008 06:32:12 +0900	[thread overview]
Message-ID: <BAY121-DAV7DE6B9E705C69F9DBCF13E2E10@phx.gbl> (raw)

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

I made a revised edition (including w32.h).

[-- Attachment #2: w32.h_w32.c_emacs.c.diff --]
[-- Type: application/octet-stream, Size: 4326 bytes --]

--- w32.h.original	2008-01-10 21:16:16.000000000 +0900
+++ w32.h	2008-04-22 05:52:24.056379500 +0900
@@ -129,6 +129,9 @@
 
 extern void init_ntproc (void);
 extern void term_ntproc (void);
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+extern void syms_of_w32 (void);
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
 extern void globals_of_w32 (void);
 extern void syms_of_w32term (void);
 extern void syms_of_w32fns (void);
--- w32.c.original	2008-02-23 22:49:09.000000000 +0900
+++ w32.c	2008-04-22 05:51:43.056197700 +0900
@@ -75,6 +75,10 @@
 #include <windows.h>
 #include <shlobj.h>
 
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+#include <shellapi.h>
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
+
 #ifdef HAVE_SOCKETS	/* TCP connection support, if kernel can do it */
 #include <sys/socket.h>
 #undef socket
@@ -104,6 +108,9 @@
 typedef HRESULT (WINAPI * ShGetFolderPath_fn)
   (IN HWND, IN int, IN HANDLE, IN DWORD, OUT char *);
 
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+void syms_of_w32 ();
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
 void globals_of_w32 ();
 
 extern Lisp_Object Vw32_downcase_file_names;
@@ -111,6 +118,10 @@
 extern Lisp_Object Vw32_get_true_file_attributes;
 extern int w32_num_mouse_buttons;
 
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+int w32_sys_unlink_use_shellapi;
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
+
 \f
 /*
   Initialization states
@@ -2240,6 +2251,71 @@
   return result;
 }
 
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+
+int
+sys_rmdir (const char * path)
+{
+  if (w32_sys_unlink_use_shellapi)
+    return (sys_unlink ((const char *)path));
+  else
+    return _rmdir (map_w32_filename (path, NULL));
+}
+
+int
+sys_unlink (const char * path)
+{
+  if (w32_sys_unlink_use_shellapi)
+    {
+      /* Each file name must be terminated by a single NULL
+	 character. An additional NULL character must be appended to the
+	 end of the final name to indicate the end of pFrom. */
+      TCHAR tmp_path[MAX_PATH + 1 + 1];
+      SHFILEOPSTRUCT stFileOp;
+
+      path = map_w32_filename (path, NULL);
+
+      /* On Unix, unlink works without write permission. */
+      _chmod (path, 0666);
+
+#if 0
+      *(tmp_path + lstrlen(tmp_path) + 1) = '\0';
+#else
+      ZeroMemory(tmp_path, sizeof(tmp_path));
+#endif
+      lstrcpy(tmp_path, path);
+
+      ZeroMemory(&stFileOp, sizeof(SHFILEOPSTRUCT));
+      stFileOp.hwnd = HWND_DESKTOP;
+      stFileOp.wFunc = FO_DELETE;
+      stFileOp.pFrom = tmp_path;
+      stFileOp.pTo = NULL;
+      stFileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;
+      stFileOp.fAnyOperationsAborted = FALSE;
+      stFileOp.hNameMappings = NULL;
+      stFileOp.lpszProgressTitle = NULL;
+
+#if 0
+      SHFileOperation(&stFileOp);
+
+      return (stFileOp.fAnyOperationsAborted);
+#else
+      /* value returned by SHFileOperation() must match value returned by _unlink() */
+      return (SHFileOperation(&stFileOp) == 0 ? 0 : -1);
+#endif
+    }
+  else
+    {
+      path = map_w32_filename (path, NULL);
+
+      /* On Unix, unlink works without write permission. */
+      _chmod (path, 0666);
+      return _unlink (path);
+    }
+}
+
+#else /* W32_SYS_UNLINK_USE_SHELLAPI */
+
 int
 sys_rmdir (const char * path)
 {
@@ -2256,6 +2332,8 @@
   return _unlink (path);
 }
 
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
+
 static FILETIME utc_base_ft;
 static long double utc_base;
 static int init = 0;
@@ -4160,6 +4238,18 @@
   SetConsoleCtrlHandler(shutdown_handler, TRUE);
 }
 
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+
+void
+syms_of_w32 ()
+{
+  DEFVAR_BOOL ("w32-sys-unlink-use-shellapi", &w32_sys_unlink_use_shellapi,
+	       "Non-nil means using shellapi for sys_unlink(), sys_rmdir().");
+  w32_sys_unlink_use_shellapi = 1;
+}
+
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
+
 /* end of w32.c */
 
 /* arch-tag: 90442dd3-37be-482b-b272-ac752e3049f1
--- emacs.c.original	2008-01-10 21:16:14.000000000 +0900
+++ emacs.c	2008-04-22 05:49:48.407912100 +0900
@@ -1588,6 +1588,9 @@
       syms_of_vmsproc ();
 #endif /* VMS */
 #ifdef WINDOWSNT
+#ifdef W32_SYS_UNLINK_USE_SHELLAPI
+      syms_of_w32 ();
+#endif /* W32_SYS_UNLINK_USE_SHELLAPI */
       syms_of_ntproc ();
 #endif /* WINDOWSNT */
       syms_of_window ();

             reply	other threads:[~2008-04-21 21:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-21 21:32 Toru TSUNEYOSHI [this message]
2008-04-22  9:02 ` patch about moving file (or directory) to the Recycle Bin on Windows NT series Toru TSUNEYOSHI
2008-04-22 15:47   ` Stefan Monnier
2008-04-22 17:04     ` Eli Zaretskii
2008-04-22 18:24       ` Eli Zaretskii
2008-04-22 18:19 ` Eli Zaretskii
2008-04-22 20:58   ` Jason Rumney
2008-04-23  1:15     ` Stefan Monnier
2008-04-23  1:14   ` Stefan Monnier
2008-04-23  4:55     ` Eli Zaretskii
2008-04-23 16:45   ` Toru TSUNEYOSHI
2008-04-23 15:35 ` Stefan Monnier
2008-04-25 20:18   ` Toru TSUNEYOSHI
  -- strict thread matches above, loose matches on Subject: below --
2008-05-27 17:11 Toru TSUNEYOSHI
2008-05-27 18:39 ` Stefan Monnier
2008-04-25 21:10 Toru TSUNEYOSHI
2008-04-26  7:25 ` Eli Zaretskii
2008-04-30 15:00   ` Toru TSUNEYOSHI
2008-05-15 17:36     ` Stefan Monnier
2008-05-25  0:07   ` Toru TSUNEYOSHI
2008-05-25  1:24 ` Stefan Monnier
2008-05-25  9:59   ` Jason Rumney
2008-05-25 11:22     ` Stefan Monnier
     [not found] <BAY121-DAV73ED6DDCDAB11014BA9E6E2E10@phx.gbl>
     [not found] ` <480CC2D7.3030302@gmail.com>
2008-04-21 17:07   ` Toru TSUNEYOSHI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY121-DAV7DE6B9E705C69F9DBCF13E2E10@phx.gbl \
    --to=t_tuneyosi@hotmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).