<commit_before>﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace TogglDesktop
{
public static class Toggl
{
    private static IntPtr ctx = IntPtr.Zero;

    public const string Project = "project";
    public const string Duration = "duration";
    public const string Description = "description";

    public const string TagSeparator = "\t";

    private const string dll = "TogglDesktopDLL.dll";
    private const CharSet charset = CharSet.Unicode;
    private const CallingConvention convention = CallingConvention.Cdecl;

    // User can override some parameters when running the app
    public static string ScriptPath;
    public static string DatabasePath;
    public static string LogPath;
    public static string Env = "production";

    // Models

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct TimeEntry
    {
        public Int64 DurationInSeconds;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Description;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectAndTaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string TaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ClientLabel;
        public UInt64 WID;
        public UInt64 PID;
        public UInt64 TID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Duration;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Color;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string GUID;
        [MarshalAs(UnmanagedType.I1)]
        public bool Billable;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Tags;
        public UInt64 Started;
        public UInt64 Ended;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string StartTimeString;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string EndTimeString;
        public UInt64 UpdatedAt;
        [MarshalAs(UnmanagedType.I1)]
        public bool DurOnly;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DateHeader;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DateDuration;
        [MarshalAs(UnmanagedType.I1)]
        public bool IsHeader;
        [MarshalAs(UnmanagedType.I1)]
        public bool CanAddProjects;
        [MarshalAs(UnmanagedType.I1)]
        public bool CanSeeBillable;
        public UInt64 DefaultWID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string WorkspaceName;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Error;
        public IntPtr Next;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct AutocompleteItem
    {
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Text;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Description;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectAndTaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string TaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ClientLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectColor;
        public UInt64 TaskID;
        public UInt64 ProjectID;
        public UInt64 WorkspaceID;
        public UInt64 Type;
        // If its a time entry, it has tags
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Tags;
        public IntPtr Next;

        public override string ToString()
        {
            return Text;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct Model
    {
        public UInt64 ID;
        public UInt64 WID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string GUID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Name;
        public IntPtr Next;

        public override string ToString()
        {
            return Name;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct Settings
    {
        [MarshalAs(UnmanagedType.I1)]
        public bool UseProxy;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyHost;
        public UInt64 ProxyPort;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyUsername;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyPassword;
        [MarshalAs(UnmanagedType.I1)]
        public bool UseIdleDetection;
        [MarshalAs(UnmanagedType.I1)]
        public bool MenubarTimer;
        [MarshalAs(UnmanagedType.I1)]
        public bool MenubarProject;
        [MarshalAs(UnmanagedType.I1)]
        public bool DockIcon;
        [MarshalAs(UnmanagedType.I1)]
        public bool OnTop;
        [MarshalAs(UnmanagedType.I1)]
        public bool Reminder;
        [MarshalAs(UnmanagedType.I1)]
        public bool RecordTimeline;
        public UInt64 IdleMinutes;
        [MarshalAs(UnmanagedType.I1)]
        public bool FocusOnShortcut;
        public UInt64 ReminderMinutes;
        [MarshalAs(UnmanagedType.I1)]
        public bool ManualMode;
        [MarshalAs(UnmanagedType.I1)]
        public bool AutodetectProxy;
        // Reminder days
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindMon;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindTue;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindWed;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindThu;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindFri;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindSat;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindSun;
        // Reminder times
        [MarshalAs(UnmanagedType.LPWStr)]
        public string RemindStarts;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string RemindEnds;

        [MarshalAs(UnmanagedType.I1)]
        public bool Autotrack;

        [MarshalAs(UnmanagedType.I1)]
        public bool OpenEditorOnShortcut;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct AutotrackerRuleView
    {
        public Int64 ID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Term;
        public UInt64 PID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectName;
        public IntPtr Next;

        public override string ToString()
        {
            return Term;
        }
    }

    // Callbacks

    [UnmanagedFunctionPointer(convention)]
    private delegate void TogglDisplayApp(
        [MarshalAs(UnmanagedType.I1)]<commit_msg>set struct setting of lib-ui interop types to 8 bytes (win)<commit_after>﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace TogglDesktop
{
public static class Toggl
{
    private static IntPtr ctx = IntPtr.Zero;

    public const string Project = "project";
    public const string Duration = "duration";
    public const string Description = "description";

    public const string TagSeparator = "\t";

    private const string dll = "TogglDesktopDLL.dll";
    private const CharSet charset = CharSet.Unicode;
    private const CallingConvention convention = CallingConvention.Cdecl;

    // User can override some parameters when running the app
    public static string ScriptPath;
    public static string DatabasePath;
    public static string LogPath;
    public static string Env = "production";

    // Models

    private const int structPackingBytes = 8;

    [StructLayout(LayoutKind.Sequential, Pack = structPackingBytes, CharSet = CharSet.Unicode)]
    public struct TimeEntry
    {
        public Int64 DurationInSeconds;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Description;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectAndTaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string TaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ClientLabel;
        public UInt64 WID;
        public UInt64 PID;
        public UInt64 TID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Duration;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Color;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string GUID;
        [MarshalAs(UnmanagedType.I1)]
        public bool Billable;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Tags;
        public UInt64 Started;
        public UInt64 Ended;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string StartTimeString;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string EndTimeString;
        public UInt64 UpdatedAt;
        [MarshalAs(UnmanagedType.I1)]
        public bool DurOnly;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DateHeader;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DateDuration;
        [MarshalAs(UnmanagedType.I1)]
        public bool IsHeader;
        [MarshalAs(UnmanagedType.I1)]
        public bool CanAddProjects;
        [MarshalAs(UnmanagedType.I1)]
        public bool CanSeeBillable;
        public UInt64 DefaultWID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string WorkspaceName;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Error;
        public IntPtr Next;
    }

    [StructLayout(LayoutKind.Sequential, Pack = structPackingBytes, CharSet = CharSet.Unicode)]
    public struct AutocompleteItem
    {
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Text;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Description;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectAndTaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string TaskLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ClientLabel;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectColor;
        public UInt64 TaskID;
        public UInt64 ProjectID;
        public UInt64 WorkspaceID;
        public UInt64 Type;
        // If its a time entry, it has tags
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Tags;
        public IntPtr Next;

        public override string ToString()
        {
            return Text;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = structPackingBytes, CharSet = CharSet.Unicode)]
    public struct Model
    {
        public UInt64 ID;
        public UInt64 WID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string GUID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Name;
        public IntPtr Next;

        public override string ToString()
        {
            return Name;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = structPackingBytes, CharSet = CharSet.Unicode)]
    public struct Settings
    {
        [MarshalAs(UnmanagedType.I1)]
        public bool UseProxy;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyHost;
        public UInt64 ProxyPort;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyUsername;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProxyPassword;
        [MarshalAs(UnmanagedType.I1)]
        public bool UseIdleDetection;
        [MarshalAs(UnmanagedType.I1)]
        public bool MenubarTimer;
        [MarshalAs(UnmanagedType.I1)]
        public bool MenubarProject;
        [MarshalAs(UnmanagedType.I1)]
        public bool DockIcon;
        [MarshalAs(UnmanagedType.I1)]
        public bool OnTop;
        [MarshalAs(UnmanagedType.I1)]
        public bool Reminder;
        [MarshalAs(UnmanagedType.I1)]
        public bool RecordTimeline;
        public UInt64 IdleMinutes;
        [MarshalAs(UnmanagedType.I1)]
        public bool FocusOnShortcut;
        public UInt64 ReminderMinutes;
        [MarshalAs(UnmanagedType.I1)]
        public bool ManualMode;
        [MarshalAs(UnmanagedType.I1)]
        public bool AutodetectProxy;
        // Reminder days
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindMon;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindTue;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindWed;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindThu;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindFri;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindSat;
        [MarshalAs(UnmanagedType.I1)]
        public bool RemindSun;
        // Reminder times
        [MarshalAs(UnmanagedType.LPWStr)]
        public string RemindStarts;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string RemindEnds;

        [MarshalAs(UnmanagedType.I1)]
        public bool Autotrack;

        [MarshalAs(UnmanagedType.I1)]
        public bool OpenEditorOnShortcut;
    }

    [StructLayout(LayoutKind.Sequential, Pack = structPackingBytes, CharSet = CharSet.Unicode)]
    public struct AutotrackerRuleView
    {
        public Int64 ID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Term;
        public UInt64 PID;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string ProjectName;
        public IntPtr Next;

        public override string ToString()
        {
            return Term;
        }
    }

    // Callbacks

    [UnmanagedFunctionPointer(convention)]
    private delegate void TogglDisplayApp(
        [MarshalAs(UnmanagedType.I1)]
{'fraction_non_alphanumeric': 0.07484601060020055, 'fraction_numerical': 0.009955593754476437, 'mean_word_length': 2.4794418141041614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '128978', 'n_tokens_mistral': 4021, 'n_tokens_neox': 3917, 'n_words': 932}