Fix config file access errors when starting up multiple TShock servers at once

Use case would be multi-server networks. This commit ensures that sscconfig.json is read with FileShare.Read enabled and stops writing to config.json and sscconfig.json on server load immediately after reading it if the file already exists, which is a no-op since neither of the config files have changed at that point.
This commit is contained in:
ZakFahey 2020-07-27 10:05:28 -07:00
parent 57b12d20b0
commit ccb2a00a71
2 changed files with 7 additions and 3 deletions

View file

@ -48,7 +48,8 @@ namespace TShockAPI.ServerSideCharacters
public static ServerSideConfig Read(string path)
{
using (var reader = new StreamReader(path))
using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var reader = new StreamReader(fileStream))
{
string txt = reader.ReadToEnd();
var config = JsonConvert.DeserializeObject<ServerSideConfig>(txt);