mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 11:39:54 +00:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace EHR.Modules;
|
|
|
|
public static class PrivateTagManager
|
|
{
|
|
private static readonly string TagFile = $"{Main.DataPath}/EHR_DATA/tags.txt";
|
|
public static Dictionary<string, string> Tags = [];
|
|
|
|
public static void AddTag(string friendcode, string tag)
|
|
{
|
|
LoadTagsFromFile();
|
|
Tags[friendcode] = tag;
|
|
SaveTagsToFile();
|
|
}
|
|
|
|
public static void DeleteTag(string friendcode)
|
|
{
|
|
LoadTagsFromFile();
|
|
if (!Tags.Remove(friendcode)) return;
|
|
SaveTagsToFile();
|
|
}
|
|
|
|
private static void SaveTagsToFile()
|
|
{
|
|
try { File.WriteAllText(TagFile, string.Join("\n", Tags.Select(x => $"{x.Key}={x.Value}"))); }
|
|
catch (Exception e) { Utils.ThrowException(e); }
|
|
}
|
|
|
|
public static void LoadTagsFromFile()
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(TagFile))
|
|
return;
|
|
|
|
Tags = File.ReadAllLines(TagFile)
|
|
.Select(x => x.Split('='))
|
|
.Where(x => x.Length == 2)
|
|
.ToDictionary(x => x[0], x => x[1]);
|
|
}
|
|
catch (Exception e) { Utils.ThrowException(e); }
|
|
}
|
|
} |