all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Toru TSUNEYOSHI" <t_tuneyosi@hotmail.com>
To: <emacs-devel@gnu.org>
Cc: "Lennart Borgman \(gmail\)" <lennart.borgman@gmail.com>
Subject: patch about moving file (or directory) to the Recycle Bin on Windows NT series
Date: Tue, 22 Apr 2008 02:07:56 +0900	[thread overview]
Message-ID: <BAY121-DAV43EDCEDF99B3260B8DC87E2E10@phx.gbl> (raw)
In-Reply-To: 480CC2D7.3030302@gmail.com

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

I made a patch for src/{w32.c,emacs.c} (in emacs 22.2) about moving file
(or directory) to the Recycle Bin on Windows NT series.

If possible, please patch emacs source.

[-- Attachment #2: w32.c_and_emacs.c.diff --]
[-- Type: application/octet-stream, Size: 3356 bytes --]

--- w32.c.original	2008-02-23 22:49:09.000000000 +0900
+++ w32.c	2008-04-21 22:08:48.248179300 +0900
@@ -75,6 +75,10 @@
 #include <windows.h>
 #include <shlobj.h>
 
+#ifdef MYDEF
+#include <shellapi.h>
+#endif	/* MYDEF */
+
 #ifdef HAVE_SOCKETS	/* TCP connection support, if kernel can do it */
 #include <sys/socket.h>
 #undef socket
@@ -111,6 +115,10 @@
 extern Lisp_Object Vw32_get_true_file_attributes;
 extern int w32_num_mouse_buttons;
 
+#ifdef MYDEF
+int w32_sys_unlink_use_shellapi;
+#endif	/* MYDEF */
+
 \f
 /*
   Initialization states
@@ -2240,6 +2248,71 @@
   return result;
 }
 
+#ifdef MYDEF
+
+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	/* MYDEF */
+
 int
 sys_rmdir (const char * path)
 {
@@ -2256,6 +2329,8 @@
   return _unlink (path);
 }
 
+#endif	/* MYDEF */
+
 static FILETIME utc_base_ft;
 static long double utc_base;
 static int init = 0;
@@ -4160,6 +4235,18 @@
   SetConsoleCtrlHandler(shutdown_handler, TRUE);
 }
 
+#ifdef MYDEF
+
+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 = 0;
+}
+
+#endif	/* MYDEF */
+
 /* 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-21 22:14:55.457184200 +0900
@@ -1588,6 +1588,9 @@
       syms_of_vmsproc ();
 #endif /* VMS */
 #ifdef WINDOWSNT
+#ifdef MYDEF
+      syms_of_w32 ();
+#endif	/* MYDEF */
       syms_of_ntproc ();
 #endif /* WINDOWSNT */
       syms_of_window ();

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

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-21 14:25 patch is received? Toru TSUNEYOSHI
2008-04-21 16:19 ` Drew Adams
2008-04-21 16:29   ` Toru TSUNEYOSHI
2008-04-21 16:37 ` Lennart Borgman (gmail)
2008-04-21 17:07   ` Toru TSUNEYOSHI [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-04-21 21:32 patch about moving file (or directory) to the Recycle Bin on Windows NT series Toru TSUNEYOSHI
2008-04-22  9:02 ` 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
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
2008-05-27 17:11 Toru TSUNEYOSHI
2008-05-27 18:39 ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=BAY121-DAV43EDCEDF99B3260B8DC87E2E10@phx.gbl \
    --to=t_tuneyosi@hotmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.