Jump to content











Photo
- - - - -

Common API for projects


  • Please log in to reply
72 replies to this topic

#1 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 May 2007 - 02:52 PM

Hi everyone!

This topic is meant to discuss the implementation of a common API (Application Programming Interface) which enables developers to create their scripts in a simpler way.


One pratical use of an API is the reduction of code lines needed to get tasks done like creating shortcuts for example and the simplification of coding making it easier to understand for others.

Also worth mentioning that using common functions also enables scripts to survive longer to overall project changes, meaning that a script done today will probably still work next year if a common method is adopted.

Please note that this API is mostly meant for Application scripts - the scripts which are supposed to add third party programs already supported on different platforms like Win9x, WinXP and Vista.

Both nativeEx and VistaPE already have their built-in API which is already used for some of the tasks described here - but we should work to create a common set of functions that can be used on both projects and eventually on the next projects to appear.


Flexibility and Expandability are good keywords to describe the future of these scripts.


So let the discussion start and see if we can in fact achieve this goal.





How do we build an API function under WinBuilder?

Using the [variables] section from the script.project file on each project it is possible to define new "commands" - so imagine this example:

[variables]

MakeDesktopShortcut=run,%API%,CreateDesktopShortcut

on the %API% file:
[CreateDesktopShortcut]

....

...

..

and while running:
[process]

MakeDesktopShortcut,This is an Example,myExampleFolder\myExample.exe


Or even a FileCopyExpand command which looks for a file from txtsetup.sif and decides whether to Cab Extract or copy the file from source.

There are a lot of ways to use this API and the best part is that Application scripts could then be used on any supported projects without much worries.

Meaning also that .script developers code once and others can use it on the project they prefer without changes..

-------------------------------------------------------------------------------------------

Proposed API

Global Variables
%Shell% - to know which shell is being used (using explorer as default)


Functions
Shortcut_Desktop - to create shortcut on desktop
Shortcut_StartMenu - same as above for Start Menu (allows to specify folder)
Shortcut_Startup - Add shortcut on startup list

Files_Extract - Extract all files inside the script on "folder" to the programs's folder

---------------------------------------------------------------------------------------------

Script Template


[variables]
%application%=myExample.exe
%shortcut_name%=This is my Example
%application_dir%=myExampleDir


[process]
Shortcut_Desktop
Shortcut_StartMenu,Applications
Files_Extract
---------------------------------------------------------------------------------------------



What does the community think about this?

Edited by Nuno Brito, 06 May 2007 - 06:40 PM.


#2 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 05 May 2007 - 03:07 PM

Using the [variables] section from the script.project file on each project it is possible to define new "commands" - so imagine this example:

[variables]

  MakeDesktopShortcut=run,%API%,CreateDesktopShortcut

I'm very sure that it should be the [variables] section of WinBuilder.ini, in order to pass between projects.
For different code in different project types we use Nunos %ProjectType% suggestion.

Or ????

Peter

#3 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 May 2007 - 03:11 PM

It should probably be inside script.project because "run,%API%,CreateDesktopShortcut" could allow to be adapted for each project needs - and some projects might not even implement the whole common API for their own specific reasons.

:confused1:

#4 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 05 May 2007 - 03:15 PM

Or even a FileCopyExpand command which looks for a file from txtsetup.sif and decides whether to Cab Extract or copy the file from source.

As a practical sample: This is what I already use, but not yet published:
[process]

// basic files, compressed to target

echo,"Copying Driver files.."

Run,%ScriptFile%,Load-Driver,acpi.sy

...
[Load-Driver]

If,ExistFile,"%SourceDir%\I386\%spFile%",ShellExecute,"hide","expand.exe","#$q%SourceDir%\I386\%spFile%#$q -F:#1s #$q%TargetDir%\i386\system32\drivers#$q"

If,NotExistFile,"%TargetDir%\i386\system32\drivers\#1s",ShellExecute,"hide","expand.exe","#$q%SourceDir%\I386\%drFile%#$q -F:#1s #$q%TargetDir%\i386\system32\drivers1#$q"

If,NotExistFile,%TargetDir%\i386\system32\drivers\#1s,If,ExistFile,"%SourceDir%\I386\#1_",Expand,"%SourceDir%\I386\#1_","%TargetDir%\i386\system32\drivers"

If,NotExistFile,%TargetDir%\i386\system32\drivers\#1s,FileCopy,"%SourceDir%\I386\#1s","%TargetDir%\i386\system32\drivers"

If,NotExistFile,%TargetDir%\i386\system32\drivers\#1s,echo,"Missing: #1s"

Of course that does not match Nuno's global definition, but could be made simply to match it.

Peter

#5 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 05 May 2007 - 03:20 PM

It should probably be inside script.project because "run,%API%,CreateDesktopShortcut" could allow to be adapted for each project needs - and some projects might not even implement the whole common API for their own specific reasons.

:confused1:


We can also use the following command in every script that we want to use the api commands:
AddVariables,"%Api%","ApiCommands"

Where %Api% is a variable holding the path to the api script and ApiCommands is a Variables section, renamed to ApiCommands .

So you can declare in a script many apis with only one command.

#6 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 May 2007 - 03:30 PM

Those are very good ideas - the sort of things that really pushes coding forward.. :confused1:

#7 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 05 May 2007 - 04:47 PM

Those are very good ideas - the sort of things that really pushes coding forward.. :confused1:

:confused1:
But please, have a look at my signature

Peter :confused1:

#8 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 06 May 2007 - 06:37 PM

Posted on first topic a few API suggestions.. :confused1:

#9 NightMan

NightMan

    Frequent Member

  • .script developer
  • 433 posts
  • Location:Russian, Moscow

Posted 07 May 2007 - 02:01 PM

HELLO!

Common API is very good idea, recently i thik how make scripts for programs is more simple and my ideas is very closely with yours :confused1:

For program scripts we are really need:
0. program name :confused1:
1. executable name ("sample.exe" or "folder\sample.exe")
2. program source folder (or archive name, or ...)
3. startup parameters ("/1234")
4. where place shortcut (desktop, start menu, quick lanch)
5. program category (antivirus, disk tools and etc)
6. registry setting (reg file or command at WB language)
7. common files (dll) from distributive
8. autorun commands...
9. program icon file
10. target type (RAM or CD)
11. target folder (may be == program name)

:confused1:

How it will be work :confused1:

[process]

Echo,"Processing program name..."

CopyApp,executable name,program source folder,target type\target folder

Extract,acrhive name,target type\target folder

Shortcut,"StartMenu\program category\program name","target type\target folder\executable name","startup parameters","program icon file"

Shortcut,"DeskTop\program category\program name","target type\target folder\executable name","startup parameters","program icon file"

AutoRun,target type\target folder\executable name,startup parameters

CopyRegSetting,source,target

AddRegFile,reg file

CopyApp - check source folder and copy program :confused1:

it's very very basic :confused1:

Next think :confused1:

Will be very good idea create program for searching all programs on computer and automatically make scripts for known programs, we need make only one big ini (or xml) file with setting and descriptions for all program and all other will be automatically :confused1:

#10 NightMan

NightMan

    Frequent Member

  • .script developer
  • 433 posts
  • Location:Russian, Moscow

Posted 07 May 2007 - 07:28 PM

Nuno Brito

:confused1:

[variables]
MakeDesktopShortcut=run,%API%,CreateDesktopShortcut

it's not working (WB 068 and 069 beta6)

[variables]

%MakeDesktopShortcut%=run,%API%,CreateDesktopShortcut
it's working good, but looking not very good :confused1:

#11 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 07 May 2007 - 08:38 PM

Thanks for joining our talks!! :confused1:

I will test it and see why it isn't working.. :confused1:

#12 Alexei

Alexei

    Silver Member

  • .script developer
  • 664 posts

Posted 08 May 2007 - 01:31 PM

APIs are good :confused1:
The only "danger" is to make them "too convenient" :confused1: What I mean is that it should be small, but complete set of APIs.
The principle I use in such situations: simple things - easy, but tricky stuff - hard.
What I mean is that doing something in a "wrong way" should be not easy, just because there is no API for it :confused1:
:confused1:
Alexei

#13 NightMan

NightMan

    Frequent Member

  • .script developer
  • 433 posts
  • Location:Russian, Moscow

Posted 15 May 2007 - 01:48 PM

[url="http://www.boot-land.net/forums/Future-pro...-API-t2198.html"]http://www.boot-land...-API-t2198.html[/url]

What do you think? :confused1:

#14 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 18 May 2007 - 10:27 PM

Hi,

I've continued my testings with API and started with the very most simple functions expected from an application script - create one or two shortcuts and extract all files inside the script into the respective folder.


Using sudoku as template, we can use something like this:

[variables]

%ProgramTitle%=Sudoku

%ProgramEXE%=sudoku.exe

%ProgramFolder%=Sudoku



[process]

Add_Shortcut,Desktop

Add_Shortcut,AutoStart

Add_Shortcut,StartMenu,Games and Fun

unpack


Inside script.project:
[variables]

%api%=%projectdir%\Basic\Build\api.script

Add_Shortcut=Run,%api%,AddShortcut

Unpack=Run,%api%,depack

Inside api.script:
[AddShortcut]

echo,""

echo,"API - Creating a new shortcut for %programTitle%.. [%programFolder%\%programExe%]"

If,#1,Equal,,Set,"%shortcut_type%","DE"

If,#1,Equal,Desktop,Set,"%shortcut_type%","DE"

If,#1,Equal,StartMenu,Set,"%shortcut_type%","SM"

If,#1,Equal,QuickLaunch,Set,"%shortcut_type%","QL"

If,#1,Equal,AutoStart,Set,"%shortcut_type%","AU"

Run,%BuildModelScript%,Add-Shortcut,"%shortcut_type%\#2","#$pProgramFiles#$p\%programFolder%\%programExe%","%ProgramTitle%","-SW:#$pProgramFiles#$p\%programFolder%"



[depack]

echo,"API - Unpacking files and settings.."

IniRead,"%ProjectInfo%","TargetPaths","Program_Files",%WorkDir%

Run,%api%,depack_extract,#1



[depack_extract]

If,#1,Equal,,Set,"%folder_name%","Folder"

If,#1,NotEqual,,Set,"%folder_name%","#1"

//

DirMake,"%targetDir%\%workDir%"

DirMake,"%targetDir%\%workDir%\%ProgramFolder%"

echo,"Extracting %ProgramTitle%.."

ExtractAllFiles,"%ScriptFile%","%folder_name%","%targetDir%\%workDir%\%ProgramFolder%"



The overall idea is to stay away from any modification on the interface section and keep scripts very flexible until this part is properly discussed.

These shortcuts are very customizable and easy to add, you can Add_Shortcut for just adding an icon on desktop, use Add_Shortcut,StartMenu to add an entry on start menu or use Add_Shortcut,StartMenu,Games and Fun to be specific on which folder inside the start menu it should be grouped.

Other type of shortcuts are possible such as AutoStart and QuickLaunch which are all provided internally by BuildModel on nativeEx.


Now the goal is providing these same two functions for VistaPE - which I will be the next step if time allows or perhaps Nighman has some time to work them for properly working under VistaPE.


I'm not covering any file copy functions or checking the support for using other shells (yet), just the basic API steps to add files inside a script and then extract them inside the folder.


Notice that unpack is very flexible and can be adapted for more tasks than just extracting files, at this moment it extract all files inside a specified encoded folder into the program folder - if none is specified then it will use the "Folder" as default.

No checks are done, but this should only be added inside the API to keep the template script as uncluttered as possible. Users shouldn't have to add too many items, just the basic information is more than enough for most cases. If a script is more advanced and requires other features, then the developer should also be able to create his scripts understanding the basis of this API and then we can also move to more advanced functions.


Also remember that adding more variables on script.project files only make the whole project gets slower performance since the variables list will become bigger and sluggier - so there should be as less "fixed" variables as possible.




You can also download api.script, just place it on %projectdir%\Basic\Build

:confused1:

Attached Files



#15 NightMan

NightMan

    Frequent Member

  • .script developer
  • 433 posts
  • Location:Russian, Moscow

Posted 20 May 2007 - 08:11 PM

Hello Nuno Brito!!!

First, BIG BIG THANKS! :confused1:

(it's anwer to your personal messenger)

-------------------------------------------------------------

Second, i can not send PM to you:
This message can not be sent because the recipient has their personal messenger disabled 

or they are in a member group not allowed to use the personal messenger.



This personal message has not been sent


ps i have some questions about API, but only in PM :confused1:

#16 thunn

thunn

    Silver Member

  • .script developer
  • 531 posts
  • Location:Brooklyn, New York
  • Interests:computers<br />mechanics<br />distortion<br /><br />
  •  
    United States

Posted 20 May 2007 - 10:38 PM

Likewise, cannot send any PM to Nuno.. :confused1:

#17 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 05 June 2007 - 11:57 AM

To solve the issues Sherpya has (see here), I created two new API commands:

Copy_Expand,#1,#2,#3
//#1: source file with missing 3rd character in extention
//#2: 3rd character in extention
//#3: target directory

If in the source there is a compressed file, it is decompressed and copied to the target
If in the source there is an uncompressed file, it is just copied to the target

Copy_Both,#1,#2,#3
//#1: source file with missing 3rd character in extention
//#2: 3rd character in extention
//#3: target directory

The file is copied to the target, idependent whether it is compressed or not.

To implement these functions, you need:
  • Add to script.Project:
    &#91;Variables&#93;
    
    ...
    
    Copy_Expand=Run,%api%,CopyOrExpand
    
    Copy_Both=Run,%api%,CopyBoth
  • Add to api.script:
    &#91;CopyOrExpand&#93;
    
    //#1&#58; source file with missing 3rd character in extention
    
    //#2&#58; 3rd character in ectention
    
    //#3&#58; target directory
    
    If,ExistFile,#1_,Expand,#1_,#3
    
    If,NotExistFile,#1_,FileCopy,#1#2,#3
    
    
    
    &#91;CopyBoth&#93;
    
    //#1&#58; source file with missing 3rd character in extention
    
    //#2&#58; 3rd character in ectention
    
    //#3&#58; target directory
    
    If,ExistFile,#1_,FileCopy,#1_,#3
    
    If,NotExistFile,#1_,FileCopy,#1#2,#3
The new API functions are actually used in nativeEx_barebone, Copy%Expand script.

Peter

#18 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 June 2007 - 04:25 PM

Good work, but we still need a way to support x64 sources..

These sources seem quite similar to x86 but use an AMD64 folder to fetch specific files - would be preferable to read txtsetup.sif to know from where the file should be copied or expanded since this is the "roadmap" to let us know which configuration is correct for the source to work and thus leading to a more reliable method..

Maybe a small binary to speed up txtsetup interpretation? :1st:

:thumbup:

#19 thunn

thunn

    Silver Member

  • .script developer
  • 531 posts
  • Location:Brooklyn, New York
  • Interests:computers<br />mechanics<br />distortion<br /><br />
  •  
    United States

Posted 05 June 2007 - 04:34 PM

Nuno,
a little off topic, but--
Do you have a command that mirrors the funtionality of the NT cmdline "&&"? :1st:
Using "&&", statement is only exicuted if it will work, else no error. (Of course it follows something on the same line)

Some of my scripts use multiple IF statements in one line.

#20 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 05 June 2007 - 04:41 PM

Good work, but we still need a way to support x64 sources..

These sources seem quite similar to x86 but use an AMD64 folder to fetch specific files - would be preferable to read txtsetup.sif to know from where the file should be copied or expanded since this is the "roadmap" to let us know which configuration is correct for the source to work and thus leading to a more reliable method..

Maybe a small binary to speed up txtsetup interpretation? :1st:

:thumbup:


Can you post a txtsetup.sif with reference to such x64 folder?
And the source directory structure of a x64 CD?
I do not have one.

Peter

#21 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 05 June 2007 - 04:46 PM

Can you post a txtsetup.sif with reference to such x64 folder?
And the source directory structure of a x64 CD?
I do not have one.

Peter


What Nuno suggests ,is not posible because txtsetup.sif is in the AMD64folder and not in i386

#22 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 June 2007 - 11:13 PM

Nuno,
a little off topic, but--
Do you have a command that mirrors the funtionality of the NT cmdline "&&"? :1st:
Using "&&", statement is only exicuted if it will work, else no error. (Of course it follows something on the same line)

Some of my scripts use multiple IF statements in one line.


Would you mind posting this request as a new topic?

This way we can discuss it further and see if a good solution can be found - I know it can be coded, but I'm just a bit unsure about enough time to implement it properly.. :thumbup:

Please bump this new topic after the next beta when I hope to have finished recoding the download methods.. :thumbup:


Can you post a txtsetup.sif with reference to such x64 folder?
And the source directory structure of a x64 CD?
I do not have one.

Peter


Unfortunately I don't have any source here at home - never also needed to use any x64 install CD so I've based my comment on holger's feedback from here: http://www.boot-land...?...ost&p=14365 and wrongly assumed the same location for txtsetup.sif based on setupldr.bin which is also present on I386 folders.. :thumbup:

Holger also refers that you can download a x64 2003 trial from MS and test on vmware.. :thumbup:


Smiley - thanks for the correction, do you know from where we can read the location of txtsetup.sif on the source disk? :thumbup:

Thanks! :thumbup:

#23 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 06 June 2007 - 08:25 AM

thanks for the correction, do you know from where we can read the location of txtsetup.sif on the source disk? :1st:


Well, txtsetup.sif must be in one of the three folders: i386 , amd64 and ia64. A simple if command can solve this.

If,ExistFile,&#34;%SourceDir%\i386\txtsetup.sif&#34;,Set,&#34;%Architecture%&#34;,&#34;i386&#34;

If,ExistFile,&#34;%SourceDir%\amd64\txtsetup.sif&#34;,Set,&#34;%Architecture%&#34;,&#34;amd64&#34;

If,ExistFile,&#34;%SourceDir%\ia64\txtsetup.sif&#34;,Set,&#34;%Architecture%&#34;,&#34;ia64&#34;

If,%Architecture%,Equal,&#34;&#34;,Halt,&#34;Invalid source!&#34;

IniWrite,&#34;%ProjectDir%\script.project&#34;,&#34;Variables&#34;,&#34;#$pArchitecture#$p&#34;,&#34;%Architecture%&#34;

IniWrite,&#34;%ProjectDir%\script.project&#34;,&#34;Variables&#34;,&#34;#$pArchSource#$p&#34;,&#34;#$pSourceDir#$p\#$pArchitecture#$p&#34;

System,RefreshVars

This should work fine define foundamentals. So every script know where to find the files it needs with the %ArchSource% variable.


Can you also have a look at my api project that I posted here?

#24 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 06 June 2007 - 12:10 PM

@smiley:

I tested (and debugged a little bit :thumbup: ):

Result: :1st:

One question:

Why putting the main definitions into [ApiDeclarations] of ProjectApi.script and not into [Variables] of script.project?

Peter

#25 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 06 June 2007 - 12:27 PM

Why putting the main definitions into [ApiDeclarations] of ProjectApi.script and not into [Variables] of script.project?


Because they have to be cleaned at every run. If I put it on script.project I have to delete one by one the api entries wile now I just only have to delete this section and delte it from scrach.

My first idea was that every script should be able to write an api in thelist so it can be used by other scripts. If this happen it will be impossible to clean up completely.




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users