Exemplo n.º 1
0
        public static async Task <LoadFileOperation> LoadToJSONObject(string path)
        {
            LoadFileOperation operation = new LoadFileOperation()
            {
                Success = false,
                Result  = null
            };

            if (File.Exists(path))
            {
                string fileContent = "";
                try
                {
                    fileContent = await File.ReadAllTextAsync(path, Encoding.UTF8);

                    operation.Success = JSONContainer.TryParse(fileContent, out operation.Result, out string error);
                    return(operation);
                }
                catch (Exception e)
                {
                    await YNBBotCore.Logger(new Discord.LogMessage(Discord.LogSeverity.Critical, "Save/Load", "Failed to load " + path, e));
                }
            }
            return(operation);
        }
Exemplo n.º 2
0
 public static async Task WriteJSONObjectToFile(string path, JSONContainer json)
 {
     try
     {
         await File.WriteAllTextAsync(path, json.Build(), Encoding.UTF8);
     }
     catch (Exception e)
     {
         await YNBBotCore.Logger(new Discord.LogMessage(Discord.LogSeverity.Critical, "Save/Load", "Failed to save " + path, e));
     }
 }