Skip to content

Commit

Permalink
Merge pull request #10960 from unknownbrackets/debugger-json
Browse files Browse the repository at this point in the history
Switch json to gason, include json writer in build
  • Loading branch information
hrydgard committed Jun 6, 2018
2 parents f9cfb05 + 082ddf5 commit df699c6
Show file tree
Hide file tree
Showing 24 changed files with 1,042 additions and 1,076 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Expand Up @@ -463,11 +463,9 @@ if(USING_GLES2)
find_package(X11) find_package(X11)
endif() endif()


add_library(vjson STATIC add_library(gason STATIC
ext/native/ext/vjson/json.cpp ext/native/ext/gason/gason.cpp
ext/native/ext/vjson/json.h ext/native/ext/gason/gason.h
ext/native/ext/vjson/block_allocator.cpp
ext/native/ext/vjson/block_allocator.h
) )


add_library(rg_etc1 STATIC add_library(rg_etc1 STATIC
Expand Down Expand Up @@ -897,10 +895,6 @@ add_library(native STATIC
ext/native/base/timeutil.h ext/native/base/timeutil.h
ext/native/data/compression.cpp ext/native/data/compression.cpp
ext/native/data/compression.h ext/native/data/compression.h
ext/native/ext/vjson/json.cpp
ext/native/ext/vjson/json.h
ext/native/ext/vjson/block_allocator.cpp
ext/native/ext/vjson/block_allocator.h
ext/native/file/chunk_file.cpp ext/native/file/chunk_file.cpp
ext/native/file/chunk_file.h ext/native/file/chunk_file.h
ext/native/file/fd_util.cpp ext/native/file/fd_util.cpp
Expand Down Expand Up @@ -954,6 +948,10 @@ add_library(native STATIC
ext/native/input/keycodes.h ext/native/input/keycodes.h
ext/native/input/input_state.h ext/native/input/input_state.h
ext/native/input/input_state.cpp ext/native/input/input_state.cpp
ext/native/json/json_reader.h
ext/native/json/json_reader.cpp
ext/native/json/json_writer.h
ext/native/json/json_writer.cpp
ext/native/math/fast/fast_math.c ext/native/math/fast/fast_math.c
ext/native/math/fast/fast_matrix.c ext/native/math/fast/fast_matrix.c
ext/native/math/fast/fast_matrix_neon.S ext/native/math/fast/fast_matrix_neon.S
Expand Down Expand Up @@ -1040,7 +1038,7 @@ if(ANDROID)
SET(ATOMIC_LIB atomic) SET(ATOMIC_LIB atomic)
endif() endif()


target_link_libraries(native ${LIBZIP_LIBRARY} ${PNG_LIBRARY} ${ZLIB_LIBRARY} rg_etc1 vjson udis86 ${RT_LIB} ${nativeExtraLibs} ${ATOMIC_LIB}) target_link_libraries(native ${LIBZIP_LIBRARY} ${PNG_LIBRARY} ${ZLIB_LIBRARY} rg_etc1 gason udis86 ${RT_LIB} ${nativeExtraLibs} ${ATOMIC_LIB})
if(TARGET Ext::GLEW) if(TARGET Ext::GLEW)
target_link_libraries(native Ext::GLEW) target_link_libraries(native Ext::GLEW)
endif() endif()
Expand Down
6 changes: 3 additions & 3 deletions Core/Config.cpp
Expand Up @@ -22,9 +22,9 @@


#include "base/display.h" #include "base/display.h"
#include "base/NativeApp.h" #include "base/NativeApp.h"
#include "ext/vjson/json.h"
#include "file/ini_file.h" #include "file/ini_file.h"
#include "i18n/i18n.h" #include "i18n/i18n.h"
#include "json/json_reader.h"
#include "gfx_es2/gpu_features.h" #include "gfx_es2/gpu_features.h"
#include "net/http_client.h" #include "net/http_client.h"
#include "util/text/parsers.h" #include "util/text/parsers.h"
Expand Down Expand Up @@ -1181,13 +1181,13 @@ void Config::DownloadCompletedCallback(http::Download &download) {
} }


JsonReader reader(data.c_str(), data.size()); JsonReader reader(data.c_str(), data.size());
const json_value *root = reader.root(); const JsonGet root = reader.root();
if (!root) { if (!root) {
ERROR_LOG(LOADER, "Failed to parse json"); ERROR_LOG(LOADER, "Failed to parse json");
return; return;
} }


std::string version = root->getString("version", ""); std::string version = root.getString("version", "");


const char *gitVer = PPSSPP_GIT_VERSION; const char *gitVer = PPSSPP_GIT_VERSION;
Version installed(gitVer); Version installed(gitVer);
Expand Down
19 changes: 10 additions & 9 deletions UI/RemoteISOScreen.cpp
Expand Up @@ -21,9 +21,9 @@
#include <condition_variable> #include <condition_variable>


#include "base/timeutil.h" #include "base/timeutil.h"
#include "ext/vjson/json.h"
#include "file/fd_util.h" #include "file/fd_util.h"
#include "i18n/i18n.h" #include "i18n/i18n.h"
#include "json/json_reader.h"
#include "net/http_client.h" #include "net/http_client.h"
#include "net/http_server.h" #include "net/http_server.h"
#include "net/resolve.h" #include "net/resolve.h"
Expand Down Expand Up @@ -252,16 +252,19 @@ static bool FindServer(std::string &resultHost, int &resultPort) {
return false; return false;
} }


const json_value *entries = reader.root(); const JsonValue entries = reader.rootArray();
if (!entries) { if (entries.getTag() != JSON_ARRAY) {
return false; return false;
} }


std::vector<std::string> servers; std::vector<std::string> servers;
const json_value *entry = entries->first_child; for (const auto pentry : entries) {
while (entry && !scanCancelled) { JsonGet entry = pentry->value;
const char *host = entry->getString("ip", ""); if (scanCancelled)
int port = entry->getInt("p", 0); return false;

const char *host = entry.getString("ip", "");
int port = entry.getInt("p", 0);


char url[1024] = {}; char url[1024] = {};
snprintf(url, sizeof(url), "http://%s:%d", host, port); snprintf(url, sizeof(url), "http://%s:%d", host, port);
Expand All @@ -270,8 +273,6 @@ static bool FindServer(std::string &resultHost, int &resultPort) {
if (TryServer(host, port)) { if (TryServer(host, port)) {
return true; return true;
} }

entry = entry->next_sibling;
} }


// None of the local IPs were reachable. // None of the local IPs were reachable.
Expand Down
39 changes: 19 additions & 20 deletions UI/Store.cpp
Expand Up @@ -18,7 +18,7 @@
#include <functional> #include <functional>


#include "base/basictypes.h" #include "base/basictypes.h"
#include "ext/vjson/json.h" #include "json/json_reader.h"


#include "i18n/i18n.h" #include "i18n/i18n.h"
#include "ui/screen.h" #include "ui/screen.h"
Expand Down Expand Up @@ -392,33 +392,32 @@ void StoreScreen::update() {


void StoreScreen::ParseListing(std::string json) { void StoreScreen::ParseListing(std::string json) {
JsonReader reader(json.c_str(), json.size()); JsonReader reader(json.c_str(), json.size());
if (!reader.ok()) { if (!reader.ok() || !reader.root()) {
ELOG("Error parsing JSON from store"); ELOG("Error parsing JSON from store");
connectionError_ = true; connectionError_ = true;
RecreateViews(); RecreateViews();
return; return;
} }
json_value *root = reader.root(); const JsonGet root = reader.root();
const json_value *entries = root->getArray("entries"); const JsonNode *entries = root.getArray("entries");
if (entries) { if (entries) {
entries_.clear(); entries_.clear();
const json_value *game = entries->first_child; for (const JsonNode *pgame : entries->value) {
while (game) { JsonGet game = pgame->value;
StoreEntry e; StoreEntry e;
e.type = ENTRY_PBPZIP; e.type = ENTRY_PBPZIP;
e.name = GetTranslatedString(game, "name"); e.name = GetTranslatedString(game, "name");
e.description = GetTranslatedString(game, "description", ""); e.description = GetTranslatedString(game, "description", "");
e.author = game->getString("author", "?"); e.author = game.getString("author", "?");
e.size = game->getInt("size"); e.size = game.getInt("size");
e.downloadURL = game->getString("download-url", ""); e.downloadURL = game.getString("download-url", "");
e.iconURL = game->getString("icon-url", ""); e.iconURL = game.getString("icon-url", "");
e.hidden = game->getBool("hidden", false); e.hidden = game.getBool("hidden", false);
const char *file = game->getString("file", 0); const char *file = game.getString("file", nullptr);
if (!file) if (!file)
continue; continue;
e.file = file; e.file = file;
entries_.push_back(e); entries_.push_back(e);
game = game->next_sibling;
} }
} }
} }
Expand Down Expand Up @@ -541,16 +540,16 @@ std::string StoreScreen::GetStoreJsonURL(std::string storePath) const {
return path; return path;
} }


std::string StoreScreen::GetTranslatedString(const json_value *json, std::string key, const char *fallback) const { std::string StoreScreen::GetTranslatedString(const JsonGet json, std::string key, const char *fallback) const {
const json_value *dict = json->getDict("en_US"); JsonGet dict = json.getDict("en_US");
if (dict && json->hasChild(lang_.c_str(), JSON_OBJECT)) { if (dict && json.hasChild(lang_.c_str(), JSON_OBJECT)) {
if (json->getDict(lang_.c_str())->hasChild(key.c_str(), JSON_STRING)) { if (json.getDict(lang_.c_str()).hasChild(key.c_str(), JSON_STRING)) {
dict = json->getDict(lang_.c_str()); dict = json.getDict(lang_.c_str());
} }
} }
const char *str = 0; const char *str = nullptr;
if (dict) { if (dict) {
str = dict->getString(key.c_str(), 0); str = dict.getString(key.c_str(), nullptr);
} }
if (str) { if (str) {
return std::string(str); return std::string(str);
Expand Down
4 changes: 2 additions & 2 deletions UI/Store.h
Expand Up @@ -29,7 +29,7 @@
// set game specific settings, etc. // set game specific settings, etc.
// Uses GameInfoCache heavily to implement the functionality. // Uses GameInfoCache heavily to implement the functionality.


struct json_value; struct JsonGet;
class ProductItemView; class ProductItemView;


enum EntryType { enum EntryType {
Expand Down Expand Up @@ -79,7 +79,7 @@ class StoreScreen : public UIDialogScreenWithBackground {
std::vector<StoreEntry> FilterEntries(); std::vector<StoreEntry> FilterEntries();


std::string GetStoreJsonURL(std::string storePath) const; std::string GetStoreJsonURL(std::string storePath) const;
std::string GetTranslatedString(const json_value *json, std::string key, const char *fallback = 0) const; std::string GetTranslatedString(const JsonGet json, std::string key, const char *fallback = nullptr) const;


std::shared_ptr<http::Download> listing_; std::shared_ptr<http::Download> listing_;
std::shared_ptr<http::Download> image_; std::shared_ptr<http::Download> image_;
Expand Down
8 changes: 4 additions & 4 deletions UWP/NativeUWP/NativeUWP.vcxproj
Expand Up @@ -328,8 +328,6 @@
<ClInclude Include="..\..\ext\native\ext\libzip\config.h" /> <ClInclude Include="..\..\ext\native\ext\libzip\config.h" />
<ClInclude Include="..\..\ext\native\ext\libzip\zip.h" /> <ClInclude Include="..\..\ext\native\ext\libzip\zip.h" />
<ClInclude Include="..\..\ext\native\ext\libzip\zipint.h" /> <ClInclude Include="..\..\ext\native\ext\libzip\zipint.h" />
<ClInclude Include="..\..\ext\native\ext\vjson\block_allocator.h" />
<ClInclude Include="..\..\ext\native\ext\vjson\json.h" />
<ClInclude Include="..\..\ext\native\file\chunk_file.h" /> <ClInclude Include="..\..\ext\native\file\chunk_file.h" />
<ClInclude Include="..\..\ext\native\file\fd_util.h" /> <ClInclude Include="..\..\ext\native\file\fd_util.h" />
<ClInclude Include="..\..\ext\native\file\file_util.h" /> <ClInclude Include="..\..\ext\native\file\file_util.h" />
Expand All @@ -338,6 +336,8 @@
<ClInclude Include="..\..\ext\native\file\path.h" /> <ClInclude Include="..\..\ext\native\file\path.h" />
<ClInclude Include="..\..\ext\native\file\vfs.h" /> <ClInclude Include="..\..\ext\native\file\vfs.h" />
<ClInclude Include="..\..\ext\native\file\zip_read.h" /> <ClInclude Include="..\..\ext\native\file\zip_read.h" />
<ClInclude Include="..\..\ext\native\json\json_reader.h" />
<ClInclude Include="..\..\ext\native\json\json_writer.h" />
<ClInclude Include="..\..\ext\native\gfx\texture_atlas.h" /> <ClInclude Include="..\..\ext\native\gfx\texture_atlas.h" />
<ClInclude Include="..\..\ext\native\gfx_es2\draw_buffer.h" /> <ClInclude Include="..\..\ext\native\gfx_es2\draw_buffer.h" />
<ClInclude Include="..\..\ext\native\gfx_es2\draw_text.h" /> <ClInclude Include="..\..\ext\native\gfx_es2\draw_text.h" />
Expand Down Expand Up @@ -1160,15 +1160,15 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">NotUsing</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\ext\native\ext\vjson\block_allocator.cpp" />
<ClCompile Include="..\..\ext\native\ext\vjson\json.cpp" />
<ClCompile Include="..\..\ext\native\file\chunk_file.cpp" /> <ClCompile Include="..\..\ext\native\file\chunk_file.cpp" />
<ClCompile Include="..\..\ext\native\file\fd_util.cpp" /> <ClCompile Include="..\..\ext\native\file\fd_util.cpp" />
<ClCompile Include="..\..\ext\native\file\file_util.cpp" /> <ClCompile Include="..\..\ext\native\file\file_util.cpp" />
<ClCompile Include="..\..\ext\native\file\free.cpp" /> <ClCompile Include="..\..\ext\native\file\free.cpp" />
<ClCompile Include="..\..\ext\native\file\ini_file.cpp" /> <ClCompile Include="..\..\ext\native\file\ini_file.cpp" />
<ClCompile Include="..\..\ext\native\file\path.cpp" /> <ClCompile Include="..\..\ext\native\file\path.cpp" />
<ClCompile Include="..\..\ext\native\file\zip_read.cpp" /> <ClCompile Include="..\..\ext\native\file\zip_read.cpp" />
<ClCompile Include="..\..\ext\native\json\json_reader.cpp" />
<ClCompile Include="..\..\ext\native\json\json_writer.cpp" />
<ClCompile Include="..\..\ext\native\gfx\texture_atlas.cpp" /> <ClCompile Include="..\..\ext\native\gfx\texture_atlas.cpp" />
<ClCompile Include="..\..\ext\native\gfx_es2\draw_buffer.cpp" /> <ClCompile Include="..\..\ext\native\gfx_es2\draw_buffer.cpp" />
<ClCompile Include="..\..\ext\native\gfx_es2\draw_text.cpp" /> <ClCompile Include="..\..\ext\native\gfx_es2\draw_text.cpp" />
Expand Down
15 changes: 0 additions & 15 deletions UWP/NativeUWP/NativeUWP.vcxproj.filters
Expand Up @@ -37,9 +37,6 @@
<Filter Include="ext"> <Filter Include="ext">
<UniqueIdentifier>{2be24387-0b6a-4253-97fa-b8b6f75a8a4c}</UniqueIdentifier> <UniqueIdentifier>{2be24387-0b6a-4253-97fa-b8b6f75a8a4c}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="ext\vjson">
<UniqueIdentifier>{7fdd3320-a8e0-42ed-b08b-2d86ba2ff414}</UniqueIdentifier>
</Filter>
<Filter Include="ext\libzip"> <Filter Include="ext\libzip">
<UniqueIdentifier>{1a486fc4-bac0-4b33-9139-262272690c74}</UniqueIdentifier> <UniqueIdentifier>{1a486fc4-bac0-4b33-9139-262272690c74}</UniqueIdentifier>
</Filter> </Filter>
Expand Down Expand Up @@ -214,12 +211,6 @@
<ClCompile Include="..\..\ext\native\i18n\i18n.cpp"> <ClCompile Include="..\..\ext\native\i18n\i18n.cpp">
<Filter>i18n</Filter> <Filter>i18n</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\ext\native\ext\vjson\block_allocator.cpp">
<Filter>ext\vjson</Filter>
</ClCompile>
<ClCompile Include="..\..\ext\native\ext\vjson\json.cpp">
<Filter>ext\vjson</Filter>
</ClCompile>
<ClCompile Include="..\..\ext\native\ext\libzip\mkstemp.c"> <ClCompile Include="..\..\ext\native\ext\libzip\mkstemp.c">
<Filter>ext\libzip</Filter> <Filter>ext\libzip</Filter>
</ClCompile> </ClCompile>
Expand Down Expand Up @@ -656,12 +647,6 @@
<ClInclude Include="..\..\ext\native\i18n\i18n.h"> <ClInclude Include="..\..\ext\native\i18n\i18n.h">
<Filter>i18n</Filter> <Filter>i18n</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\ext\native\ext\vjson\block_allocator.h">
<Filter>ext\vjson</Filter>
</ClInclude>
<ClInclude Include="..\..\ext\native\ext\vjson\json.h">
<Filter>ext\vjson</Filter>
</ClInclude>
<ClInclude Include="..\..\ext\native\ext\libzip\config.h"> <ClInclude Include="..\..\ext\native\ext\libzip\config.h">
<Filter>ext\libzip</Filter> <Filter>ext\libzip</Filter>
</ClInclude> </ClInclude>
Expand Down
4 changes: 2 additions & 2 deletions ext/native/Android.mk
Expand Up @@ -35,15 +35,15 @@ LOCAL_SRC_FILES :=\
ext/jpge/jpgd.cpp \ ext/jpge/jpgd.cpp \
ext/jpge/jpge.cpp \ ext/jpge/jpge.cpp \
ext/sha1/sha1.cpp \ ext/sha1/sha1.cpp \
ext/vjson/json.cpp \ ext/gason/gason.cpp \
ext/vjson/block_allocator.cpp \
file/fd_util.cpp \ file/fd_util.cpp \
file/chunk_file.cpp \ file/chunk_file.cpp \
file/file_util.cpp \ file/file_util.cpp \
file/free.cpp \ file/free.cpp \
file/path.cpp \ file/path.cpp \
file/ini_file.cpp \ file/ini_file.cpp \
file/zip_read.cpp \ file/zip_read.cpp \
json/json_reader.cpp \
json/json_writer.cpp \ json/json_writer.cpp \
i18n/i18n.cpp \ i18n/i18n.cpp \
input/gesture_detector.cpp \ input/gesture_detector.cpp \
Expand Down
20 changes: 20 additions & 0 deletions ext/native/ext/gason/LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013-2015 Ivan Vashchaev

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit df699c6

Please sign in to comment.