Install directory relative to another - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Blueberry
Posts: 5
Joined: Tue Feb 07, 2012 7:46 am

Install directory relative to another

Dear,

There is a problem which I can't solve... I have a directory which should be installed relative to the [APPDIR]. I made a property named 'AUTOUPDATEPATH' with value '[|APPDIR]' in beginning of installation. In the Begin-Event I change it to '[APPDIR]..\AutoUpdate', when i try to install it, it just says "The folder path '..' contains invalid characters."
I have no idea how to solve this problem...
Thanks for help!

best regards
Blueberry
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Install directory relative to another

Hi and welcome to Advanced Installer forums,

Please keep in mind this attempt to reference paths relative to the application folder is not correct. Here's the recommended and correct approach to installing in a custom folder:
http://www.advancedinstaller.com/user-g ... older.html

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Blueberry
Posts: 5
Joined: Tue Feb 07, 2012 7:46 am

Re: Install directory relative to another

Hi mihai.petcu

I know what you mean, but I have to install the second application as follow:
If the user choose "C:\Program Files (x86)\FirstProduct" I have to install the AutoUpdater at "C:\Program Files (x86)\AutoUpdate", that's why I need a relative path to APPDIR... Is there a VBScript which can do that?
Thanks for help!

best regards
Blueberry
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Install directory relative to another

Hello,

In this case, you can try to set the APPDIR to the Program Files folder and add the two subdirectories to it.
If you don't want the user to see choose the parent folder, you can trim the APPDIR within your own UI custom action. You can schedule this custom action before the SetTargetPath event on the "Next" button.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Blueberry
Posts: 5
Joined: Tue Feb 07, 2012 7:46 am

Re: Install directory relative to another

Okay, I have solved the Problem by using a VBScript:

DIM param, symPos, prop

'Get Parameter (Property name/In custom Action it's the Action Data) and resolve it.
param = Session.Property("CustomActionData")
prop = Session.Property(param)

'May be the string ends with '\' if not it doesn't matter if I cut one char away.
prop = Left(prop, Len(prop) - 1)

'Get Position of the last '\' and replace the whole path-string with the substring 0 to position of last '\'
symPos = InStrRev(prop, "\")
prop = Left(prop, symPos)

'Set Property to new value
Session.Property(param) = prop

Now I can call this Script with "AUTOUPDATEAPPDIR" in Action Data. So I get the Parant-Directory

best regards

Blueberry
Blueberry
Posts: 5
Joined: Tue Feb 07, 2012 7:46 am

Re: Install directory relative to another

I wrote a new VBScript which resolves relative paths and assign the new value to the delivered property, further down you can see the new script:
if you call this script via Advanced Installer you have to type follow into the ActionData-Field: "PropertyName|RelativePath" (without "") as example you can Type: "SecondAppDir|[APPDIR]..\..\SecAppDir" (without "") and it will resolve the path and assign it to the property SecondAppDir. If the delivered path isn't relative it just assign it to the property and will exit then.

Code: Select all

Dim params, prop, path, splitPath, endsWithBack, elmCounter

' ActionData abrufen und spliten
params = Split( Session.Property("CustomActionData"), "|", 2)

' Parameter zuweisen
prop = params(0)
path = params(1)

' Prüfen, ob es mit einem Backslash endet
If Right(path, 1) = "\" Then
	endsWithBack = 1
Else
	endsWithBack = 0
End If

' Prüfen, ob es ein relativer Pfad ist
If InStr(path, "\..") > 1 Then
	' Splitten und iterieren
	splitPath = Split(path, "\")
	For i = 0 to (UBound(splitPath) - 1)
		' Falls es ein ".." ist, muss das zu ersetzende Element ermittelt und geleert werden
		' zusätzlich muss man das momentane Element auch leeren, damit es beim zusammensetzen
		' nicht wieder relativ wird.
		If splitPath(i) = ".." then
			elmCounter = 1
			While splitPath(i - elmCounter) = ""
				elmCounter = elmCounter + 1
			Wend
			splitPath(i - elmCounter) = ""
			splitPath(i) = ""
		End If
	Next
	' Nach dem alle relativen Teile aufgelöst wurden,
	' wird der Pfad jetzt wieder zusammengesetzt.
	path = ""
	For Each pPath in splitPath
		If pPath <> "" Then
			path = path + pPath + "\"
		End If
	Next
	
	' Falls der Anfangspfad nicht mit einem Backslash endet,
	' wird dieser hier wieder abgeschnitten.
	If endsWithBack = 0 Then
		path = Left(path, Len(path) - 1)
	End If
End If

Session.Property(prop) = path
If somebody has a question, send me a PN or ask it here.

best regards

Blueberry
alco
Posts: 80
Joined: Thu Nov 18, 2010 5:02 pm

Re: Install directory relative to another

@Blueberry thanks for this hint, I was able to set APPDIR to the install location in my patch. For some reason unknown to me, APPDIR is empty on the start of patch execution.

Return to “Common Problems”