소스 검색

Applied resource search path patch from Erik Beran.
Added similar fallback to executable search path (FileSystem::SystemRun()).

Lasse Öörni 12 년 전
부모
커밋
0092e3da5b
2개의 변경된 파일30개의 추가작업 그리고 4개의 파일을 삭제
  1. 22 4
      Engine/Engine/Engine.cpp
  2. 8 0
      Engine/IO/FileSystem.cpp

+ 22 - 4
Engine/Engine/Engine.cpp

@@ -147,6 +147,7 @@ bool Engine::Initialize(const VariantMap& parameters)
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
     String exePath = fileSystem->GetProgramDir();
+    String cwdPath = fileSystem->GetCurrentDir();
     
     Vector<String> resourcePaths = GetParameter(parameters, "ResourcePaths", "CoreData;Data").GetString().Split(';');
     Vector<String> resourcePackages = GetParameter(parameters, "ResourcePackages").GetString().Split(';');
@@ -155,7 +156,11 @@ bool Engine::Initialize(const VariantMap& parameters)
     for (unsigned i = 0; i < resourcePaths.Size(); ++i)
     {
         bool success = false;
+        
         String packageName = exePath + resourcePaths[i] + ".pak";
+        // Try cwd-relative path if not found next to executable
+        if (!fileSystem->FileExists(packageName))
+            packageName = cwdPath + resourcePaths[i] + ".pak";
         
         if (fileSystem->FileExists(packageName))
         {
@@ -167,8 +172,16 @@ bool Engine::Initialize(const VariantMap& parameters)
             }
         }
         
-        if (!success && fileSystem->DirExists(exePath + resourcePaths[i]))
-            success = cache->AddResourceDir(exePath + resourcePaths[i]);
+        if (!success)
+        {
+            String pathName = exePath + resourcePaths[i];
+            // Try cwd-relative path if not found next to executable
+            if (!fileSystem->DirExists(pathName))
+                pathName = cwdPath + resourcePaths[i];
+            
+            if (fileSystem->DirExists(pathName))
+                success = cache->AddResourceDir(pathName);
+        }
         
         if (!success)
         {
@@ -182,10 +195,15 @@ bool Engine::Initialize(const VariantMap& parameters)
     {
         bool success = false;
         
-        if (fileSystem->FileExists(exePath + resourcePackages[i]))
+        String packageName = exePath + resourcePackages[i];
+        // Try cwd-relative path if not found next to executable
+        if (!fileSystem->FileExists(packageName))
+            packageName = cwdPath + resourcePackages[i];
+        
+        if (fileSystem->FileExists(packageName))
         {
             SharedPtr<PackageFile> package(new PackageFile(context_));
-            if (package->Open(exePath + resourcePackages[i]))
+            if (package->Open(packageName))
             {
                 cache->AddPackageFile(package);
                 success = true;

+ 8 - 0
Engine/IO/FileSystem.cpp

@@ -141,6 +141,10 @@ int FileSystem::SystemRun(const String& fileName, const Vector<String>& argument
         if (GetExtension(fixedFileName).Empty())
             fixedFileName += ".exe";
 
+        // If executable is not found, try cwd-relative path as a fallback
+        if (!FileExists(fixedFileName))
+            fixedFileName = GetNativePath(GetCurrentDir() + GetFileNameAndExtension(fixedFileName));
+
         String commandLine = "\"" + fixedFileName + "\"";
         for (unsigned i = 0; i < arguments.Size(); ++i)
             commandLine += " " + arguments[i];
@@ -166,6 +170,10 @@ int FileSystem::SystemRun(const String& fileName, const Vector<String>& argument
 
         return exitCode;
         #else
+        // If executable is not found, try cwd-relative path as a fallback
+        if (!FileExists(fixedFileName))
+            fixedFileName = GetNativePath(GetCurrentDir() + GetFileNameAndExtension(fixedFileName));
+        
         pid_t pid = fork();
         if (!pid)
         {