Skip to content

Commit

Permalink
Add command to launch CCEmuX
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidDev committed Jun 27, 2021
1 parent be76478 commit b99e302
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions etc/ccemux.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env lua

local function find_latest(dir)
local launcher = io.open(dir .. "/launcher.properties", "r")
if not launcher then return nil, "Cannot find CCEmuX" end

local info = {}
for line in launcher:lines() do
local k, v = line:match("^([^=]+)=(.*)$")
if k then info[k] = v end
end
launcher:close()

if not info.version or not info.build then return nil, "Cannot find CCEmuX version" end
return ("%s/versions/%s/CCEmuX-%s.jar"):format(dir, info.version, info.build)
end

local function guess_path()
local appdata = os.getenv("APPDATA")
if appdata then return find_latest(appdata:gsub("\\", "/") .. "/ccemux") end

local home = os.getenv("HOME") -- Probably should check XDG here too, but this works.
if home then return find_latest(home .. "/.local/share/ccemux") end

-- Who knows what OSX does‽ I don't.
return nil, "Cannot find CCEmuX installation directory"
end

local ccemux_path, err = ...
if not ccemux_path then ccemux_path, err = guess_path() end
if not ccemux_path then
io.stderr:write(err .. "\n")
os.exit(1)
end

local cmd = ("java -jar %q -c ."):format(ccemux_path)
print("> " .. cmd)
os.execute(cmd)

0 comments on commit b99e302

Please sign in to comment.