aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.TelemetryTester.CLI/DatabaseHelper.cs
blob: 60791a5d84c0d1e97aec8da158a1012771442f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.TelemetryTester.CLI
{
    public class DatabaseHelper
    {
        public static void ClearTelemetryDatabase()
        {
            string appName = AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "");
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Telemetry");
            string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Telemetry", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName) + ".telemetry");
            string logFile = Path.Combine(path, appName + "-log.telemetry");
            string backup = file + ".bak";

            try
            {
                if (File.Exists(file)) File.Delete(file);
                if (File.Exists(backup)) File.Delete(backup);
                if (File.Exists(logFile)) File.Delete(logFile);
                Logger.LogWarning("Cleaned telemetry database for fresh test run.");
            }
            catch (Exception ex)
            {
                Logger.LogError($"Failed to clear telemetry database: {ex.Message}");
            }
        }
    }
}