VLC – Patch to delete file from the filesystem
This patch adds a hotkey to delete the current file from the filesystem. When typing “Delete”, the next track will be played and the current file erased. On Windows, it tries to move the file to the recycle bin. If it cannot (which is pretty common, I fought, but did not understand why…) it creates a “todelete.bat
” file with the commands to delete the files (Note the encoding of this file is local windows encoding, not dos encoding. If it causes problem, try chcp 1252
at dos prompt). Just double click on it then. On other systems, it simply deletes the file (and it works )
Here is the patch, on vlc-1.0.2 :
diff -ur vlc-1.0.2/autotools/config.guess vlc-1.0.2-rp/autotools/config.guess
diff -ur vlc-1.0.2/modules/control/hotkeys.c vlc-1.0.2-rp/modules/control/hotkeys.c
--- vlc-1.0.2/modules/control/hotkeys.c 2009-09-18 18:37:45.000000000 +0200
+++ vlc-1.0.2-rp/modules/control/hotkeys.c 2009-11-15 01:18:48.000000000 +0100
@@ -41,6 +41,11 @@
#include "vlc_keys.h"
#include "math.h"
+#ifdef WIN32
+#include <shellapi.h>
+#include <windows.h>
+#endif
+
#define BUFFER_SIZE 10
#define CHANNELS_NUMBER 4
@@ -876,6 +881,102 @@
var_SetBool( p_input, "record", b_record );
}
}
+ else if( i_action == ACTIONID_DELETE_FILE )
+ {
+ // TODO : Delete file
+ input_item_t * p_input_item;
+ char * psz_dup;
+ char * psz_todelete;
+ const char *psz_access;
+ const char *psz_demux;
+ char *psz_path;
+ int ret;
+
+ p_input_item = input_GetItem( p_input );
+ psz_todelete = strdup(p_input_item->psz_uri);
+ psz_dup = strdup(psz_todelete);
+ // Code taken from input.c / InputSourceInit
+ input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup);
+ if( !strcmp( psz_access, "file" ) )
+ {
+ if( psz_path[0] != '/'
+#if (DIR_SEP_CHAR != '/')
+ /* We accept invalid URIs too. */
+ && psz_path[0] != DIR_SEP_CHAR
+#endif
+ )
+ { /* host specified -> only localhost is supported */
+ static const unsigned localhostLen = 9; /* strlen("localhost") */
+ if (!strncmp( psz_path, "localhost/", localhostLen + 1))
+ psz_path += localhostLen;
+ else
+ {
+ msg_Err( p_input, "cannot open remote file `%s://%s'",
+ psz_access, psz_path );
+ msg_Info( p_input, "Did you mean `%s:///%s'?",
+ psz_access, psz_path );
+ }
+ }
+ /* Remove HTML anchor if present (not supported). */
+ char *p = strchr( psz_path, '#' );
+ if( p )
+ *p = '0';
+ /* Then URI-decode the path. */
+ decode_URI( psz_path );
+#if defined( WIN32 ) && !defined( UNDER_CE )
+ /* Strip leading slash in front of the drive letter */
+ psz_path++;
+#endif
+#if (DIR_SEP_CHAR != '/')
+ /* Turn slashes into anti-slashes */
+ for( char *s = strchr( psz_path, '/' ); s; s = strchr( s + 1, '/' ) )
+ *s = DIR_SEP_CHAR;
+#endif
+ }
+ // End of code taken
+ playlist_Next( p_playlist );
+ msg_Info(p_input, "Delete : %s (%s)", psz_path, psz_todelete);
+ if (psz_todelete)
+ {
+#ifdef WIN32
+ wchar_t wpath[MAX_PATH+1];
+ if (!MultiByteToWideChar (CP_UTF8, 0, psz_path, -1, wpath, MAX_PATH))
+ {
+ msg_Err(p_input, "Failed conversion");
+ }
+ wpath[MAX_PATH] = L'0';
+ strcat(wpath,_T("00"));
+
+ SHFILEOPSTRUCT SHFileOp;
+ ZeroMemory(&SHFileOp, sizeof(SHFILEOPSTRUCT));
+ SHFileOp.hwnd = NULL;
+ SHFileOp.wFunc = FO_DELETE;
+ SHFileOp.pFrom = wpath;
+ SHFileOp.pTo = NULL;
+ SHFileOp.fFlags = FOF_ALLOWUNDO | FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION;
+ Sleep(500);
+ ret = SHFileOperation(&SHFileOp);
+ if(ret != 0)
+ {
+ msg_Err(p_input, "Failed ! Code : %d", ret);
+
+ FILE * fdel;
+ fdel = fopen("todelete.bat","a+");
+ fprintf(fdel,"del "%s"n", ToLocale(psz_path));
+ fclose(fdel);
+ }
+#else
+ utf8_unlink(psz_path); // remove file
+#endif
+ }
+ /*
+ if (psz_path) free (psz_path);
+ if (psz_access) free (psz_access);
+ if (psz_demux) free (psz_demux);
+ if (psz_todelete) free (psz_todelete);
+ if (psz_dup) free (psz_dup);
+ */
+ }
}
cleanup_and_continue:
if( p_aout )
diff -ur vlc-1.0.2/src/libvlc-module.c vlc-1.0.2-rp/src/libvlc-module.c
--- vlc-1.0.2/src/libvlc-module.c 2009-09-19 21:30:22.000000000 +0200
+++ vlc-1.0.2-rp/src/libvlc-module.c 2009-11-14 17:44:08.000000000 +0100
@@ -1250,6 +1250,9 @@
#define POSITION_KEY_TEXT N_("Position")
#define POSITION_KEY_LONGTEXT N_("Select the hotkey to display the position.")
+#define FILE_DELETE_KEY_TEXT N_("Delete current file on the disk")
+#define FILE_DELETE_KEY_LONGTEXT N_("Select the key to delete the current file on the disk.")
+
#define JBEXTRASHORT_KEY_TEXT N_("Very short backwards jump")
#define JBEXTRASHORT_KEY_LONGTEXT
N_("Select the hotkey to make a very short backwards jump.")
@@ -2207,6 +2210,8 @@
# define KEY_RANDOM 'r'
# define KEY_LOOP KEY_MODIFIER_SHIFT|'l'
+# define KEY_FILE_DELETE KEY_DELETE
+
# define KEY_CROP_TOP KEY_MODIFIER_ALT|'i'
# define KEY_UNCROP_TOP KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'i'
# define KEY_CROP_LEFT KEY_MODIFIER_ALT|'j'
@@ -2332,6 +2337,8 @@
# define KEY_DUMP KEY_MODIFIER_SHIFT|'d'
# define KEY_WALLPAPER 'w'
+# define KEY_FILE_DELETE KEY_DELETE
+
/* Cropping */
# define KEY_CROP_TOP KEY_MODIFIER_ALT|'r'
# define KEY_UNCROP_TOP KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|'r'
@@ -2539,6 +2546,9 @@
add_key( "key-loop", KEY_LOOP, NULL,
LOOP_KEY_TEXT, LOOP_KEY_LONGTEXT, false )
+ add_key( "key-delete-file", KEY_FILE_DELETE, NULL,
+ FILE_DELETE_KEY_TEXT, FILE_DELETE_KEY_LONGTEXT, false)
+
set_section ( N_("Zoom" ), NULL )
add_key( "key-zoom-quarter", KEY_ZOOM_QUARTER, NULL,
ZOOM_QUARTER_KEY_TEXT, NULL, false )
@@ -2825,6 +2835,7 @@
{ "key-toggle-autoscale", ACTIONID_TOGGLE_AUTOSCALE, },
{ "key-incr-scalefactor", ACTIONID_SCALE_UP, },
{ "key-decr-scalefactor", ACTIONID_SCALE_DOWN, },
+ { "key-delete-file", ACTIONID_DELETE_FILE, },
};
const size_t libvlc_actions_count =
Win32 binaries are not currenlty online, cross-compilation works quite well, or just ask.
Comments are powered by Github. You must authenticate to GitHub before commenting. Create an account if you haven't one, it only takes 1 minute!
Les commentaires sont hébergés sur GitHub. Il vous faudra vous authentifier sur GitHub pour pouvoir commenter. Si vous n'avez pas de compte, une minute suffit à en créer un !