mirror of
https://github.com/clubby789/OWClock.git
synced 2025-12-11 20:15:31 +01:00
Update to Framework 4.8 Update all NuGet packages to latest Remove unused references Add NetAnalyzers Close all messages from new NetAnalyzers
36 lines
963 B
C#
36 lines
963 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Clock
|
|
{
|
|
[Serializable]
|
|
public class EventFile
|
|
{
|
|
public List<TimeEvent> eventList = new List<TimeEvent>();
|
|
private const string _fileName = "events.json";
|
|
|
|
public void AddEvent(float timestamp, string name)
|
|
{
|
|
eventList.Add(new TimeEvent((float)Math.Truncate(timestamp), name));
|
|
eventList.Sort(SortTimestamp);
|
|
Save();
|
|
}
|
|
|
|
private void Save()
|
|
{
|
|
OWClock.Helper.Storage.Save(this, _fileName);
|
|
}
|
|
|
|
public static EventFile LoadSaveFile()
|
|
{
|
|
var save = OWClock.Helper.Storage.Load<EventFile>(_fileName);
|
|
save.eventList.Sort(SortTimestamp);
|
|
return save ?? new EventFile();
|
|
}
|
|
|
|
private static int SortTimestamp(TimeEvent e1, TimeEvent e2)
|
|
{
|
|
return e1.Timestamp.CompareTo(e2.Timestamp);
|
|
}
|
|
}
|
|
} |