42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
|
|
|
internal abstract class Storage
|
|
{
|
|
|
|
// ...
|
|
|
|
internal static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite)
|
|
{
|
|
bool result;
|
|
string text;
|
|
if (!compareBeforeWrite)
|
|
result = true;
|
|
else
|
|
{
|
|
if (!File.Exists(path))
|
|
text = string.Empty;
|
|
else
|
|
text = File.ReadAllText(path);
|
|
result = text != contents;
|
|
if (!result && updateDateWhenMatches)
|
|
File.SetLastWriteTime(path, DateTime.Now);
|
|
}
|
|
if (result)
|
|
{
|
|
if (path.Contains("()"))
|
|
File.WriteAllText(path, contents);
|
|
else if (path.Contains("{}") && !path.EndsWith(".json"))
|
|
File.WriteAllText(path, contents);
|
|
else if (path.Contains("[]") && !path.EndsWith(".json"))
|
|
File.WriteAllText(path, contents);
|
|
else if (path.Contains("{}") && path.EndsWith(".json") && contents[0] == '{')
|
|
File.WriteAllText(path, contents);
|
|
else if (path.Contains("[]") && path.EndsWith(".json") && contents[0] == '[')
|
|
File.WriteAllText(path, contents);
|
|
else
|
|
File.WriteAllText(path, contents);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} |