Sfoglia il codice sorgente

Merge pull request #562 from AtomicGameEngine/JME-ATOMIC-558-LOG

Add some error reporting for engine JSON config
JoshEngebretson 10 anni fa
parent
commit
cd108981dc

+ 18 - 0
Source/Atomic/Engine/EngineConfig.cpp

@@ -20,7 +20,10 @@
 // THE SOFTWARE.
 //
 
+#include "../Core/Context.h"
+#include "../IO/Log.h"
 #include "../IO/File.h"
+#include "../IO/FileSystem.h"
 #include "../Resource/JSONFile.h"
 #include "../Graphics/GraphicsDefs.h"
 #include "EngineConfig.h"
@@ -29,6 +32,7 @@ namespace Atomic
 {
 
 VariantMap EngineConfig::engineConfig_;
+String EngineConfig::engineConfigFilename_;
 
 bool EngineConfig::GetBoolValue(const JSONValue& jvalue, bool defaultValue)
 {
@@ -276,7 +280,10 @@ bool EngineConfig::LoadFromJSON(const String& json)
     JSONValue jroot;
 
     if (!JSONFile::ParseJSON(json, jroot))
+    {
+        LOGERRORF("EngineConfig::LoadFromJSON - Unable to parse config file JSON: %s", engineConfigFilename_.CString());
         return false;
+    }
 
     if (!jroot.IsObject())
         return false;
@@ -289,10 +296,21 @@ bool EngineConfig::LoadFromJSON(const String& json)
 
 bool EngineConfig::LoadFromFile(Context *context, const String& filename)
 {
+
+    FileSystem* fileSystem = context->GetSubsystem<FileSystem>();
+
+    if (!fileSystem->FileExists(filename))
+        return false;
+
+    engineConfigFilename_ = filename;
+
     SharedPtr<File> file(new File(context));
 
     if (!file->Open(filename))
+    {
+        LOGERRORF("EngineConfig::LoadFromFile - Unable to open config file %s", filename.CString());
         return false;
+    }
 
     String json;
     file->ReadText(json);

+ 1 - 0
Source/Atomic/Engine/EngineConfig.h

@@ -59,6 +59,7 @@ private:
     static bool LoadEngineConfig(const JSONValue& jengine);
 
     static VariantMap engineConfig_;
+    static String engineConfigFilename_;
 
 };