mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-28 03:03:47 +02:00
Handle parsing malformed user created VRC config.json files
This commit is contained in:
@@ -28,7 +28,7 @@ namespace VRCX
|
|||||||
if (string.IsNullOrEmpty(json))
|
if (string.IsNullOrEmpty(json))
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||||
if (obj["cache_directory"] == null)
|
if (obj["cache_directory"] == null)
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ namespace VRCX
|
|||||||
if (string.IsNullOrEmpty(json))
|
if (string.IsNullOrEmpty(json))
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||||
if (obj["picture_output_folder"] == null)
|
if (obj["picture_output_folder"] == null)
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.IO;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using librsync.net;
|
using librsync.net;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
@@ -19,6 +20,14 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Error = delegate(object _, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||||
|
{
|
||||||
|
args.ErrorContext.Handled = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public string MD5File(string blob)
|
public string MD5File(string blob)
|
||||||
{
|
{
|
||||||
var fileData = Convert.FromBase64CharArray(blob.ToCharArray(), 0, blob.Length);
|
var fileData = Convert.FromBase64CharArray(blob.ToCharArray(), 0, blob.Length);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
{
|
{
|
||||||
@@ -18,6 +19,27 @@ namespace VRCX
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ReadConfigFileSafe()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var configFile = ReadConfigFile();
|
||||||
|
if (string.IsNullOrEmpty(configFile))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
var jObject = JsonConvert.DeserializeObject<dynamic>(configFile, JsonSerializerSettings);
|
||||||
|
if (jObject == null)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
return JsonConvert.SerializeObject(jObject, Formatting.Indented);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Warn(ex, "Failed to parse VRC config.json file");
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void WriteConfigFile(string json)
|
public void WriteConfigFile(string json)
|
||||||
{
|
{
|
||||||
var path = GetVRChatAppDataLocation();
|
var path = GetVRChatAppDataLocation();
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace VRCX
|
|||||||
if (string.IsNullOrEmpty(json))
|
if (string.IsNullOrEmpty(json))
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||||
if (obj["cache_directory"] == null)
|
if (obj["cache_directory"] == null)
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ namespace VRCX
|
|||||||
if (string.IsNullOrEmpty(json))
|
if (string.IsNullOrEmpty(json))
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||||
if (obj["picture_output_folder"] == null)
|
if (obj["picture_output_folder"] == null)
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
|
|
||||||
|
|||||||
@@ -401,7 +401,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function readVRChatConfigFile() {
|
async function readVRChatConfigFile() {
|
||||||
const config = await AppApi.ReadConfigFile();
|
const config = await AppApi.ReadConfigFileSafe();
|
||||||
if (config) {
|
if (config) {
|
||||||
try {
|
try {
|
||||||
const parsedConfig = JSON.parse(config);
|
const parsedConfig = JSON.parse(config);
|
||||||
|
|||||||
Reference in New Issue
Block a user