--MJTS-140914 

local fileroot = ".\\Data\\MjTs-140914\\ms_wetkitt"
local inifile = ".\\modules\\ms_settings.ini"
local tid

function set_tournament_id(ctx, tournament_id)
    tid = tournament_id or nil
    return tournament_id
end

function read_ini(ctx)
    if inifile:sub(1,1) == "." then
        inifile = ctx.sider_dir .. inifile
    end
    local t = {}
    for line in io.lines(inifile) do
        local name, value = string.match(line, "^(wet.kit)%s*=%s*([-%d.]+)")
        if name and value then
            t[name] = tonumber(value) or value
			wet_kit = t[name]
        end
    end
    return t
end	

local function make_key(ctx, filename)
    ini = read_ini(ctx)
    if ctx.season == 1 and wet_kit == 1 then
       MjTs_Data = "wet-kit"
	else
	   MjTs_Data = nil
    end
    if tid and wet_kit == 1 then
        return string.format("%s:%s", MjTs_Data, filename)
    end
  end

local function get_filepath(ctx, filename, key)
    if tid and wet_kit == 1 then
        return string.format("%s\\%s\\%s", fileroot, MjTs_Data, filename)
    end
end

local function init(ctx)
    if fileroot:sub(1,1)=='.' then
        fileroot = ctx.sider_dir .. fileroot
    end
    ctx.register("set_tournament_id", set_tournament_id)
    ctx.register("livecpk_make_key", make_key)
    ctx.register("livecpk_get_filepath", get_filepath)
end

return { init = init }