Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update: LazyAPI Add File saving
  • Loading branch information
Controllerdestiny committed Nov 22, 2024
commit 3e11378e3bb441f5e30a32b43179f715cb917bb6
15 changes: 13 additions & 2 deletions src/LazyAPI/ConfigFiles/JsonConfigBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using TShockAPI;
using TShockAPI.Hooks;
using static LinqToDB.Reflection.Methods.LinqToDB.Insert;
Comment thread
LaoSparrow marked this conversation as resolved.
Outdated

namespace LazyAPI.ConfigFiles;

Expand Down Expand Up @@ -46,16 +47,26 @@ private static T GetConfig()
var file = t.FullFilename;
if (File.Exists(file))
{
return JsonConvert.DeserializeObject<T>(File.ReadAllText(file), _settings) ?? new();
return JsonConvert.DeserializeObject<T>(File.ReadAllText(file), _settings) ?? t;
}
else
{
t.SetDefault();
}
File.WriteAllText(file, JsonConvert.SerializeObject(t, _settings));
t.Save();
return t;
}

public virtual void Save()
Comment thread
LaoSparrow marked this conversation as resolved.
Outdated
{
var dirInfo = new DirectoryInfo(Path.GetDirectoryName(this.FullFilename)!);
if (!dirInfo.Exists)
{
dirInfo.Create();
}
File.WriteAllText(this.FullFilename, JsonConvert.SerializeObject(this, _settings));
}

// .cctor is lazy load
public static string Load()
{
Expand Down
2 changes: 1 addition & 1 deletion src/LazyAPI/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LazyAPI;
public class PluginContainer : LazyPlugin
{
public override string Author => "cc004 & members of UnrealMultiple";
public override Version Version => new(1, 0, 0, 2);
public override Version Version => new(1, 0, 0, 3);

public PluginContainer(Main game) : base(game) { }
public override void Initialize()
Expand Down