Hi all,
for tools such as pre-processors it can be important to know the PB installation folder. When executing a program from the IDE, the folder is
Code: Select all
#PB_Compiler_Home
//edit 2009-03-17: new code
Code: Select all
#SLASH_CHARS$ = "/\"
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
#PB_IDE$ = "purebasic.exe" ; file name relative to #PB_COMPILER_HOME
CompilerCase #PB_OS_Linux
#PB_IDE$ = "compilers/purebasic"
CompilerEndSelect
Procedure.s GetPBFolder()
; returns the absolute path of the PB installation directory
; (with trailing slash)
CompilerIf #PB_Compiler_Debugger
; The program runs as source code in the IDE with debugger on.
ProcedureReturn #PB_Compiler_Home
CompilerElse ; EXE file
Protected folder$
; First look whether the program runs as IDE tool.
folder$ = GetEnvironmentVariable("PB_TOOLS_IDE")
If folder$
ProcedureReturn Left(folder$, Len(folder$)-Len(#PB_IDE$))
EndIf
; Look for a regarding environment variable on the system.
folder$ = GetEnvironmentVariable("PUREBASIC_HOME")
If folder$
If FindString(#SLASH_CHARS$, Right(folder$,1),1) = 0
folder$ + "/"
EndIf
ProcedureReturn folder$
EndIf
; The program runs as standalone program, and the environment variable PUREBASIC_HOME is not set.
; In this case, the executable file must be in a SUBDIRECTORY of the PB installation directory.
folder$ = GetPathPart(ProgramFilename())
Repeat
folder$ = GetPathPart(Left(folder$, Len(folder$)-1)) ; parent folder
If folder$ = ""
Break
EndIf
Until FileSize(folder$ + #PB_IDE$) > 0
ProcedureReturn folder$
CompilerEndIf
EndProcedure