BuildEcho/main.aardio

165 lines
4.3 KiB
Plaintext
Raw Normal View History

2023-05-31 00:15:25 +08:00
import win.ui;
/*DSG{{*/
2023-05-31 00:20:35 +08:00
mainForm = win.form(text="BuildEcho";right=1135;bottom=702)
2023-05-31 00:15:25 +08:00
mainForm.add()
/*}}*/
//如果运行或发布遇到问题,请先卸载 WebView2 再运行示例以更新该组件。
import web.view;
var wb = web.view(mainForm);
import process.popen;
import fsys;
import fsys.ini
import console;
configFile = io.splitpath(io._exefile).name + ".ini"
if not io.exist(configFile){
ini = fsys.ini(configFile);
if(_STUDIO_INVOKED){
ini.write("Makefile","路径","./makefile");
}
else {
ini.write("Makefile","路径","./");
}
ini.write("Makefile","文件名","project_*.mk");
string.save(configFile, '\r\n', true);
ini.write("编译模块配置","new","new");
ini.write("编译模块配置","app","app");
ini.write("编译模块配置","simulator","simulator");
ini.write("编译模块配置","resource","resource");
string.save(configFile, '\r\n', true);
ini.write("编译配置","job","job=8");
ini.write("编译配置","j","-j4");
ini.write("编译配置","job","job=8");
string.save(configFile, '\r\n', true);
ini.write("市场名","OP","开放");
ini.write("市场名","IN","印度");
ini.write("市场名","RU","俄罗斯");
}else {
ini = fsys.ini(configFile)
}
var getAllProjectFiles = function(path, fileName){
var data = {};
fsys.enum( path, fileName,
function(dirname,filename,fullpath,findData){
if(filename){
table.insert(data, filename);
}
}
,false/*如果此参数为false则忽略子目录*/
);
return data;
}
var listToDict = function(p_list){
class DictStruct {
project_name;
makefile_name;
}
var all_project_files_list_dict = {};
for(i=1;#p_list;1){
var temp = DictStruct();
temp.project_name = string.split(p_list[i],"_")[3];
temp.makefile_name = p_list[i];
table.push(all_project_files_list_dict,temp)
}
return all_project_files_list_dict;
}
var tableUnique = function(arr,key){
var rAr = {};
var temp = {};
for(k,v in arr){
var a = v[key];
if(!rAr[a]){
rAr[a]= v;
table.insert(temp, a);
}
}
return temp;
}
//获取所有文件名
var allMakefileName = getAllProjectFiles(ini.read("Makefile","路径"), ini.read("Makefile","文件名"));
//设置文件名、项目名的键值对
var allPrjFileDict = listToDict(allMakefileName);
//提取唯一项目名
var allPrjName = tableUnique(allPrjFileDict,"project_name")
table.sort(allPrjName);
var dicData = table.array();
for(sub, prjName in allPrjName){
var temp = table.array();
for(k,prjFile in allPrjFileDict){
if(prjFile.project_name == prjName){
table.insert(temp, prjFile.makefile_name)
}
}
dicData[prjName] = temp;
}
// wb.export 导出的函数被JS调用返回的值使用JSON自动转换为JS对象
wb.export(
getAllPrjName = function(){
return allPrjName;
}
getAllMakefile = function(prjName){
return dicData[prjName];
}
//console.dump(ini.getSection("市场名").OP)
getMarketName = function(makefile){
var marketStr = string.split(makefile,"_");
var allMarketName = {};
marketStr = string.split(marketStr[#marketStr],".")[1];
allMarketName = ini.read("市场名",marketStr)
return allMarketName ? allMarketName : string.find(marketStr,"^En") ? "OP" : marketStr;;
}
getMakefilePath = function(makefile){
return io._exedir + makefile;
}
cmdSpecial = function(command){
2023-05-31 00:18:53 +08:00
if(string.find(command,"make")){
var configFile = io.splitpath(io._exefile).name + ".ini";
var ini = fsys.ini(configFile);
var makefilePath = string.replace(ini.getSection("Makefile").路径, "\\", "/");
if(!string.endWith(makefilePath,"/")){
makefilePath = makefilePath + "/";
2023-05-31 00:15:25 +08:00
}
2023-05-31 00:18:53 +08:00
command = string.replace(command, "make", makefilePath+"make.bat");
2023-05-31 00:15:25 +08:00
mainForm.msgbox(command);
2023-05-31 00:18:53 +08:00
return;
2023-05-31 00:15:25 +08:00
}
//同步有同步的优势,扬长避短是智慧,倒行逆施最累人。
prcs = process.popen(command);
for( all,out,err in prcs.each() ){
wb.invoke("insertAtTheEndOfEditor", all);
}
wb.invoke("insertAtTheEndOfEditor", "---->>>End<<<----");
return;
}
isT117 = function(){
return true
}
)
import wsock.tcp.simpleHttpServer;
wb.go(wsock.tcp.simpleHttpServer.startSpaUrl("\web\index.html"))
mainForm.show();
win.loopMessage();