Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ProgramPath to be overridable via an environment variable #17

Open
wants to merge 1 commit into
base: DelphiTokyo
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/xeMeta.pas
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ function StoreNodes(nodes: TDynViewNodeDatas): Cardinal;

{$region 'API functions'}
procedure InitXEdit; cdecl;
var
ProgramPath: String;
begin
// initialize variables
_store := TInterfaceList.Create;
Expand All @@ -302,8 +304,24 @@ procedure InitXEdit; cdecl;
// add welcome message
AddMessage('XEditLib v' + ProgramVersion);

// resolve program path; we allow the program path default value to be
// overridden with an `XEDITLIB_PROGRAM_PATH` environment variable. If
// not provided or value is empty, the program path will default to the
// directory of the first parameter of the command line, which is typically
// the path of the program executable
//
// overriding the program path is useful for scenarios where XEditLib.dll
// is being wrapped by an interpreted language, in which case the program
// executable may be the path to the interpreter, which can be located in
// some system folder where data files related to XEditLib.dll cannot and
// should not be expected to be located at.
ProgramPath := GetEnvironmentVariable('XEDITLIB_PROGRAM_PATH');
if ProgramPath = '' then begin
ProgramPath := ExtractFilePath(ParamStr(0));
end;

// store global values
Globals.Values['ProgramPath'] := ExtractFilePath(ParamStr(0));
Globals.Values['ProgramPath'] := ProgramPath;
Globals.Values['Version'] := ProgramVersion;
Globals.Values['FileCount'] := '0';
end;
Expand Down