From 3f469897b0f0bb588c342449367c65999b0a07f2 Mon Sep 17 00:00:00 2001 From: stax76 Date: Thu, 24 Mar 2022 18:32:32 +0100 Subject: [PATCH] Fix crash on Windows 7 systems without PowerShell. --- docs/Changelog.md | 6 ++-- src/Misc/CorePlayer.cs | 20 +++++++------ src/Scripts/Lua/.vscode/launch.json | 14 +++++++++ src/Scripts/Lua/delete-current-file.lua | 38 +++++++++++++++---------- 4 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 src/Scripts/Lua/.vscode/launch.json diff --git a/docs/Changelog.md b/docs/Changelog.md index 26d9be1..6cbdaf7 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,4 +1,5 @@ +- Fix crash on Windows 7 systems without PowerShell. - Fix showing incorrect timestamps in About dialog of Store version. - Fix Store page showing non existant ARM and x86 support. - Fix opening zip files. @@ -7,8 +8,9 @@ - Media Info isn't shown directly, instead the command palette shows several choices. The command palette can be bypassed using the arguments: msgbox, editor, full, raw. -- mpv.net specific commands are documented in the manual. -- The command palette and auto-play property is documented in the manual. +- mpv.net specific commands, the command palette, auto-play property + and various other things are documented in the manual. + 5.7.0.0 Stable (2022-03-09) diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index 1f8830d..eaf026b 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -232,15 +232,17 @@ namespace mpvnet if (!Directory.Exists(_ConfigFolder)) { - using (Process proc = new Process()) - { - proc.StartInfo.UseShellExecute = false; - proc.StartInfo.CreateNoWindow = true; - proc.StartInfo.FileName = "powershell.exe"; - proc.StartInfo.Arguments = $@"-Command New-Item -Path '{_ConfigFolder}' -ItemType Directory"; - proc.Start(); - proc.WaitForExit(); - } + try { + using (Process proc = new Process()) + { + proc.StartInfo.UseShellExecute = false; + proc.StartInfo.CreateNoWindow = true; + proc.StartInfo.FileName = "powershell.exe"; + proc.StartInfo.Arguments = $@"-Command New-Item -Path '{_ConfigFolder}' -ItemType Directory"; + proc.Start(); + proc.WaitForExit(); + } + } catch (Exception) {} if (!Directory.Exists(_ConfigFolder)) Directory.CreateDirectory(_ConfigFolder); diff --git a/src/Scripts/Lua/.vscode/launch.json b/src/Scripts/Lua/.vscode/launch.json new file mode 100644 index 0000000..a156dcf --- /dev/null +++ b/src/Scripts/Lua/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/src/Scripts/Lua/delete-current-file.lua b/src/Scripts/Lua/delete-current-file.lua index 5d74c4a..2bea2a8 100644 --- a/src/Scripts/Lua/delete-current-file.lua +++ b/src/Scripts/Lua/delete-current-file.lua @@ -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",