<commit_before>﻿using System;
using System.Linq;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell.Settings;

namespace AttachToolbar
{
    public class SettingsManager
    {
        public SettingsManager(Package settingProvider)
        {
            ShellSettingsManager settingsManager = new ShellSettingsManager(settingProvider);
            _settings = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
            LoadSettings();
        }

        public void LoadSettings()
        {
            try
            {
                string attachList = _settings.GetString("AttachToolbar", "ProcessList");
                State.ProcessList = attachList.Split(';').ToList();

                string lastProgram = _settings.GetString("AttachToolbar", "LastProcessName");
                State.ProcessName = State.ProcessList.Contains(lastProgram) ?
                    lastProgram : State.ProcessList.First();

                State.EngineType = _settings.GetString("AttachToolbar", "LastEngineType").GetAttachType();
            }
            catch (Exception)
            {
                CreateDefaultSettings();
                State.Clear();
            }
        }

        public void SaveSettings()
        {
            _settings.SetString("AttachToolbar", "ProcessList", string.Join(";", State.ProcessList));
            _settings.SetString("AttachToolbar", "LastProcessName", State.ProcessName);
            _settings.SetString("AttachToolbar", "LastEngineType", State.EngineType.GetEngineName());
        }

        private void CreateDefaultSettings()
        {
            _settings.DeleteCollection("AttachToolbar");
            _settings.CreateCollection("AttachToolbar");
            _settings.SetString("AttachToolbar", "ProcessList", "");
            _settings.SetString("AttachToolbar", "LastProcessName", "");
            _settings.SetString("AttachToolbar", "LastEngineType", EngineType.Native.GetEngineName());
        }

        private readonly WritableSettingsStore _settings;
    }
}<commit_msg>Read-write process index to settings<commit_after>﻿using System;
using System.Linq;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell.Settings;

namespace AttachToolbar
{
    public class SettingsManager
    {
        public SettingsManager(Package settingProvider)
        {
            ShellSettingsManager settingsManager = new ShellSettingsManager(settingProvider);
            _settings = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
            LoadSettings();
        }

        public void LoadSettings()
        {
            try
            {
                string attachList = _settings.GetString("AttachToolbar", "ProcessList");
                State.ProcessList = attachList.Split(';').ToList();

                State.ProcessIndex = _settings.GetInt32("AttachToolbar", "ProcessIndex");
                State.EngineType = _settings.GetString("AttachToolbar", "EngineType").GetAttachType();
            }
            catch (Exception)
            {
                CreateDefaultSettings();
                State.Clear();
            }
        }

        public void SaveSettings()
        {
            _settings.SetString("AttachToolbar", "ProcessList", string.Join(";", State.ProcessList));
            _settings.SetInt32("AttachToolbar", "ProcessIndex", State.ProcessIndex);
            _settings.SetString("AttachToolbar", "EngineType", State.EngineType.GetEngineName());
        }

        private void CreateDefaultSettings()
        {
            _settings.DeleteCollection("AttachToolbar");
            _settings.CreateCollection("AttachToolbar");
            _settings.SetString("AttachToolbar", "ProcessList", "");
            _settings.SetInt32("AttachToolbar", "ProcessIndex", -1);
            _settings.SetString("AttachToolbar", "EngineType", EngineType.Native.GetEngineName());
        }

        private readonly WritableSettingsStore _settings;
    }
}
{'fraction_non_alphanumeric': 0.10309278350515463, 'fraction_numerical': 0.001718213058419244, 'mean_word_length': 2.5008591065292096, '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': '4694377', 'n_tokens_mistral': 976, 'n_tokens_neox': 974, 'n_words': 158}