import fsys.dlg; import protobuf.parser import win.ui; /*DSG{{*/ var winform = win.form(text="Protobuf 编译器";right=538;bottom=306;parent=...) winform.add( btnGenText={cls="button";text="编译生成";left=408;top=225;right=520;bottom=253;db=1;dr=1;z=5}; btnOpenProtoFile={cls="button";text="选择proto文件...";left=414;top=6;right=526;bottom=33;dr=1;dt=1;z=2}; cmbLang={cls="combobox";left=273;top=228;right=397;bottom=248;db=1;dr=1;edge=1;items={"aardio";"C++";"Java";"python";"PHP"};mode="dropdown";z=6}; editProto={cls="edit";left=18;top=40;right=524;bottom=215;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=4}; editProtoFilePath={cls="edit";left=18;top=8;right=406;bottom=33;dl=1;dr=1;dt=1;edge=1;multiline=1;z=1}; lbTip={cls="static";text="本程序编译 proto 描述文件,并自动在用户库中生成类库代码 建议将此代码文件置入您的工程目录下,打开工程后运行该代码.";left=16;top=261;right=524;bottom=300;db=1;dl=1;transparent=1;z=3} ) /*}}*/ winform.cmbLang.oncommand = function(id,event){ winform.editProto.disabled = (winform.cmbLang.selIndex!=1) if( winform.cmbLang.selIndex!=1){ if( ! #winform.editProtoFilePath.text ){ if( #winform.editProto.text ){ string.save("\res\temp.proto", winform.editProto.text ) winform.editProtoFilePath.text = "\res\temp.proto" } } } } winform.cmbLang.selIndex = 1; winform.editProto.text = /* message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; } // a simple comment repeated PhoneNumber phone = 4; } message AddressBook { repeated Person person = 1; } */ import protobuf.compile; winform.btnGenText.oncommand = function(id,event){ var selText = winform.cmbLang.selText; if( selText == "aardio"){ var p = protobuf.parser(); p.parse( winform.editProto.text ) winform.lbTip.text = "编译完成,已添加 Protobuf 类到用户库" } else { if( ! io.exist(winform.editProtoFilePath.text) ){ winform.msgbox("请指定有效的 proto 文件路径","标题") winform.editProtoFilePath.setFocus() return; } var map = { ["C++"]="cpp";["Java"]="java";["python"]="python";["PHP"]="php" }; var prcs,err = protobuf.compile( map[selText],"./out",winform.editProtoFilePath.text); var out = prcs.readAll(); if(#out){ winform.msgbox(out); } var outPath = fsys.path.replaceFile(winform.editProtoFilePath.text,"out"); process.explore_select(outPath) winform.lbTip.text = '已输出到:' + outPath } } winform.btnOpenProtoFile.oncommand = function(id,event){ var path = fsys.dlg.open("proto描述文件|*.proto||") if(!path) return; winform.editProtoFilePath.text = path; var tpath = io.splitpath( path ) if( string.cmp(tpath.ext,".proto") != 0 ){ winform.msgbox("不是有效的proto文件","错误") return; } winform.editProto.text = string.load(path) } winform.wndproc = function(hwnd,message,wParam,lParam){ select(message) {//判断消息类型 case 0x233/*_WM_DROPFILES*/ { winform.editProtoFilePath.text = win.getDropFile(wParam )[1]; } } } winform.enableDpiScaling(); winform.show() win.loopMessage(); return winform;