How hta Changed the Way I Deliver Builds - Part 11 - Multiple Software Install Locations

For the next series of posts, download the hta example from:

http://communities.bentley.com/communities/everything_else_community/f/289/p/80102/220916.aspx#220916

Up until new we've stay away from variable driven application and stayed with fixed paths to get familiar with what to do. The reality is often very different, especially if you are dealing with multiple office who are still doing their own thing. Don't get me wrong, I'm all for standardisation, but the reality is there is always some transition period that has to be catered for. One of the worst of these are the install paths for the CAD software. 

It staggers me just how many different ways people come up with when it comes to installing a package over and above the standard. So, before we get them all on the same page we need to have the hta be able to find a way to identify where that is.

As always, check to make sure you have all variables defined and objects set or errors will occur, just follow the example hta to make sure you have everything covered.

The first thing we do is set a location where the hta can read the list of install location from and what variable that location is set to. We've done this by using:

SiteInstallList = "R:\_CADmanage\Bentley\Site\Site_Installs\SiteInstallPaths.txt"

The text file looks something like:

#-------------------------------------------------------------------------------------------------------
# Microstation V8 installs 
#-------------------------------------------------------------------------------------------------------
MS85,C:\Program Files (x86)\Bentley2004\
MS85,C:\Apps\Bentley\MS85\
MS85,C:\Program Files\Bentley\
MS85,C:\Program Files (x86)\Bentley\
#-------------------------------------------------------------------------------------------------------
# Microstation XM installs 
#-------------------------------------------------------------------------------------------------------
MS89,C:\Apps\Bentley\MS89\
MS89,C:\Program Files (x86)\Bentley\
MS89,C:\Program Files\BentleyXM\
#-------------------------------------------------------------------------------------------------------
# Microstation V8i installs
#-------------------------------------------------------------------------------------------------------
MS811,C:\Apps\Bentley\MS811_SS2\MicroStation V8i (SELECTseries)\
MS811,C:\Apps\Bentley\MS811_SS2\
MS811,C:\Program Files (x86)\Bentley811\MicroStation V8i SS2\
MS811,C:\Program Files (x86)\Bentley\Bentley811\MicroStation V8i SS2\
MS811,C:\Apps\Bentley\MS811\
MS811,C:\Program Files\Bentley811\MicroStation V8i SS2\
MS811,C:\Program Files\Bentley\MicroStation (SELECTseries)\
MS811,C:\Program Files\Bentley\MicroStation V8i (SELECTseries)\
MS811,C:\Program Files\Bentley\MicroStation V8i (SELECTseries 1)\
MS811,C:\Program Files (x86)\Bentley\MicroStation v8i (SELECTseries)\
MS811,C:\Program Files (x86)\Bentley\MicroStation V8i\

Word of warning here, do NOT leave empty lines between sections in the text file. This will be treated as an end point and further lines will not be read.

Next thing we do is set the code to read the text file from a sub and then loop until found. Once found this is then assigned to another variable. This looks like:

'------------------------------------------------------------------------------------------
' Get Primary Microstation Root Directories
'------------------------------------------------------------------------------------------
BentleyV8Root = (GetPath(SiteInstallList,"MS85"))
BentleyXMRoot = (GetPath(SiteInstallList,"MS89"))
BentleyV8iRoot = (GetPath(SiteInstallList,"MS811"))

Where 'GetPath' is calling up another sun in the hta which loops to find the correct path:

Function GetPath(TargetFile,targetval)

Dim objFSO,objFile,myFile,line,Result,TmpPath
Dim filesys, newfolder

myFile=(TargetFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
set filesys=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(myFile,1)


Do Until objFile.AtEndOfLine
line=objFile.ReadLine
If InStr(line,targetval) > 0 Then
Result=Split(line,",")
TmpPath= Result(1)
If filesys.FolderExists(TmpPath) Then
GetPath = TmpPath
' msgbox "FOUND " & TmpPath 
Exit Function
Else
'msgbox " Not Found " & TmpPath 
'msgbox TmpPath & " wasn't found"
GetPath="undefined"
End if
End If
Loop

Set objFSO=Nothing
Set objFile=Nothing
End Function

While you're debugging the hta and your text file, I would suggest opening up the line:

msgbox "FOUND " & TmpPath 

so you at least know your install paths have been found. You can always comment this line out later.

Now that we have the install paths for our software we can plug the variables into the rest of the hta to get the same functionality as we have started in the previous articles. One example of that is turning off the buttons if the software has not been found:

If BentleyV8IRoot = "undefined" then
startv8ibutton.disabled=True
startv8ibsbutton.disabled=True
startpwnavbutton.disabled=True
'msgbox "Microstation V8i installation not found"

End If

Again, you could open up the message box as an extra alert while you're debugging.

Same thing going for the start lines for your buttons. These now look like:

Sub StartV8i
If (oEnv("Phase")) <> "Legacy" Then 
objFSO.CopyFile SitePath + "MS811\Standards\data\std_appl.cfg" , BentleyV8iRoot + "MicroStation\config\appl\", OverwriteExisting
End If
If (oEnv("Phase")) <> "" Then 
WshShell.run chr(34) & (BentleyV8iRoot) & "MicroStation\ustation.exe" & chr(34)
Else
msgbox "Please Select a Phase first !"
End If
End Sub

Now we're starting to see some of the real power of the hta.

More soon.

Anonymous