2026-02-21 16:51:34 +08:00
|
|
|
using System;
|
2025-06-23 14:33:58 +08:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Ink_Canvas.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class StartupCount
|
|
|
|
|
{
|
|
|
|
|
private static readonly string CountFilePath = Path.Combine(App.RootPath, "startup-count");
|
|
|
|
|
private static readonly object fileLock = new object();
|
|
|
|
|
|
|
|
|
|
public static int GetCount()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(CountFilePath))
|
|
|
|
|
{
|
|
|
|
|
var text = File.ReadAllText(CountFilePath).Trim();
|
|
|
|
|
if (int.TryParse(text, out int count))
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-21 16:51:34 +08:00
|
|
|
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
2025-06-23 14:33:58 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Increment()
|
|
|
|
|
{
|
|
|
|
|
lock (fileLock)
|
|
|
|
|
{
|
|
|
|
|
int count = GetCount() + 1;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(CountFilePath, count.ToString());
|
|
|
|
|
}
|
2026-02-21 16:51:34 +08:00
|
|
|
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
2025-06-23 14:33:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Reset()
|
|
|
|
|
{
|
|
|
|
|
lock (fileLock)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(CountFilePath))
|
|
|
|
|
File.Delete(CountFilePath);
|
|
|
|
|
}
|
2026-02-21 16:51:34 +08:00
|
|
|
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
2025-06-23 14:33:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|