-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.aardio
276 lines (243 loc) · 9.08 KB
/
main.aardio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import win.ui;
import win.inputBox;
import process;
import process.popen;
import winex;
import console;
import thread.event;
import simulator.helper;
import thread.command;
import fsys.config;
import table;
import process;
import sys;
/*DSG{{*/
winFrom = win.form(text="模拟器控制器1.3";right=474;bottom=447)
winFrom.add(
api_num={cls="static";text="0";left=213;top=29;right=247;bottom=46;align="center";font=LOGFONT(name='微软雅黑';h=-13;weight=700);transparent=1;z=11};
api_time={cls="static";text="2016-07-15 18:23:32";left=225;top=52;right=353;bottom=70;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=13};
api_type={cls="static";text="device_open 6584";left=225;top=74;right=380;bottom=92;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=15};
device_list={cls="listview";left=11;top=171;right=461;bottom=433;edge=1;font=LOGFONT(name='微软雅黑';h=-14;weight=700);gridLines=1;vscroll=1;z=1};
p_id={cls="static";text="电脑编号";left=385;top=18;right=457;bottom=41;font=LOGFONT(name='微软雅黑';h=-16;weight=700);transparent=1;z=6};
pc_num={cls="static";text="0";left=360;top=26;right=465;bottom=100;align="center";font=LOGFONT(name='微软雅黑';h=-64;weight=700);transparent=1;z=5};
reg_rom={cls="button";text="导入模拟器";left=18;top=112;right=105;bottom=141;font=LOGFONT(name='微软雅黑';weight=700);z=16};
serv_status={cls="static";text="服务已关闭";left=151;top=117;right=230;bottom=134;color=255;font=LOGFONT(name='微软雅黑';h=-14;weight=700);transparent=1;z=17};
service={cls="button";text="开启服务";left=18;top=17;right=107;bottom=104;font=LOGFONT(name='微软雅黑';h=-16;weight=700);z=7};
set_code={cls="button";text="设置编号";left=376;top=113;right=453;bottom=141;font=LOGFONT(name='微软雅黑';weight=700);z=8};
static={cls="static";text="在线设备列表";left=15;top=147;right=92;bottom=169;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=2};
static2={cls="static";text="数量:";left=103;top=149;right=139;bottom=167;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=3};
static3={cls="static";text="接口调用:";left=151;top=29;right=218;bottom=48;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=9};
static4={cls="static";text="次";left=249;top=31;right=278;bottom=46;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=10};
static5={cls="static";text="调用时间:";left=151;top=51;right=218;bottom=70;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=12};
static6={cls="static";text="任务类型:";left=151;top=73;right=218;bottom=92;center=1;font=LOGFONT(name='微软雅黑';weight=700);transparent=1;z=14};
total_num={cls="static";text="0";left=128;top=148;right=152;bottom=170;align="right";font=LOGFONT(name='微软雅黑';h=-13;weight=700);transparent=1;z=4}
)
/*}}*/
var cfg = fsys.config("/res/")
var p_id = cfg.config.p_id;//电脑编号
var api_url = "http://bot.leesrobots.com:8081";//接口域名
var serv_status = false;
var now_devices = {};
var cycle_task = 2; //任务执行周期,5分钟
var cycle_status = 5;//状态上传周期
var listener = thread.command();
//窗口数据初始化
var init_w = function(){
winFrom.pc_num.text = p_id
winFrom.device_list.clear();
winFrom.api_time.text = null;
winFrom.api_type.text = null;
winFrom.api_time.api_num = 0;
}
//设备列表增加
listener.add_device = function(d_code,wx_nick,d_id){
var item = {d_id;d_code;wx_nick};
table.push(now_devices,item);
winFrom.device_list.addItem(item);
winFrom.total_num.text = tostring(winFrom.device_list.count);
}
//设备列表删除
listener.del_device = function(d_id){
var index = winFrom.device_list.findItemEx(d_id);
for (k,v in now_devices ){
if(d_id == v[1])
{
table.remove(now_devices,k);
break ;
}
}
winFrom.device_list.delItem(index);
winFrom.total_num.text = tostring(winFrom.device_list.count);
}
//更新api相关字段
listener.update_api = function(task_id,task_type){
winFrom.api_time.text = tostring(time.now());
var api_type = task_type ? tostring(task_type)+" "+tostring(task_id) : "空";
winFrom.api_type.text = api_type;
winFrom.api_num.text = tostring(tonumber(winFrom.api_num.text)+1);
}
//循环更新viewlist设备列表(异常关闭设备,列表删除)
listener.refresh_list = function(new_list){
winFrom.device_list.clear();
sleep(1000);
var devices = {};
for (k,v in now_devices ){
for(key,val in new_list){
//console.varDump(val)
if(v[2]==val)
{
table.push(devices,v);
winFrom.device_list.addItem(v);
}
}
}
now_devices = devices;
winFrom.total_num.text = tostring(table.count(new_list));
}
//设置电脑编号
winFrom.set_code.oncommand = function(id,event){
//winFrom.msgbox( winFrom.set_code.text );
inputbox = win.inputBox()
inputbox.text = "设置编号"
inputbox.info.text = "请输入电脑编号"
inputbox.input.text = p_id
var pc_id = inputbox.doModal();
if(pc_id)
{
cfg.config.p_id = pc_id;
cfg.saveAll();
p_id = pc_id;
winFrom.pc_num.text = p_id
}
}
var pcTask = thread.event("pc任务线程",false)
//var vmsStatus = thread.event("模拟器状态上传线程",false)
//pc类任务线程
var pc_task_thread = function(cycle){
import win;
import thread.event;
import console;
import sys;
import simulator.helper;
var helper = simulator.helper();
var evt = thread.event("pc任务线程")
var evt_type = 0;
while( !evt.wait(cycle) ){
//第一次任务打开z盘
if(evt_type==0)
{
import process.popen;
prcs = process.popen("cmd.exe")
cmd = /*
start z:
*/
prcs.write(cmd)
}
//1-6点关机处理
var tm = time.now();
var hour = tostring(tm,"%H");
hour = tonumber(hour);
if(hour>=1 && hour<6)
{
sys.shutdown();
}else {
evt_type+=1;
if(evt_type%3 >0 )//执行任务
{
task = helper.api_get_task();
if(!task)
continue ;
var task_type = task.task_type;
var rs,msg = null;
if(!task_type)
continue ;
if(task_type=="device_open")
{
rs = helper.open_device(task.order.d_code,task.order.wx_nick,task.order.d_id);//开机
msg = rs ? "成功" : "失败";
}elseif(task_type=="device_close"){
rs = helper.close_device(task.order.d_code,task.order.wx_nick,task.order.d_id);//关机
msg = rs ? "成功" : "失败";
}elseif(task_type=="install_apk"){
rs = helper.download_file(task.order.file_url,"d:/apk/",task.order.file_name);//下载
if(rs)
rs = helper.install_apk(task.order.file_name,task.order.activity,task.order.d_code,"d:/apk/");//安装并启动
msg = rs ? "成功" : "失败";
}elseif(task_type=="device_config"){
rs = helper.device_config(task.order,"D:/roms/");//配置位置,cpu等信息
msg = rs ? "成功" : "失败";
}else {
helper.api_upload_status();//上传状态
rs = true;
msg = "成功";
}
//任务结果回传
helper.api_res_task(task.order.d_id,task.task_id,task_type,tostring(rs),msg);
}else {//上传挂机状态
helper.api_upload_status();
}
}
}
}
//模拟器状态上传线程(废弃)
var vms_status_thread = function(cycle){
import win;
import thread.event;
import console;
import simulator.helper;
var helper = simulator.helper();
var evt = thread.event("模拟器状态上传线程")
while( !evt.wait(cycle) ){
helper.api_upload_status();//上传状态
}
}
//开启关闭服务
winFrom.service.oncommand = function(id,event){
//winFrom.msgbox( winFrom.service.text );
serv_status = !serv_status;
if(serv_status)
{
init_w();
winFrom.serv_status.text = "服务运行中..."
winFrom.service.text = "关闭服务";
winFrom.set_code.disabled = true;
//var helper = simulator.helper();
//rs = helper.download_file("http://bot.leesrobots.com:8081/statics/files/wx_helper6.5.4.apk","d:/apk/","wx_helper6.5.4.apk");
//helper.api_upload_status();//上传状态
//if(rs) helper.install_apk("wx_helper6.5.4.apk","com.lees.help/.MainActivity","MEmu","d:/apk/");
//task = helper.api_get_task();
//console.varDump(task);
//helper.open_device("MEmu","逍遥模拟器",22);
//helper.device_config("MEmu","z:/MEmu/MemuHyperv VMs/");
//helper.copy_device('MEmu_500')
//for processEntry in process.each( "MemuHeadless.exe" ){
// console.varDump(processEntry);
//}
var pcTaskThread = thread.create(pc_task_thread,cycle_task*60*1000);
//thread.waitOne(pcTaskThread)
//var vmsStatusThread = thread.create(vms_status_thread,cycle_status*60*1000);
//thread.waitOne(vmsStatusThread)
}else
{
winFrom.serv_status.text = "服务已关闭"
winFrom.service.text = "开启服务";
winFrom.set_code.disabled = false;
//var helper = simulator.helper();
//helper.get_online_device();
pcTask.set();
//vmsStatus.set();
}
}
//导入模拟器
winFrom.reg_rom.oncommand = function(id,event){
//winFrom.msgbox( winFrom.reg_rom.text );
process("/res/import.bat");
}
init_w()
winFrom.device_list.insertColumn("设备id",60)
winFrom.device_list.insertColumn("设备编号",150)
winFrom.device_list.insertColumn("微信昵称",230)
winFrom.show();
//程序开启后,自动开启服务
winFrom.service.oncommand();
win.loopMessage();