When creating a portable application you will often find that using relative paths instead of absolute ones spares a lot of time and hard work. The problem is that not every software supports relative paths, so you have to check it first.
Definition of absolute and relative paths (from Wiki):
A full path or absolute path is a path that points to the same location on one file system regardless of the working directory or combined paths.
A relative path is a path relative to the current working directory, so the full absolute path may not need to be given.
For example, an absolute path looks like this: “C:WindowsSystem32″. It must contain a drive letter.
A relative path does not contain the drive letter: “WindowsSystem32″. It is relative to the current working directory, so in this example you “must be” in drive C. If you “are” in “D:Music” and use the relative path above, it will be interpreted as “D:MusicWindowsSystem32″. So, relative path is dependent from the current working directory.
In most cases, paths in the registry must be absolute paths otherwise the software will not run correctly or won’t run at all.
You can define relative paths in several ways. The two you will find useful when creating portables are these:
. = refers to the current directory
.. = refers to the parent directory
In some cases you shouldn’t create a launcher to make a software portable. I’ll demonstrate it on a software called Wings 3D, which is a great subdivision modeler software (freeware).
I will not begin the install process with Total Uninstall now, because I want only show you how to turn a software portable with changing absolute paths to relative ones in the program’s settings.
So install Wings 3D (“InstallWings 3Dwings-0.98.32a.exe”), then go to the directory where you’ve installed it (you’ll find it probably in “C:Program Fileswings3d_0.98.32a” directory. The directory settings of the program is in the “bin” directory, in “erl.ini” file. Open it with a text editor. Its contents should look like this:
[erlang]
Bindir=C:Program Fileswings3d_0.98.32abin
Progname=erl
Rootdir=C:Program Fileswings3d_0.98.32a
The paths of Bindir and Rootdir is given with absolute paths. Note that these paths are not ordinary paths because two backslashes are in it instead of only one. It is important to notice because we should modify it taking this fact into account.
First, we have to find the .exe file, because the directory where it is located will be the root directory, and relative paths need a root directory.
The .exe file now is Wings3D.exe. The Bindir is the directory “bin” and the Rootdir is the root directory (where the .exe is located).
So normally the modified erl.ini should look like this:
[erlang]
Bindir=.bin
Progname=erl
Rootdir=.
But if we save it this way, Wings3D will not run. Now remember that there was two backslashes in the original erl.ini instead of one, so change erl.ini this way:
[erlang]
Bindir=.bin
Progname=erl
Rootdir=.
Save it and see if it works (it should).
Note: you can refer to the current directory with a single point (.). So changing Rootdir to “Rootdir=.” will work also. In some cases, when referring to a child directory, you can simply refer it with the directory’s name, no need to use points and backslashes. It works here also; change “Bindir=.bin” to “Bindir=bin” and it will work also.
In the previous chapter you saw that with NSIS it is really easy to create paths relative to the launcher. For example, “$EXEDIR” refers to the current directory, “$EXEDIR..” refers to the parent directory of the launcher. But you can use other ones also, for example: “$WINDIR”=Windows directory, “$PROGRAMFILES”=Program files directory, and so on (see “TemplatesNSIS directories.txt”).
The beauty of these is that you shouldn’t bother with drive letters. For example, if you have to copy a file into the Windows directory but on the target computer it is not on drive C but, for example, on “Y:wheretoinstallthisWindows”, it will be copied there using “$WINDIR”.
You can imagine that it is really handy if you want to refer to the user’s application data folder, because the name of the user vary on every computer. But using “$APPDATA” in NSIS eliminates this problem.
This example is only for showing you how to use relative paths. If you wish to make Wings3D (or any other software) portable, you should check with Total Uninstall that what changes were made during the install process, and create a launcher (wrapper) if it is necessary.
In fact, Wings3D creates a directory in the Application Data “C:Documents and SettingsYOURNAMEApplication DataWings3D” and a text file in it called “Preferences.txt”. If you wish to make it portable, you should handle this text file somehow (see topic “File Management” in this chapter).
[...] 1. Relative Paths [...]