package.path = package.path .. ';' .. cfg.dir .. '/?.lua'

local lang_en = {
    ["AC696X"]="",
    ["调音工具"]="Audio Config Tool",
    ["检查依赖的软件包是否更新"]="Check Update",
    ["配置工具"]="Config Tool",
    ["生成配置\n(生成 cfg_tool.bin)"]="Generate Config\n(generate cfg_tool.bin)",
    ["配置音效\n(生成 eq_cfg_hw.bin)"]="Generate Audio Effect\n(generate eq_cfg_hw.bin)",
    ["打开"]="Open",
    ["路径"]="Path",
};

cfg:setTranslate("en", lang_en);

local rootDir = cfg.rootDir;

local pkgman = rootDir .. "/pkgman.exe";
-- 依赖的软件包
local req_pkgs = {"efftool", "sdktool", "luaconfig", "3rd", "sdkaudiocvt"};
local check_prog = {pkgman};

local missing_pkgs = {};
for k, v in pairs(req_pkgs) do
	if cfg:utilsGetPkg(v) == nil then
		-- 检查是否缺失依赖的软件
		table.insert(missing_pkgs, v)
	end
end

for k, v in pairs(missing_pkgs) do table.insert(check_prog, v) end

if #missing_pkgs ~= 0 then
	if (cfg:runProg(check_prog) ~= 0) then
		cfg:msgBox("warn", "软件包不是最新，可能会出现问题");
	end
end

local sdktool   = rootDir .. '/' .. cfg:utilsGetPkg("sdktool").run;
local luaconfig = rootDir .. '/' .. cfg:utilsGetPkg("luaconfig").run;
local projdir  = cfg.dir .. '/download/';
local efftool = rootDir .. '/' .. cfg:utilsGetPkg("efftool").run;
local title = "AC695X-SDK";

local default_bin_path = cfg.dir .. '/cfg_tool.bin';
local default_tone_path = cfg.dir .. '/tone.cfg';
local sdk_jcf_path = cfg.dir .. '/sdk.jcf';

local cfgtool_entry_view = cfg:stEntry(":/uires/icon_settle.png",
	"配置工具", "生成配置\n(生成 cfg_tool.bin)",
	cfg:stButton2("路径", "", "secondary", function ()
		cfg:utilsShellShow(luaconfig);
	end),
	cfg:stButton2("打开", "", "main", function ()
		cfg:runProgNoWait({luaconfig, sdk_jcf_path,
			'-p', cfg.dir,
			'-r', rootDir,
			'-b', default_bin_path,
			'-t', default_tone_path});
	end));

local efftool_entry_view = cfg:stEntry(":/uires/icon_eq.png",
	"调音工具", "配置音效\n(生成 eq_cfg_hw.bin)",
	cfg:stButton2("路径", "", "secondary", function ()
		cfg:utilsShellShow(efftool);
	end),
	cfg:stButton2("打开", "", "main", function ()
		cfg:runProgNoWait({efftool, '--type', 'atk'});
	end))

local check_allupdate_btn = cfg:stButton2("检查依赖的软件包是否更新", "", "secondary", function ()
		local check_prog = {pkgman};
		for k, v in pairs(req_pkgs) do table.insert(check_prog, v) end
		if (cfg:runProg(check_prog) ~= 0) then
			if(cfg.lang == "zh") then
				cfg:msgBox("warn", "软件包不是最新，可能会出现问题");
			else
				cfg:msgBox("warn", "software Packages are not up-to-date and may have problems");
			end
		else
			if(cfg.lang == "zh") then
				cfg:msgBox("info", "已经是最新");
			else
				cfg:msgBox("info", "software Packages are up-to-date");
			end
		end
end);

local layout = cfg:vBox{ cfg:stGroup(title, cfg:stHScroll ( cfg:vBox {
	cfgtool_entry_view,
	efftool_entry_view,
	check_allupdate_btn,
}))};


cfg:addKeyInfo("jlxproj.width", "600");
cfg:addKeyInfo("jlxproj.height", "400");
cfg:addKeyInfo("jlxproj.title", title);


cfg:setLayout(layout)
