local _rf = readfile local _wf = writefile local _iff = isfile local _df = delfile local dotBad = false local function stripExt(p) if type(p) ~= "string" then return p end return (p:gsub("([^/]+)%.[^/]+$", "%1")) end local function isInvalidPathErr(e) return type(e) == "string" and e:find("Invalid path", 1, true) ~= nil end if type(_wf) == "function" then getgenv().writefile = function(p, data, ...) if type(p) ~= "string" then return _wf(p, data, ...) end local pNoExt = stripExt(p) local ok, err = pcall(_wf, p, data, ...) if ok then dotBad = false return end if pNoExt ~= p and isInvalidPathErr(err) then local ok2, err2 = pcall(_wf, pNoExt, data, ...) if ok2 then dotBad = true return end error(err2 or err) end error(err) end end if type(_rf) == "function" then getgenv().readfile = function(p, ...) if type(p) ~= "string" then return _rf(p, ...) end local pNoExt = stripExt(p) local ok, res = pcall(_rf, p, ...) if ok and res ~= nil then dotBad = false return res end if pNoExt ~= p then local ok2, res2 = pcall(_rf, pNoExt, ...) if ok2 then dotBad = true return res2 end end return nil end end if type(_iff) == "function" then getgenv().isfile = function(p, ...) if type(p) ~= "string" then local ok, res = pcall(_iff, p, ...) return ok and res or false end local pNoExt = stripExt(p) local ok, res = pcall(_iff, p, ...) if ok and res then return true end if pNoExt ~= p then local ok2, res2 = pcall(_iff, pNoExt, ...) if ok2 and res2 then dotBad = true return true end end return false end end if type(_df) == "function" then getgenv().delfile = function(p, ...) if type(p) ~= "string" then return _df(p, ...) end local pNoExt = stripExt(p) local ok, err = pcall(_df, p, ...) if ok then dotBad = false return end if pNoExt ~= p and isInvalidPathErr(err) then local ok2, err2 = pcall(_df, pNoExt, ...) if ok2 then dotBad = true return end error(err2 or err) end error(err) end end