Post by xxgeek on Jul 12, 2021 19:16:55 GMT
Automates the making of the TKN file, user selects a .bas file, and auto tkn does the rest.
Place in it's own dir, since it makes a dir name tkn, and uses a few temp files in the root dir (they get deleted after used)
'Name Auto TKN
'Version - 1.0
'Created - July 2021
'Author - xxgeek, a member of the justbasiccom.proboards.com/ forums
'
'Place this bas file in it's own folder as it will create 2 temp files, and a TKN folder
'Run it and click "Select" to select a .bas file to make the TKN file.
'Any spaces in the filename will be removed on the TKN file (Just so you know)
'A folder named TKN is created in same dir as this file is run to store this and future TKN files
'Temp files named temp.txt, and autoSave.vbs will be created, and deleted once they are not needed
'Enjoy!
'[checkjbpath]
'check Just Basic v2.0 Default Install Dir for existence
JBpath$ = "c:\Program Files (x86)\Just Basic v2.0"
res=pathExists(JBpath$)
'if Just Basic v2.0 is NOT installed to it's Default Install Dir, get Path from User
if res then [go] else notice " Just Basic v2.0 was not installed to the default install folder."+chr$(13)+"Hit [ok], then Select the Folder Just Basic v2.0 is Installed"
JBpath$ = FolderDialog$("Select the Folder Where You Installed JB - Named Just Basic v2.0")
if JBpath$ = "" then notice "No path given - closing Auto TKN" : end
[go]
' setup a Window for User to Select a .bas File to Make a Project with
nomainwin
WindowWidth = 600
WindowHeight = 320
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
BackgroundColor$ = "lightgray"
ForegroundColor$ = "black"
'add some text ,some buttons, and a menu to the Window
statictext #pick.header, "Auto TKN", 190, 30, 590, 45
statictext #pick.info, "Select a working Just Basic Source Code File (.bas)", 30, 110, 590, 40
statictext #pick.jbforums, "Visit the Just Basic Forums @ https://justbasiccom.proboards.com/", 125, 270, 590, 20
button #pick.default, "Select File", [defaultClick],UL 140, 195, 135, 35
button #pick.32, "Cancel", [cancel],UL 320, 195, 135, 35
'open the Window, and set some Fonts for each statictext, and buttons
open "Auto TKN v1.0" for window_nf as #pick
#pick, "trapclose [quit.pick]"
#pick, "font Arial 10 bold"
#pick.header, "!font Arial 24 bold"
#pick.info, "!font Arial 16 bold"
#pick.jbforums "!font Arial 8 bold"
#pick.default, "!font Arial 12 bold"
#pick.default, "!setfocus"
wait
[defaultClick]
'check existence and JBPath$
res=pathExists(JBpath$)
if res then a = a + 1 else notice " Just Basic v2.0 was not was not found in ";JBpath$;" Restart BAS2EXE - Try Again":end
' Just Basic 2 is installed - continue on
'define some variables
JBexe$ = "jbasic.exe"
q$=chr$(34)
'Checking for jbasic.exe in Just basic dir
res=fileExists(JBpath$,JBexe$)
if res then a = a + 1 else notice JBexe$;" Does not exist in ";JBpath$;" Closing Auto TKN" : end
' all needed files accounted for
' Use the filedialog function to allow user to select a source file (.bas)
[filediag]
'open file dialog to choose a .bas file for tkn creation
filedialog "Open \ Select a Just Basic Source File (.bas) ", DefaultDir$; "\*.bas", fname$
if fname$ = "" then notice "No file selected, Auto TKN will now close" : end
'Separate path from selected filename, and extension from selected filename
for var1 = len(fname$) to 1 step -1
if mid$(fname$, var1, 1) = "\" then var2 = var1 -1 : var3 = var2 - ((len(fname$))) : exit for
next var1
var3 = abs(var3)
orig$ = left$(fname$, var2)
fname0$ = right$(fname$, var3 -1)
'Remove spaces in selected filename if any
open "temp.txt" for output as #1
for x = 1 to len(fname0$)
keeper$=mid$(fname0$, x, 1)
if keeper$ <> " " then print #1, keeper$;
next x
close #1
dim array$(250)
open "temp.txt" for input as #1
while eof(#1) = 0
line input #1, array$(x)
line$ = array$(x)
x = x + 1
fname0$ = line$
wend
close #1
'finish separating path-filename
for var4 = len(fname0$) to 1 step -1
if mid$(fname0$, var4, 1) = "." then var5 = var4 -1 : var6 = var5 - ((len(fname0$))) : exit for
next var4
var6 = abs(var6)
fnamenobas$ = left$(fname0$, var5)
' fname$ = Full Path of User Selected .bas file (including the filename.bas)
' fname0$ = Name of the Selected .bas File Only - eg ; filename.bas
' fnamenobas$ = Name of the Selected .bas File (without the .bas) - eg: filename
'delete temporay file used for saving fname0 while removing spaces in filename
[begin]
DestPath$=DefaultDir$
TKN$ = DefaultDir$;"\TKN"
'Make Folder for TKN files
res =mkdir(TKN$)
'make sure TKN Folder was actually created
res=pathExists(TKN$)
if res then a = a + 1 else notice "TKN folder was NOT Created in ";DestPath$: end
'copy the project .bas file to this projects dir
open fname$ for input as #fname
open TKN$;"\";fname0$ for output as #1
print #1, input$(#fname, lof(#fname));
close #1
close #fname
close #pick
'check if a previous tkn of same name exists - delete if true
tknFile$ = fnamenobas$;".tkn"
res = fileExists(TKN$, tknFile$)
if res then kill TKN$;"\";tknFile$
'Create the TKN file.
RUN JBpath$;"\";JBexe$;" -T -A ";TKN$;"\";fname0$
'give time for the save TKN window to appear
for x = 1 to 550000
next x
'#######################################################################
'Write script to a .vbs file
open "autoSave.vbs" for output as #1
print #1, "Set WshShell = WScript.CreateObject(";q$;"WScript.Shell";q$;")"
#1, "WshShell.AppActivate ";q$;"Save *.TKN File As...";q$
'#1, "Wscript.Sleep(200)" - keeping for testing
#1, "WshShell.SendKeys ";q$;"{ENTER}";q$
#1, "Wscript.Sleep(800)"
#1, "WshShell.AppActivate ";q$;"saved as";q$
#1, "WshShell.SendKeys ";q$;"{ENTER}";q$
close #1
'#######################################################################
'run the .vbs file through cscript.exe(built into Windows)
run "cscript /nologo ";"autoSave.vbs" '- nologo helps a little to hide script window
'loop until TKN File is verified saved
do
res = fileExists(TKN$,fnamenobas$;".tkn")
if res then exit do
scan
loop until res
'delete temp files
res = fileExists(DefaultDir$,"temp.txt")
if res then kill DefaultDir$;"\";"temp.txt"
res = fileExists(DefaultDir$,"autoSave.vbs")
if res then kill DefaultDir$;"\";"autoSave.vbs"
res = fileExists(TKN$,fname0$)
if res then kill TKN$;"\";fname0$
'inform user of tkn file location
'choice for user to keep or delete the temp files(saved projects folder)
confirm "TKN file was created in "+chr$(13)+TKN$+chr$(13) +chr$(13)+"Would you like make another TKN file? ";choice$
if choice$="no" then [notagain]
if choice$ <> "no" then [go]
[notagain]
end
[quit.pick]
close #pick
end
[cancel]
close #pick
end
'function for checking file existence
function fileExists(path$, filename$)
dim info$(0, 0)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
'function for checking folder existence
function pathExists(path$)
pathExists = (mkdir(path$)=183)
end function
'functions for making the folder dialog window
function FolderDialog$(caption$)
WindowWidth = 600
WindowHeight = 370
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
BackgroundColor$ = "lightgray"
ForegroundColor$ = "black"
gosub [FolderDlgGetDrives]
statictext #folderdlg.S, "Note: - Only Drives and Folders Appear Below - No Files Appear", 45, 15, 550, 25
statictext #folderdlg.S, "Select a Drive or a Folder From the List", 175, 40, 300, 25
statictext #folderdlg.D, " (Double Click Drive Letters and Folders to Select or Navigate)", 85, 70, 395, 15
listbox #folderdlg.list, FolderList$(, [FolderDlgSelect], 22, 90, 550, 130
button #folderdlg.default, "Ok", [FolderDlgOk], UL, 190, 293, 85, 35
button #folderdlg.B, "Back", [FolderDlgBack], UL, 490, 45, 80, 30
button #folderdlg.C, "Cancel", [FolderDlgCancel], UL, 290, 293, 85, 35
textbox #folderdlg.text, 42, 225, 510, 30
statictext #folderdlg.path, "Selected Drive or Folder Path Appears Here", 130, 258, 400, 20
open caption$ for dialog_modal as #folderdlg
#folderdlg, "trapclose [FolderDlgCancel]"
#folderdlg.default, "!font Arial 10 bold"
#folderdlg, "font Arial 10 bold"
#folderdlg.S, "!font Arial 10 bold"
#folderdlg.path, "!font Arial 10 bold"
#folderdlg.list, "font Arial 10 bold"
#folderdlg.C, "!font Arial 10 bold"
#folderdlg.D, "!font Arial 8 bold"
#folderdlg.text, "!font Arial 10 bold"
wait
[FolderDlgSelect]
#folderdlg.list, "selection? temp$"
if temp$ <> "" then
level = level+1
folder$ = folder$; temp$; "\"
#folderdlg.text, folder$
gosub [FolderDlgGetDir]
#folderdlg.list, "reload"
end if
wait
[FolderDlgBack]
if level > 0 then
level = level-1
if level = 0 then
folder$ = ""
gosub [FolderDlgGetDrives]
else
i = len(folder$)-1
while mid$(folder$, i, 1) <> "\" and mid$(folder$, i, 1) <> ""
i = i-1
wend
folder$ = left$(folder$, i)
gosub [FolderDlgGetDir]
end if
#folderdlg.text, folder$
#folderdlg.list, "reload"
end if
wait
[FolderDlgGetDrives]
c = 1
while word$(Drives$, c) <> ""
c = c+1
wend
redim FolderList$(c)
for i = 1 to c
FolderList$(i) = word$(Drives$, i)
next i
return
[FolderDlgGetDir]
files folder$, info$(
s = val(info$(0,0))
t = val(info$(0,1))
redim FolderList$(t)
for i = 1 to t
FolderList$(i) = info$(i+s, 1)
next i
return
[FolderDlgOk]
#folderdlg.text, "!contents? FolderDialog$"
If right$(FolderDialog$,1) = "\" then FolderDialog$ = left$(FolderDialog$, len(FolderDialog$) - 1)
[FolderDlgCancel]
close #folderdlg
end function