Fix crash on Windows 7 systems without PowerShell.
This commit is contained in:
14
src/Scripts/Lua/.vscode/launch.json
vendored
Normal file
14
src/Scripts/Lua/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lua",
|
||||
"request": "launch",
|
||||
"name": "launch",
|
||||
"runtimeExecutable": "D:/Software/Development/MSYS2/mingw64/bin/mpv.exe",
|
||||
"runtimeArgs": ["--script=${workspaceFolder}\\delete-current-file.lua", "D:\\Samples\\castele.m2v"],
|
||||
"stopOnEntry": false,
|
||||
"luaVersion": "5.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
|
||||
-- This script deletes the file that is currently playing.
|
||||
-- Only supported on Windows.
|
||||
|
||||
-- This script deletes the file that is currently playing
|
||||
-- via keyboard shortcut, the file is moved to the recycle bin.
|
||||
|
||||
-- Usage:
|
||||
-- Configure input.conf as described below.
|
||||
-- Press 0 to initiate the delete operation.
|
||||
-- Press 1 to confirm and delete.
|
||||
|
||||
-- input.conf:
|
||||
|
||||
@@ -10,30 +18,30 @@
|
||||
-- 1 script-binding delete_current_file/confirm
|
||||
|
||||
function delete()
|
||||
FileToDelete = mp.get_property("path")
|
||||
DeleteTime = os.time()
|
||||
file_to_delete = mp.get_property("path")
|
||||
delete_time = os.time()
|
||||
mp.commandv("show-text", "Press 1 to delete file", "10000")
|
||||
end
|
||||
|
||||
function confirm()
|
||||
local path = mp.get_property("path")
|
||||
|
||||
if FileToDelete == path and (os.time() - DeleteTime) < 10 then
|
||||
if file_to_delete == path and (os.time() - delete_time) < 10 then
|
||||
mp.commandv("show-text", "")
|
||||
|
||||
local count = mp.get_property_number("playlist-count")
|
||||
local pos = mp.get_property_number("playlist-pos")
|
||||
local newPos = 0
|
||||
local pos = mp.get_property_number("playlist-pos")
|
||||
local new_pos = 0
|
||||
|
||||
if pos == count - 1 then
|
||||
newPos = pos - 1
|
||||
new_pos = pos - 1
|
||||
else
|
||||
newPos = pos + 1
|
||||
new_pos = pos + 1
|
||||
end
|
||||
|
||||
if newPos > -1 then
|
||||
if new_pos > -1 then
|
||||
mp.command("set pause no")
|
||||
mp.set_property_number("playlist-pos", newPos)
|
||||
mp.set_property_number("playlist-pos", new_pos)
|
||||
end
|
||||
|
||||
mp.command("playlist-remove " .. pos)
|
||||
@@ -41,13 +49,13 @@ function confirm()
|
||||
local ps_code = [[& {
|
||||
Start-Sleep -Seconds 2
|
||||
Add-Type -AssemblyName Microsoft.VisualBasic
|
||||
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('FileToDelete', 'OnlyErrorDialogs', 'SendToRecycleBin')
|
||||
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('file_to_delete', 'OnlyErrorDialogs', 'SendToRecycleBin')
|
||||
}]]
|
||||
|
||||
local escapedFileToDelete = string.gsub(FileToDelete, "'", "''")
|
||||
escapedFileToDelete = string.gsub(escapedFileToDelete, "’", "’’")
|
||||
escapedFileToDelete = string.gsub(escapedFileToDelete, "%%", "%%%%")
|
||||
ps_code = string.gsub(ps_code, "FileToDelete", escapedFileToDelete)
|
||||
local escaped_file_to_delete = string.gsub(file_to_delete, "'", "''")
|
||||
escaped_file_to_delete = string.gsub(escaped_file_to_delete, "’", "’’")
|
||||
escaped_file_to_delete = string.gsub(escaped_file_to_delete, "%%", "%%%%")
|
||||
ps_code = string.gsub(ps_code, "file_to_delete", escaped_file_to_delete)
|
||||
|
||||
mp.command_native({
|
||||
name = "subprocess",
|
||||
|
||||
Reference in New Issue
Block a user