[main] Title=api Description=This script contains a set of magic functions that you can use inside your script to make some tasks easier like creating shortcuts and extracting files. Selected=none Level=1 Credits=To the whole community of developers, beta testers and active members which make these developments fun and interesting. Date=2008-MAR-08 Version=11 Contact=http://www.boot-land.net/forums/Common-API-for-projects-t2100.html Download_Level=0 Author=Pedro Le 15 [Interface] pButton1="Update Script.Project",1,8,9,37,117,44,Update_Api pTextFile1=Update_Api.txt,1,6,12,91,345,84 pTextLabel1="Click on this button for adding or correct all variables required by API",1,1,137,36,216,42,8,Normal [Update_Api] //If,NotExistFile,%ProjectInfo%,Run,%ScriptFile%,Exit_Message,You#$smust#$srun#$sthis#$sscript#$sin#$sa#$sProject#$sbased#$son#$sNativeEx,#$s#$s#$s#$s!!#$sNot#$sfind#$s%ProjectInfo%#$s!! StrFormat,filename,%ScriptFile%,#1 IniRead,"%ProjectDir%\Script.project","Variables","#$pAPI#$p",#2 StrFormat,path,#2,#3 If,#3,NotEqual,,IniWrite,"%ProjectDir%\Script.project","Variables","#$pAPI#$p",#3#1 If,#3,Equal,,IniWrite,"%ProjectDir%\Script.project","Variables","#$pAPI#$p","#$pProjectDir#$p\Basic\Build\#1" ExtractFile,"%ScriptFile%","InterfaceEncoded","Update_Api.txt","%ScriptDir%" IniMerge,"%ScriptDir%\Update_Api.txt","%ProjectDir%\Script.project" FileDelete,"%ScriptDir%\Update_Api.txt" Message,"Script.project updated",Information [Calculate] //In Script.project==> _Calculate=run,%API%,Calculate //Syntax==> _Calculate,[expression],[Variable (whithout %)] ShellExecute,Hide,"%Tools%\sCalculate.exe","#$q#2=#1#$q#$s#$q%ProjectTemp%\calc.txt#$q" Run,"%ProjectTemp%\calc.txt",Calculate FileDelete,"%ProjectTemp%\calc.txt" [NotCompatible] If,#1,Equal,nativeEX,If,ExistFile,%ProjectInfo%,Run,%API%,Exit_Message,#1 If,#1,Equal,LiveXP,If,ExistFile,%ProjectInfo%,Run,%API%,Exit_Message,#1 [Exit_Message] If,#2,Equal,,Message,This#$sprogram#$s#$sis#$snot#$scompatible#$swith#$s#1!#$x#$xExiting... If,#2,NotEqual,,Message,#1#$x#2#$x#$xExiting... Exit,"Exiting..." [Copy_Files] //In Script.project==> _FileCopy=run,%API%,Copy_Files //Syntax==> _FileCopy,[Source],[Target] Echo,"Copy file #1" StrFormat,ext,#1,#3 If,NotExistDir,"#2",DirMake,"#2" If,#3,NotEqual,".*",If,ExistFile,"#1",FileCopy,"#1","#2" If,#3,Equal,".*",FileCopy,"#1","#2" [Copy_Program] //In Script.project==> CopyProgram=run,%API%,Copy_Program //Syntax==> CopyProgram,[%FileBox_Source%],[%Target_Prog%\%ProgramFolder%],[%ProgramExe%] Echo,"Copy program files..." StrFormat,path,#2\,#2 If,#2,Equal,"\",StrFormat,path,"%Target_Prog%\%ProgramFolder%\",#2 If,#3,Equal,"",StrFormat,filename,%ProgramExe%,#3 If,NotExistFile,"#1\#3",Message,"The path you specified as your source is not valid! #$x#$xPlease select a valid source dir in the script configuration window..." If,NotExistFile,"#1\#3",Exit,"Exiting..." //ShellExecute,hide,"%WindowsDir%\System32\cmd.exe","/c mkdir #$q#2#$q" DirMake,#2 DirCopy,"#1\*.*","#2" ############################################################################### [Depack] //===> Unpack,[Folder],[Archive],[Option],[%Target_Prog%],[%ProgramFolder%],[%programExe%] echo," Extracting files and settings ..." If,#1,Equal,"",StrFormat,filename,"Folder",#1 StrFormat,path,#4\,#4 StrFormat,path,#5\,#5 If,#4,Equal,"\",StrFormat,path,"%Target_Prog%\",#4 If,#5,Equal,"\",StrFormat,path,"%ProgramFolder%\",#5 If,#6,Equal,"",StrFormat,filename,"%ProgramExe%",#6 //DirMake,"#4#5" ShellExecute,hide,"%WindowsDir%\System32\cmd.exe","/c mkdir #$q#4#5#$q" If,#2,NotEqual,"",run,%API%,Check_Archive,#1,#2,#3,#4,#5,#6 If,#2,Equal,"",ExtractAllFiles,"%ScriptFile%","#1","#4#5" [Check_Archive] StrFormat,ext,#2,#8 If,#8,Equal,".exe",Run,%API%,Execute_Archive,#1,#2,#3,#4,#5,#6,#7,#8 If,#8,NotEqual,".exe",Run,%API%,Extract_Archive,#1,#2,#3,#4,#5,#6,#7,#8 [Execute_Archive] ExtractAllFiles,"%ScriptFile%","#1","#4#5" ShellExecute,open,"#4#5#2","#3",#4#5 FileDelete,"#4#5#2" [Extract_Archive] If,NotExistFile,"%ScriptDir%\#5#6",Run,%API%,Depack_Archive,#1,#2,#3,#4,#5,#6,#7,#8 If,ExistFile,"%ScriptDir%\#5#6",Run,%API%,Copy_Program,"%ScriptDir%\#5","#4#5","#6",,#8 [Depack_Archive] ExtractFile,"%ScriptFile%","#1","#2","#4#5" If,#8,NotEqual,".rar",ShellExecute,Hide,#$q%Tools%\7za.exe#$q,"x -y #$q#4#5#2#$q -o#$q#4#5#$q" If,#8,Equal,".rar",ShellExecute,Hide,#$q%Tools%\unrar.exe#$q,"x -y #$q#4#5#2#$q #$q#4#5#$q" If,ExistFile,"#4#5#2",FileDelete,"#4#5#2" ############################################################################### [reg_hiveload] echo,"Loading hive from %HIVE_#1%" RegHiveLoad,%reg_temp%,%HIVE_#1% Echo,"Updating registry.." [reg_hiveunload] /echo,"Unloading %reg_temp%" RegHiveUnLoad,%reg_temp% [Association] //In Script.project==> Add_Asso=Run,%API%,Association //Syntax==> Add_Asso,[Ext] echo,"Associate . #1 file" reg_add,0x1,"%reg%\Classes\.#1",,"#1file" reg_add,0x2,"%reg%\Classes\#1file","FriendlyTypeName","%PE_Programs%\%programFolder%\%programExe%" reg_add,0x2,"%reg%\Classes\#1file\shell\open\command",,"%PE_Programs%\%programFolder%\%programExe%#$q#$s#$q%1#$q" ############################################################################### [do_associate] echo,"Associating #1 filetype.." RegHiveLoad,%reg_temp%,%HIVE_HKU% reg_add,0x1,"%reg%\Classes\.#1","","#1file" run,%API%,do_associate_action_#2,#1,#2,#3,#4 RegHiveUnLoad,%reg_temp% [do_associate_action_] //echo," " If,#3,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q%PE_Programs%\%programFolder%\%programExe%#$q" If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q" If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q#$c#4" reg_add,0x2,"%reg%\Classes\#1file\shell\open\command","","#$q%PE_Programs%\%programFolder%\%programExe%#$q#$s#$q%1#$q" [do_associate_action_edit] If,#3,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q%PE_Programs%\%programFolder%\%programExe%#$q" If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q" If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q#$c#4" reg_add,0x2,"%reg%\Classes\#1file\shell\edit\command","","#$q%PE_Programs%\%programFolder%\%programExe%#$q#$s#$q%1#$q" [do_associate_action_open] //echo," " If,#3,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q%PE_Programs%\%programFolder%\%programExe%#$q" If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q" If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q#$c#4" //If,#3,Equal,,reg_add,0x2,"%reg%\Classes\%my_file_type_label%\shell\open\command","","#$q%PE_Programs%\%programFolder%\%programExe%#$q#$s#$q%1#$q" //If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\%my_file_type_label%\shell\open\command","","#$q#3#$q#$s#$q%1#$q" //If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\%my_file_type_label%\shell\open\command","","#$q#3#$q#$s#$q#4#$q" If,#3,Equal,,reg_add,0x2,"%reg%\Classes\#1file\shell\open\command","","#$q%PE_Programs%\%programFolder%\%programExe%#$q#$s#$q%1#$q" If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\#1file\shell\open\command","","#$q#3#$q#$s#$q%1#$q" If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\#1file\shell\open\command","","#$q#3#$q#$s#$q#4#$q" [do_associate_action_icon] //echo," " If,#3,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q%PE_Programs%\%programFolder%\%programExe%#$q" If,#3,NotEqual,,If,#4,Equal,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q" If,#3,NotEqual,,If,#4,NotEqual,,reg_add,0x2,"%reg%\Classes\#1file\DefaultIcon","","#$q#3#$q#$c#4" ############################################################################### [Expand_file] StrFormat,filename,#1,#3 StrFormat,path,#1,#2 If,NotExistFile,%Target_Sys%\#2#3",CopyOrExpand,"%Source_Sys%\#3","%Target_Sys%\#2" ############################################################################### [AddShortcut] //===> Add_Shortcut,[Type],[Folder],[FullFileName],[Title],[Work Folder],[Parameters],[IconFile( .ico .exe)],[StartMode(1, 2, 3, or 4)] echo,"Create ShortCut #1 " StrFormat,filename,,%OptionShortcut% If,#3,NotEqual,,If,#5,Equal,,StrFormat,path,#3,%My_Shortcut_FOLDER% If,#3,NotEqual,,If,#5,NotEqual,,StrFormat,path,#5\,%My_Shortcut_FOLDER% If,#4,Equal,,StrFormat,filename,%ProgramTitle%,#4 If,".#6#7#8.",NotEqual,"..",run,%API%,ShortcutOptions,#1,#2,#3,#4,#5,#6,#7,#8 run,%API%,AddShortcut_#1,#1,#2,#3,#4,#5,#6,#7,#8 [AddShortcut_] run,%API%,AddShortcut_StartMenu,#1,#2,#3,#4,#5,#6,#7,#8 [AddShortcut_Desktop] If,#3,Equal,,Run,%BuildModelScript%,Add-Shortcut,"DE","%PE_Programs%\%programFolder%\%programExe%","#4","-SW:%PE_Programs%\%programFolder%%OptionShortcut%" If,#3,NotEqual,,Run,%BuildModelScript%,Add-Shortcut,"DE","#3","#4","-SW:%My_Shortcut_FOLDER%%OptionShortcut%" [AddShortcut_StartMenu] If,#2,Equal,,StrFormat,filename,%Scriptdir%,%Dir_Name% If,#2,Equal,,If,ExistFile,"%ProjectDir%\Apps\FolderName.ini",IniRead,"%ProjectDir%\Apps\FolderName.ini","FolderName","%Dir_Name%",#2 If,#2,Equal,,StrFormat,filename,%Scriptdir%,#2 If,#3,Equal,,Run,%BuildModelScript%,Add-Shortcut,"SM\#2","%PE_Programs%\%programFolder%\%programExe%","#4","-SW:%PE_Programs%\%programFolder%%OptionShortcut%" If,#3,NotEqual,,Run,%BuildModelScript%,Add-Shortcut,"SM\#2","#3","#4","-SW:%My_Shortcut_FOLDER%%OptionShortcut%" [AddShortcut_QuickLaunch] If,#3,Equal,,Run,%BuildModelScript%,Add-Shortcut,"QL","%PE_Programs%\%programFolder%\%programExe%","#4","-SW:%PE_Programs%\%programFolder%%OptionShortcut%" If,#3,NotEqual,,Run,%BuildModelScript%,Add-Shortcut,"QL","#3","#4","-SW:%My_Shortcut_FOLDER%%OptionShortcut%" [AddShortcut_AutoRun] run,%API%,AddShortcut_AutoStart,#1,#2,#3,#4,#5,#6,#7,#8 [AddShortcut_AutoStart] If,#3,Equal,,Run,%BuildModelScript%,Add-Shortcut,"AU","%PE_Programs%\%programFolder%\%programExe%","#4","-SW:%PE_Programs%\%programFolder%%OptionShortcut%" If,#3,NotEqual,,Run,%BuildModelScript%,Add-Shortcut,"AU","#3","#4","-SW:%My_Shortcut_FOLDER%%OptionShortcut%" [AddShortcut_SendTo] If,#3,Equal,,Run,%BuildModelScript%,Add-Shortcut,"ST","%PE_Programs%\%programFolder%\%programExe%","#4","-SW:%PE_Programs%\%programFolder%%OptionShortcut%" If,#3,NotEqual,,Run,%BuildModelScript%,Add-Shortcut,"ST","#3","#4","-SW:%My_Shortcut_FOLDER%%OptionShortcut%" [ShortcutOptions] echo,"Add options " StrFormat,filename,,%shortcut_Parameters% StrFormat,filename,,%shortcut_IconFile% StrFormat,filename,,%shortcut_Show% If,#6,NotEqual,,Set,"%shortcut_Parameters%","#$q#$s#$q-SP:#6" If,#7,NotEqual,,If,#3,Equal,,Set,"%shortcut_IconFile%","#$q#$s#$q-SF:%PE_Programs%\%programFolder%\#7#$q#$s#$q-SI:0" If,#7,NotEqual,,If,#3,NotEqual,,Set,"%shortcut_IconFile%","#$q#$s#$q-SF:%My_Shortcut_FOLDER%#7#$q#$s#$q-SI:0" If,#8,Equal,1,Set,"%shortcut_Show%","#$q#$s#$q-SS:SW_SHOW" If,#8,Equal,2,Set,"%shortcut_Show%","#$q#$s#$q-SS:SW_SHOWMINIMIZED" If,#8,Equal,3,Set,"%shortcut_Show%","#$q#$s#$q-SS:SW_SHOWMAXIMIZED" If,#8,Equal,4,Set,"%shortcut_Show%","#$q#$s#$q-SS:SW_HIDE" System,RefreshVars Set,"%OptionShortcut%","%shortcut_Parameters%%shortcut_IconFile%%shortcut_Show%" echo,"OptionShortcut=%OptionShortcut%" ############################################################################### [demo usage] Add_Shortcut Add_Shortcut,StartMenu Add_Shortcut,StartMenu,Games Add_Shortcut,QuickLaunch Add_Shortcut,AutoStart Add_Shortcut,Desktop require_file,myLibrary.dll unpack unpack,AnotherFolder unpack,#1,#2,#3 #1=AnotherFolder #2=Archive.7z,zip,rar #3=Param for silent install when archive is an exe SFX hive_load,HKU hive_unload,HKU reg_add,0x1,"%reg%\Classes\filetype","test","1" associate_file,html associate_file,html,open,c:\test.exe associate_file,html,open,c:\test.exe,/run=%2 associate_file,html,edit associate_file,html,icon,c:\test.exe associate_file,html,icon,%systemroot%\System32\Shell32.dll,-153 Use Add_Asso when there is a lot associate to do , process is more speed but require to use hive_load and hive_unload hive_load,HKU Add_Asso,bmp Add_Asso,jpg hive_unload,HKU CopyProgram,%FileBox_Source% CopyProgram,%FileBox_Source%,%Target_Prog%\%ProgramFolder%,%ProgramExe% [history] 070513 - api.script was created. 070718 - added function "require" (extract/check if system files are available and expand from source if needed - added syntax guide inside script.project from livexp - added %HKLM% and %HKCU% to write registry keys - added %source_win%, %target_win%, %source_sys%, %target_sys% that allow access work folders under most situations (supports both Install CD files or Installed windows dirs) 070723 - added support for creating start menu items based on the folder where the script is placed 070723 - hive_load and hive_unload commands added to support HKCU,HKU and HKLM 070723 - reg_add command added with support for internal and external hive registry writes 070723 - association command was also added to bring support to file associations 070724 - added support to add association to any other files along with custom parameters and custom icons (like shell32.dll,-153) 070724 - unpack was made simpler also extracting from any folder when specified 070725 - add_shortcut can now create shortcuts for other files, also added support for parameters 071020 - added Add_Asso and CopyProgram 080127 - correct error in associate find by galapo 080210 - suppress "System,RefreshVars" in [reg_hiveload] -added Calculate for running AutoIt command line (need sCalculate.exe by Nikzzzz in %Tools% folder) -added reg_del=RegDelete,"%HIVE_BASE%" ( ask by Galapo) -added _FileCopy,[Source],[Target] 080220 - Little change in Unpack , now archive are directly unziped in target so param 3 is use only for SFX archive no effect for archive .7z .zip or .rar 080308 - Added in Shortcut possibility to translate folder name of application only when param 2 is not specified it look in %ProjectDir%\Apps\FolderName.ini in section FolderName if key [My folder=Mon Dossier] exist [InterfaceEncoded] Update_Api.txt=471bytes,628bytes [EncodedFolders] Folder [Folder] [EncodedFile-InterfaceEncoded-Update_Api.txt] lines=0 0=eJx1kstOwzAQRfeW/BNI3gUWVEJssihpUSsKqhoeC4IsE09SizQOtkPp3zNOUmJRscvccz2PzLw+C6PEewX2jRLmhCnB8b2qWcweu2CmDMuWk+urEduDPcVZerAOdpNL9FndmhyGNGkXhGkG3Kc5xX1ivja6ZDHG63n3bcTOdvFi+Tzni7vVPb4OOsosuLYxUF5s1ddoS57+2BJdF6rMJBSirdxo/MdndeH2wsDReDNN5yz25VHBahyHbli8fz/HstBrLItHlFEylZKnW21c3rp409YRm66XLEL5qFKygc9WGeC3qoLY/Hrm342oJS9QpeSpbkT+EWSYgRco8aV5pYUMXvoGvO7lwdHW/3h6QImPhZTxBsoXoxxEZ8HQZz2XUHk+gwpODcJanSvhoOs4qCQ1/2WUPGjHE71rhFN4esFACEadEtx7DtbiaGVvSnOjGrfCy4gGdo6MkkQ3h+FIgqJePd5Ov4Up9hBuYGhJ6ZqS7tf7J38zeN0iT0SVtxUOEBqOGiU/KhsXAXic4wstSEksSY13LMjUK6koYRgFIwt4M0PoLkbs8oL6/6oZmAC8JQgNFLTWIwEAAAACAAAAKQAAAIoBAAAAAAAAAQAAAAAAAAAAAAAA