From 0411efcd57f521b28ea8b6ce5fad37f219b4e01b Mon Sep 17 00:00:00 2001 From: Enrico Horn Date: Thu, 18 Aug 2022 13:03:06 +0200 Subject: [PATCH] vrclient: Convert action manifests to unix paths --- vrclient_x64/gen_wrapper.py | 13 ++++++ vrclient_x64/vrclient_x64/json_converter.cpp | 44 ++++++++++++++++++++ vrclient_x64/vrclient_x64/vrclient_private.h | 1 + vrclient_x64/vrclient_x64/winIVRInput.c | 6 +++ 4 files changed, 64 insertions(+) diff --git a/vrclient_x64/gen_wrapper.py b/vrclient_x64/gen_wrapper.py index df7831ee8..ed8be097b 100755 --- a/vrclient_x64/gen_wrapper.py +++ b/vrclient_x64/gen_wrapper.py @@ -133,6 +133,7 @@ "l2w_lens":[], "w2l_names": ["pchActionManifestPath"], "w2l_arrays": [False], + "file_converter": "json_convert_action_manifest", "return_is_size": False }, { @@ -141,6 +142,7 @@ "l2w_lens":[], "w2l_names": ["pchFilePath"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, { @@ -149,6 +151,7 @@ "l2w_lens":[], "w2l_names": ["pchApplicationManifestFullPath"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, { @@ -157,6 +160,7 @@ "l2w_lens":[], "w2l_names": ["pchApplicationManifestFullPath"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, { @@ -165,6 +169,7 @@ "l2w_lens":[], "w2l_names": ["pchPreviewFilename", "pchVRFilename"], "w2l_arrays": [False, False], + "file_converter": None, "return_is_size": False }, { @@ -173,6 +178,7 @@ "l2w_lens":[], "w2l_names": ["pchPreviewFilename", "pchVRFilename"], "w2l_arrays": [False, False], + "file_converter": None, "return_is_size": False }, { @@ -181,6 +187,7 @@ "l2w_lens":[], "w2l_names": ["pchSourcePreviewFilename", "pchSourceVRFilename"], "w2l_arrays": [False, False], + "file_converter": None, "return_is_size": False }, { @@ -189,6 +196,7 @@ "l2w_lens":["cchFilename"], "w2l_names": [], "w2l_arrays": [], + "file_converter": None, "return_is_size": True }, { @@ -197,6 +205,7 @@ "l2w_lens":[], "w2l_names": ["a"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, { @@ -205,6 +214,7 @@ "l2w_lens":[], "w2l_names": ["a"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, { @@ -213,6 +223,7 @@ "l2w_lens":[], "w2l_names": ["pchRenderModelPath"], "w2l_arrays": [False], + "file_converter": None, "return_is_size": False }, @@ -530,6 +541,8 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e else: cfile.write(" char lin_%s[PATH_MAX];\n" % path_conv["w2l_names"][i]) cfile.write(" vrclient_dos_path_to_unix_path(%s, lin_%s);\n" % (path_conv["w2l_names"][i], path_conv["w2l_names"][i])) + if path_conv["file_converter"] is not None: + cfile.write(" %s(lin_%s);\n" % (path_conv["file_converter"], path_conv["w2l_names"][i])) if None in path_conv["l2w_names"]: cfile.write(" const char *path_result;\n") elif path_conv["return_is_size"]: diff --git a/vrclient_x64/vrclient_x64/json_converter.cpp b/vrclient_x64/vrclient_x64/json_converter.cpp index 83fd2ec08..f4ef55de8 100644 --- a/vrclient_x64/vrclient_x64/json_converter.cpp +++ b/vrclient_x64/vrclient_x64/json_converter.cpp @@ -6,6 +6,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(vrclient); #include "vrclient_private.h" #include "json/json.h" +#include extern "C" { @@ -143,4 +144,47 @@ char *json_convert_startup_info(const char *startup_info) return ret; } +bool json_convert_action_manifest(const char *manifest_file) +{ + char dst_path[PATH_MAX]; + Json::CharReaderBuilder rbuilder; + std::ifstream manifest(manifest_file, std::ifstream::binary); + Json::Value root; + std::string errs; + + WINE_TRACE("converting action manifest file %s.\n", manifest_file); + + bool ok = Json::parseFromStream(rbuilder, manifest, &root, &errs); + manifest.close(); + if (!ok) { + WINE_ERR("error parsing action manifest as JSON %s: %s.\n", manifest_file, errs.c_str()); + return false; + } + + if (!root.isMember("default_bindings")) + return true; + + if (!root["default_bindings"].isArray()) { + WINE_ERR("error converting action manifest %s: default_bindings is not an array.\n", manifest_file); + return false; + } + + for (Json::Value::ArrayIndex i = 0; i != root["default_bindings"].size(); i++) { + if (root["default_bindings"][i].isMember("binding_url")) { + if (!root["default_bindings"][i]["binding_url"].isString()) { + WINE_ERR("error converting action manifest %s: binding_url %i is not a string.\n", manifest_file, i); + return false; + } + vrclient_dos_path_to_unix_path(root["default_bindings"][i]["binding_url"].asCString(), dst_path); + root["default_bindings"][i]["binding_url"] = dst_path; + } + } + + std::ofstream ofstream(manifest_file); + ofstream << root; + ofstream.close(); + + return true; +} + } diff --git a/vrclient_x64/vrclient_x64/vrclient_private.h b/vrclient_x64/vrclient_x64/vrclient_private.h index a99117c4c..c5175df85 100644 --- a/vrclient_x64/vrclient_x64/vrclient_private.h +++ b/vrclient_x64/vrclient_x64/vrclient_private.h @@ -7,6 +7,7 @@ extern "C" { char *json_convert_paths(const char *input); char *json_convert_startup_info(const char *startup_info); +bool json_convert_action_manifest(const char *manifest_file); bool vrclient_dos_path_to_unix_path(const char *src, char *dst); diff --git a/vrclient_x64/vrclient_x64/winIVRInput.c b/vrclient_x64/vrclient_x64/winIVRInput.c index 2a95b5f24..63a451f62 100644 --- a/vrclient_x64/vrclient_x64/winIVRInput.c +++ b/vrclient_x64/vrclient_x64/winIVRInput.c @@ -30,6 +30,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_010_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_010_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); } @@ -377,6 +378,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_007_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_007_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); } @@ -688,6 +690,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_006_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_006_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); } @@ -981,6 +984,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_005_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_005_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); } @@ -1265,6 +1269,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_004_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_004_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); } @@ -1486,6 +1491,7 @@ EVRInputError __thiscall winIVRInput_IVRInput_003_SetActionManifestPath(winIVRIn { char lin_pchActionManifestPath[PATH_MAX]; vrclient_dos_path_to_unix_path(pchActionManifestPath, lin_pchActionManifestPath); + json_convert_action_manifest(lin_pchActionManifestPath); TRACE("%p\n", _this); return cppIVRInput_IVRInput_003_SetActionManifestPath(_this->linux_side, pchActionManifestPath ? lin_pchActionManifestPath : NULL); }