The Ultimate Portable Build - Part 1 - Relative Pathing hta

The end goal of everything I've been doing has been to be able to deliver the ultimate portable build. Over the next series of blog's we'll be looking at how we can use relative pathing that is usually associated with html together with our hta file so we can have a build that can be copied or activated from just about any location or situation. To go with this series, download the cadmanage.hta linked in this blog. Just remember to change the extension from txt to hta.

As with previous blogs I recommend notepadd++ for editing and BeyondCompare for file comparison.

When you open this hta you'll notice one thing straight away. That is I have added some vbscript at a higher level than normal. This has been done to help capture variables we will need later in the hta. The difference here over previous hta files we have reviewed is that there are no hard coded locations.

<SCRIPT language="VBScript">

Dim DRV_ROOT,BENTLEY_ROOT,AdminPath,AdminScriptsPath
Dim oWshShell,oMe,oMy,oEnv,MSpath

Set WshShell = CreateObject("WScript.Shell")
Set oEnv = WshShell.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set MSpath = createobject("Scripting.FileSystemObject")
Set SITE_ROOT = createobject("Scripting.FileSystemObject")
Set DRV_ROOT = createobject("Scripting.FileSystemObject")
Set ProjDrv = createobject("Scripting.FileSystemObject")
Set Bentley_Root = createobject("Scripting.FileSystemObject")


DRV_ROOT = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("..\.")
oEnv("hta_DRV_Root") = Replace(DRV_Root, "/", "\")
'msgbox DRV_Root

AdminPath = DRV_Root + "\_Admin\"
oEnv("hta_sAdminPath") = Replace(AdminPath, "/", "\")
AdminScriptsPath= AdminPath + "Scripts\"
'msgbox AdminScriptsPath
'msgbox AdminScriptsPath + "user_create_local.bat"

WshShell.Run AdminScriptsPath & "user_create_local.bat" ,0
WshShell.Run AdminScriptsPath & "std_cad.bat" ,0
WshShell.Run AdminScriptsPath & "std_cad_Link.bat" ,0

Site_Root = DRV_Root + "\Bentley\Site\"
SiteInstallList = Site_Root + "Site_Installs\SiteInstallPaths.txt"
oEnv("hta_sSite") = Replace(SITE_ROOT, "/", "\")

Bentley_Root = DRV_Root + "\Bentley\"
oEnv("hta_sBentley") = Replace(BENTLEY_ROOT, "/", "\")
'msgbox Bentley_Root

</SCRIPT>

The way this works is that all files and directory paths are derived from the location where the cadmanage.hta file is kept and launched from. For my build, I use a batch directory located as per the image below:


If you've even done a bit of html coding, this all works in a very similar fashion. I can use something like '..\' to go back a single or multiple directories and call up other files. In vbscript we can use the same html functionality to call up the base directory '_MyBuild' so that we can then set all other directories as required. This is done using:

DRV_ROOT = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("..\.")

This goes back a single directory and applies that relative path to the variable 'DRV_ROOT'.

You could go back 2 directories by using:

CM_ROOT = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("..\..\.") 

The path assigned will be a full path, thus our build becomes totally portable. this is because 'GetAbsolutePathName("..\.")' is taking the location one directory back from where CADmanage.hta is located. For example, if CADmanage.hta was in:

C:\_MyBuild\Batch\

Then 

DRV_ROOT = C:\_MyBuild\

Taking this further, if CADmanage.hta was in:

Z:\Engineering\_MyBuild\Batch\

Then 

DRV_ROOT = Z:\Engineering\_MyBuild\

All of this derived from where we started CADmanage.hta.

You can debug you variables at any time using:

msgbox DRV_Root

When the hta is started, a box will appear displaying what the variable has been assigned to.

All we've done for now is assign the location to a hta variable. we still need to set this as a session variable that can be used in our build. This is done by:

oEnv("hta_DRV_Root") = Replace(DRV_Root, "/", "\")

Remembering to set:

Set oEnv = WshShell.Environment("PROCESS")

as shown in the code above.

This means that 'hta_DRV_Root' becomes the variable we would call up in our cfg files in our build outside of the hta.

Now that we have our base build directory, we can go ahead and set the other locations we'll use in the build and in other files such as our batch files.

Set the admin path and run our build batch files (more on what the batch files do in later blog's):

AdminPath = DRV_Root + "\_Admin\"
oEnv("hta_sAdminPath") = Replace(AdminPath, "/", "\")
AdminScriptsPath= AdminPath + "Scripts\"
'msgbox AdminScriptsPath
'msgbox AdminScriptsPath + "user_create_local.bat"

WshShell.Run AdminScriptsPath & "user_create_local.bat" ,0
WshShell.Run AdminScriptsPath & "std_cad.bat" ,0
WshShell.Run AdminScriptsPath & "std_cad_Link.bat" ,0

using ,0 at the end of the run line for any batch file means the dos window is suppressed and will not be seen.

Now we set the 'Site_Root' to pick up our application installation paths:
Site_Root = DRV_Root + "\Bentley\Site\" 
SiteInstallList = Site_Root + "Site_Installs\SiteInstallPaths.txt"
oEnv("hta_sSite") = Replace(SITE_ROOT, "/", "\")

Lastly, we set the location of the Bentley directory that can then use used in the my_appl.cfg file to set the location for _USTN_SITE:
Bentley_Root = DRV_Root + "\Bentley\"
oEnv("hta_sBentley") = Replace(BENTLEY_ROOT, "/", "\")
'msgbox Bentley_Root

We now have all the building blocks in place to make our build truly portable. We've got a bit to go to cover all of our bases, but the hard work is done.

More soon.