mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-16 21:33:51 +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))
|
||||
return defaultPath;
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||
if (obj["cache_directory"] == null)
|
||||
return defaultPath;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace VRCX
|
||||
if (string.IsNullOrEmpty(json))
|
||||
return defaultPath;
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||
if (obj["picture_output_folder"] == null)
|
||||
return defaultPath;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using librsync.net;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace VRCX
|
||||
@@ -18,6 +19,14 @@ namespace VRCX
|
||||
public void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
Error = delegate(object _, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||
{
|
||||
args.ErrorContext.Handled = true;
|
||||
}
|
||||
};
|
||||
|
||||
public string MD5File(string blob)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
@@ -18,6 +19,27 @@ namespace VRCX
|
||||
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)
|
||||
{
|
||||
var path = GetVRChatAppDataLocation();
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace VRCX
|
||||
if (string.IsNullOrEmpty(json))
|
||||
return defaultPath;
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||
if (obj["cache_directory"] == null)
|
||||
return defaultPath;
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace VRCX
|
||||
if (string.IsNullOrEmpty(json))
|
||||
return defaultPath;
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json);
|
||||
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||
if (obj["picture_output_folder"] == null)
|
||||
return defaultPath;
|
||||
|
||||
|
||||
@@ -401,7 +401,7 @@
|
||||
}
|
||||
|
||||
async function readVRChatConfigFile() {
|
||||
const config = await AppApi.ReadConfigFile();
|
||||
const config = await AppApi.ReadConfigFileSafe();
|
||||
if (config) {
|
||||
try {
|
||||
const parsedConfig = JSON.parse(config);
|
||||
|
||||
Reference in New Issue
Block a user