From 0e6bfa830b13d711524a9196e9ee69f508f18f7f Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Tue, 7 Jun 2022 11:47:18 -0400 Subject: [PATCH] Allow running native apps from other directories. It isn't always safe to assume `./` is the app directory, and removing that assumption opens up options. Requires at least Haxe 3.4, but I don't think Lime supports 3.3 anyway. --- src/lime/system/CFFI.hx | 10 ++++++++-- templates/haxe/ManifestResources.hx | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lime/system/CFFI.hx b/src/lime/system/CFFI.hx index 4f36f0306..37a4d8452 100644 --- a/src/lime/system/CFFI.hx +++ b/src/lime/system/CFFI.hx @@ -1,6 +1,7 @@ package lime.system; #if (!lime_doc_gen || lime_cffi) +import haxe.io.Path; import lime._internal.macros.CFFIMacro; #if (sys && !macro) import sys.io.Process; @@ -135,11 +136,16 @@ class CFFI __moduleNames.set(library, library); - result = __tryLoad("./" + library, library, method, args); + var programPath:String = "."; + #if sys + programPath = Path.directory(Sys.programPath()); + #end + + result = __tryLoad(programPath + "/" + library, library, method, args); if (result == null) { - result = __tryLoad(".\\" + library, library, method, args); + result = __tryLoad(programPath + "\\" + library, library, method, args); } if (result == null) diff --git a/templates/haxe/ManifestResources.hx b/templates/haxe/ManifestResources.hx index a49c845f6..bcb34b5a0 100644 --- a/templates/haxe/ManifestResources.hx +++ b/templates/haxe/ManifestResources.hx @@ -3,6 +3,7 @@ package; import haxe.io.Bytes; +import haxe.io.Path; import lime.utils.AssetBundle; import lime.utils.AssetLibrary; import lime.utils.AssetManifest; @@ -44,6 +45,8 @@ import sys.FileSystem; rootPath = ""; #elseif console rootPath = lime.system.System.applicationDirectory; + #elseif sys + rootPath = Path.directory(Sys.programPath()) + "/"; #else rootPath = "./"; #end