Skip to content

Commit

Permalink
Better osx support and EMCO tab change event (#26)
Browse files Browse the repository at this point in the history
* Raise event after changing tabs
* improve exists/isDir to use lfs since we have it by default. Makes it more OSX compatibile
* Add some whitespace in the raw html logs
  • Loading branch information
demonnic committed Aug 31, 2021
1 parent a02a321 commit 8a36726
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
30 changes: 23 additions & 7 deletions src/resources/demontools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@ local DemonTools = {}
local cheatConsole = Geyser.MiniConsole:new({name = "DemonnicCheatConsole", width = 4000, wrapWidth = 10000, color = "black"})
cheatConsole:hide()
local function exists(path)
local ok, err, code = os.rename(path, path)
if not ok and code == 13 then
path = path:gsub([[\]], "/")
if path:ends("/") then
path = path:sub(1,-2)
end
local ok, err, code = lfs.attributes(path)
if ok then
return true
end
return ok, err
if err:lower():find("no such file or directory") then
return false
end
return ok, err, code
end

local function isWindows()
return package.config:sub(1, 1) == [[\]]
end

local function isDir(path)
path = path:gsub("\\", "/")
if not path:ends("/") then
path = path .. "/"
if not exists(path) then return false end
path = path:gsub([[\]], "/")
if path:ends("/") then
path = path:sub(1,-2)
end
return exists(path)
local ok, err, code = lfs.attributes(path, "mode")
if ok then
if ok == "directory" then
return true
else
return false
end
end
return ok, err, code
end

local function mkdir_p(path)
Expand Down
1 change: 1 addition & 0 deletions src/resources/emco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ function EMCO:switchTab(tabName)
end
self.mc[tabName]:show()
self.currentTab = tabName
raiseEvent("EMCO tab change", self.name, oldTab, tabName)
end

function EMCO:createComponentsForTab(tabName)
Expand Down
7 changes: 5 additions & 2 deletions src/resources/loggingconsole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ end
function LoggingConsole:writeToLog(str)
local fileName = self:getFullFilename()
self:createPathIfNotExists()
if self:getExtension() == "html" and not io.exists(fileName) then
str = htmlHeader .. str
if self:getExtension() == "html" then
if not io.exists(fileName) then
str = htmlHeader .. str
end
str = str .. "\n" -- html doesn't care about the extra whitespace, but it makes the raw file much easier to read
end
local file, err = io.open(fileName, "a")
if not file then
Expand Down

0 comments on commit 8a36726

Please sign in to comment.