PDA

View Full Version : thinBundle: How to run from a script or commandline?



ReneMiner
13-06-2022, 06:55
Currently i have the following problem concerning thinbundle:

As it says
there is a way to run thinbundle from a thinbasic-script
- i am missing the most important thing to do so:

What is the magic thinbasic-keyword to run thinbundle and what syntax to use ?

All the #Bundle-combinable keywords that i find in help:


#Bundle File
#Bundle Name
#Bundle Icon
#Bundle Type
#Bundle Version

are to prepare any settings previously to bundle only,

there is no keyword as
Start, Go, Run, Execute, Invoke nor Bundle
that were possible to combine with #Bundle to make it do what it is supposed to from within a script.
trying

SHELL #BUNDLE, "", 10000
#Bundle Now
#Bundle Do #Bundle
#Bundle On

was not succesful :(

Using from script

OS_SHELL( App_Path & "thinair\thinbasic_Bundle_UI.exe", "d:\tbScripting\Experiments\test.tBasic")

or running it directly from commandline
(%systemroot%\syswow64\cmd.exe and also %systemroot%\system32\cmd.exe )
result in the same Error-Message that says

"thinBasic-Engine not found!"

"thinbasic_Bundle_UI /?"

does not result in any help about commandline-parameters
but also laments that no engine were to find.

So the only way to bundle is using thinAir manually since when using AutoIt, Autohotkey or NirCmd the menu on thinAir will not receive the focus and all keystrokes go to the code-window and the code-windows context-menu is not offering a shortcut to run thinbundle.

Is thinbundle depending on thinAir now? Is there no more other way?

xLeaves
16-06-2022, 05:02
This is certainly possible, and you might want to check out what LzBot does, which uses ThinBasic to write an autocompiled program that generates an EXE file "unknowingly".

The implementation is as follows.





Function Main() As Long
Dim As Long iPid, hWin, hCon, hDlg, hBtn
Dim As Double ST
// 获取命令行
Dim sBasePath As String = Replace$(OS_GetCommand(2), """", "")
Dim sMakeType As String = Replace$(OS_GetCommand(3), """", "")
Dim sProcName As String = Replace$(OS_GetCommand(4), """", "")
Dim sSavePath As String = Trim(OS_GetCommand(5), Any """")

If sBasePath <> "" Then
// 软件路径自动补末尾
Dim sChr As String = Right$(sBasePath, 1)
If (sChr <> "\") And (sChr <> "/") Then
sBasePath &= "\"
End If

// 自动纠错 sMakeType 选项
Select Case sMakeType
Case "thinBasic.exe", "thinBasicc.exe"
Case Else
sMakeType = "thinBasic.exe"
End Select

// 生成路径和命令行
Dim sBuild As String = sBasePath & "bin\build\ThinBasic_Bundle_UI.exe"
Dim sRunner As String = sBasePath & "bin\" & sMakeType
Dim sScript As String = sBasePath & "temp\boot.tbasic"
Dim sExePath As String = sBasePath & "temp\" & sProcName & ".exe"
Dim sCommand As String = """" & sBuild & """ -f """ & sScript & """ -t """ & sRunner & """"

// 检查文件路径
If FILE_Exists(sBuild) = 0 Then
// 返回代码 [构建程序文件不存在]
MsgBox "编译失败,错误代码 11(编译器程序文件不存在)。", , "GeekBot"
Return 11
End If
If FILE_Exists(sRunner) = 0 Then
// 返回代码 [执行器程序文件不存在]
MsgBox "编译失败,错误代码 12(执行器程序文件不存在)。", , "GeekBot"
Return 12
End If
If FILE_Exists(sScript) = 0 Then
// 返回代码 [脚本文件不存在]
MsgBox "编译失败,错误代码 13(脚本文件不存在)。", , "GeekBot"
Return 13
End If

// 清理之前残留的编译器进程和文件
OS_ProcessKillByName("ThinBasic_Bundle_UI.exe")
FILE_Kill(sExePath)

// 运行编译器
RunApp(sCommand, True)

// 查找窗口
ST = Timer
Do
hWin = Window_Find(104, "FORM_THINBASIC_BUNDLE_UI_FRMMAIN_CLASS", "ThinBasic_Bundle_UI", &H10000000, 0, 0, 0)
If hWin <> 0 Then
iPid = Window_GetPID(hWin)
Window_Show(hWin, 0)
Exit Do
End If
If (Timer - ST) > 10 Then
// 返回代码 [查找窗口超时]
MsgBox "编译失败,错误代码 21(编译器未启动)。", , "GeekBot"
Return 21
End If
Delay 60
Loop

// 查找工具栏
ST = Timer
Do
hCon = Window_E2H(hWin, "ToolbarWindow32", 1)
If hCon <> 0 Then
Exit Do
End If
If (Timer - ST) > 6 Then
// 返回代码 [查找工具栏超时]
MsgBox "编译失败,错误代码 22(编译器加载不完全)。", , "GeekBot"
Return 22
End If
Delay 60
Loop

// 点击工具栏的编译按钮
Window_Post(hWin, 273, 5101, hCon)

// 查找消息框
ST = Timer
Do
hDlg = Window_Find(88, "#32770", "ThinBasic_Bundle_UI", &H10000000, 0, 0, 0)
If hDlg <> 0 Then
Exit Do
End If
If (Timer - ST) > 12 Then
// 返回代码 [查找消息框超时]
MsgBox "编译失败,错误代码 23(无法确认编译结果)。", , "GeekBot"
Return 23
End If
Delay 60
Loop

// 结束 编译器 进程
PID_Kill(iPid)

// 检查编译后的文件是否存在
If FILE_Exists(sExePath) = 0 Then
// 返回代码 [编译后找不到文件]
MsgBox "编译失败,错误代码 31(找不到编译后的可执行程序)。", , "GeekBot"
Return 31
End If

// 询问保存位置、保存文件
If sSavePath = "" Then
Dim sPtr As Long = Dlg_SaveFile(0, "GeekBot.exe", "可执行程序 (*.exe)|*.exe||")
sSavePath = Peek$(ASCIIZ, sPtr)
End If
If sSavePath = "" Then
// 返回代码 [用户取消了保存文件]
Function = 41
Else
File_Copy(sExePath, sSavePath)
If MsgBox("文件成功生成到 " & sSavePath & vbcrlf & vbcrlf & "是否打开目录查看生成的文件?", %MB_YESNO or %MB_ICONINFORMATION) = %IDYES Then
RunApp("explorer.exe /select,""" & sSavePath & """")
End If
End If

// 清理文件
File_Kill(sScript)
File_Kill(sBasePath & "temp\main.tbasic")
File_Kill(sExePath)

Else
// 返回代码 [命令行参数不正确]
Return 1
End If
Return 0
End Function




This code can't be run directly with ThinBasic because I modified some things, but the general principle should be clear, and a lot of it is in the ThinBasic manual, or available using some analysis tools.

ReneMiner
19-06-2022, 03:51
140 + lines for a command that should be only a few chars?
Are you kidding? And what of that is in the thinbasic-manual?
And why doesn't it do anything but show chinese messages?

Guess i am out now.

Bye

xLeaves
22-06-2022, 18:38
Why don't you try to read the code? As a developer, it shouldn't be very challenging to understand 100+ lines of code.

Line 29 is the command line usage of ThinBasic_Bundle_UI.exe, and because of your rudeness, that's all I'll tell you.

I have noted in my reply that this code is not runnable, it is just for you to understand the principle of it, because it uses some other tools I developed, if you want to run it, you need to make some changes, otherwise you will only be able to read it, not run it.