Skip to content

Commit

Permalink
Fix crash when toggle on read-only media
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Dec 27, 2021
1 parent 9f07660 commit da064c5
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions AnimeAnyK.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function getIndicatorFileStatus_jbgyampcwu()
end
end

-- Video loaded event
function videoLoadedEvent_jbgyampcwu(event)
-- Send Anime4K command to mpv
function sendAnime4kCommand_jbgyampcwu()
--
-- BEGIN User input
--
Expand Down Expand Up @@ -74,22 +74,6 @@ function videoLoadedEvent_jbgyampcwu(event)



--
-- BEGIN Check indicator file
--

local indicatorFileExist, _ = getIndicatorFileStatus_jbgyampcwu()
if indicatorFileExist == false
then
return
end

--
-- END Check indicator file
--



--
-- BEGIN Anime4K Command
--
Expand Down Expand Up @@ -236,6 +220,17 @@ function videoLoadedEvent_jbgyampcwu(event)
--
end

-- Video loaded event
function videoLoadedEvent_jbgyampcwu(event)
local indicatorFileExist, _ = getIndicatorFileStatus_jbgyampcwu()
if indicatorFileExist == false
then
return
else
sendAnime4kCommand_jbgyampcwu()
end
end

-- Toggle on/off event
function inputCommandEvent_jbgyampcwu()
-- Get indicator file status
Expand All @@ -245,13 +240,15 @@ function inputCommandEvent_jbgyampcwu()
then
-- Create file
local file_object = io.open(indicatorFileFullPath, 'a')
file_object:close();

-- Ignore possible close error (happens on read only file system)
local closeResult, err = pcall(function () file_object:close() end)

-- Trigger scripted Anime4K
videoLoadedEvent_jbgyampcwu()
sendAnime4kCommand_jbgyampcwu()
else
-- Delete exist file
os.remove(indicatorFileFullPath)
-- Delete exist file, ignore possible delete error (happens on read only file system)
local deleteResult, err = pcall(function () os.remove(indicatorFileFullPath) end)

-- Clear glsl
mp.command("no-osd change-list glsl-shaders clr \"\"; show-text \"GLSL shaders cleared\"")
Expand Down

0 comments on commit da064c5

Please sign in to comment.