option explicit
'==============================
'declare constants
const compiler_folder = "c:\Picaxe_compilers\" 'needs a location with no spaces in name
const com_port = 4
const list_of_valid_chips="08_08m_08m2_14m_14m2_18_18a_18m_18m2_18x_20m_20m2_20x2_28_28a_28x1_28x2"
'==============================
'declare variables
dim argument 'calling arguments
dim source_file 'Name of program file
dim source_file_copy 'Name of program file copoy
dim error_file 'name of error file created this run
dim strFileProperties 'properties of file to test size
dim fso 'filesystem Object
dim fo 'file Object
dim chip_id 'Picaxe chip type
dim Wshshell 'Shell Object
dim OBJfso 'file system object
dim Retval 'return code
dim Id_result 'return code from chip name test
dim cmd_run_parm 'parameter for cmd call to compiler
dim date_f, date_h 'storage for date format
dim time_f 'storage for time format
'==============================
'check for proper call environment
set argument = wscript.arguments 'argument übernehmen
if argument.count = 0 then 'Script not started from ther context menu
msgbox "No argument received, aborting", vbcritical, "PICAXE-Download"
wscript.quit
end if
source_file = argument(0) 'source_file name
'==============================
'set up the date and time string
date_h = date()
date_f = right(date_h,4) & "_" & mid(date_h,4,2) & "_" & left(date_h,2)
time_f = time()
time_f = replace(time_f,":","_")
'msgbox now
'==============================
'create the new filename
source_file_copy = replace(source_file,".bas","_Downloaded_" & date_f & "_" & time_f & ".bas")
error_file = replace(source_file,".bas","_Downloaded_" & date_f & "_" & time_f & ".err")
'==============================
'see if chip id is name prefix
'first lose the folder prefix
chip_id = right(source_file_copy,len(source_file_copy)-InStrRev(source_file_copy,"\"))
'msgbox "chip= "&chip_id
'then extract the chip
chip_id = left(chip_id,InStr(1,chip_id,"_")-1)
'msgbox "chip= "&chip_id
'check is valid
id_result = InStr(1,list_of_valid_chips,chip_id)
'==============================
'create copy file
set fso = CreateObject("Scripting.FileSystemObject")
'instantiate file system object
set fo = fso.GetFile(source_file) 'instantiate file object
fo.Copy source_file_copy 'make a copy of the file
'==============================
'identify the chip
'while id_result = 0 do 'this loop isn't implemented yet so must enter a valid name
if id_result = 0 then 'chip_id wasn't a prefix to the file name
chip_id = inputbox("Using COM: "&com_port&chr(13)&chr(10)&"Enter Chip Type:"&chr(13)&chr(10)&"(e.g.28x2, x/m:lower case, for 40 use 28)")
end if
id_result = InStr(1,list_of_valid_chips,chip_id)
'end do
set wshshell = Wscript.CreateObject ("Wscript.Shell")
'==============================
'delete old err files if any
retval=WshShell.run("cmd.exe /c del /q *.err",7,True) '7=silent
'msgbox "RetVal="&retval
'==============================
'construct the compile command
cmd_run_parm = "cmd.exe /k " _
& "c:\Picaxe_compilers\picaxe" _
& chip_id _
& ".exe" _
& " -cCOM" _
& com_port _
& " " _
& chr(34) _
& source_file_copy _
& chr(34)
'==============================
'perform the compilation
retval=WshShell.run(cmd_run_parm,1,True) 'compile via cmd.exe
'msgbox "RetVal="&retval
'==============================
'delete .bas file if error file size > 0 i.e. did not download
'or delete error file if no error
set fo = fso.GetFile(error_file) 'Instanz von Fileobjekt einrichten
if fo.size > 0 then
'error so delete .bas file
retval=WshShell.run("cmd.exe /c del /q "&chr(34)&source_file_copy&chr(34),7,True) '7=silent
'msgbox "del bas file= "&source_file_copy
else
'no error so del error file
retval=WshShell.run("cmd.exe /c del /q "&chr(34)&error_file&chr(34),7,True)
'msgbox "del err file= "&error_file
end if
'==============================
'clean up
wscript.quit 'clean up and exit