Index: dm/DMJsonWriter.cpp |
diff --git a/dm/DMJsonWriter.cpp b/dm/DMJsonWriter.cpp |
index 8aea814aed8063341587cfeea84093579070af66..56c1301df166ad1a70c49f54dec7b4c74e51db38 100644 |
--- a/dm/DMJsonWriter.cpp |
+++ b/dm/DMJsonWriter.cpp |
@@ -8,6 +8,7 @@ |
#include "DMJsonWriter.h" |
#include "SkCommonFlags.h" |
+#include "SkData.h" |
#include "SkJSONCPP.h" |
#include "SkOSFile.h" |
#include "SkStream.h" |
@@ -79,4 +80,31 @@ void JsonWriter::DumpJson() { |
stream.flush(); |
} |
+bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) { |
+ SkAutoTUnref<SkData> json(SkData::NewFromFileName(path)); |
+ if (!json) { |
+ return false; |
+ } |
+ |
+ Json::Reader reader; |
+ Json::Value root; |
+ const char* data = (const char*)json->data(); |
+ if (!reader.parse(data, data+json->size(), root)) { |
+ return false; |
+ } |
+ |
+ const Json::Value& results = root["results"]; |
+ BitmapResult br; |
+ for (unsigned i = 0; i < results.size(); i++) { |
+ const Json::Value& r = results[i]; |
+ br.name = r["key"]["name"].asCString(); |
+ br.config = r["key"]["config"].asCString(); |
+ br.sourceType = r["key"]["source_type"].asCString(); |
+ br.ext = r["ext"].asCString(); |
+ br.md5 = r["md5"].asCString(); |
+ callback(br); |
+ } |
+ return true; |
+} |
+ |
} // namespace DM |