<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;

namespace DiabloInterface
{
    public class SettingsHolder
    {
        const string defaultSettingsFile = "settings.conf";

        public string fileFolder = "txt";
        public string fontName = "Courier New";
        public string d2Version = "";
        public int fontSize = 10;
        public int titleFontSize = 18;
        public bool createFiles = false;
        public bool doAutosplit = false;
        public bool showDebug = false;
        public bool checkUpdates = false;
        public string triggerKeys = "";
        public List<AutoSplit> autosplits = new List<AutoSplit>();
        public List<int> runes = new List<int>();

        public void saveAs(string file)
        {
            Dictionary<string, dynamic> dict = new Dictionary<string, dynamic>();

            string confString = "";
            confString += "Font: " + fontName + "\n";
            confString += "FontSize: " + fontSize + "\n";
            confString += "FontSizeTitle: " + titleFontSize + "\n";
            confString += "CreateFiles: " + (createFiles ? "1" : "0") + "\n";
            confString += "DoAutosplit: " + (doAutosplit ? "1" : "0") + "\n";
            confString += "ShowDebug: " + (showDebug ? "1" : "0") + "\n";
            confString += "CheckUpdates: " + (checkUpdates ? "1" : "0") + "\n";
            confString += "TriggerKeys: " + triggerKeys + "\n";
            confString += "D2Version: " + d2Version + "\n";
            foreach (AutoSplit autosplit in autosplits)
            {
                confString += "AutoSplit: " + autosplit.name.Replace('|', ' ') + "|" + (int)autosplit.type + "|" + autosplit.value + "|" + autosplit.difficulty + "\n";
            }
            foreach (int rune in runes)
            {
                confString += "Rune: " + rune + "\n";
            }

            Properties.Settings.Default.SettingsFile = file;
            Properties.Settings.Default.Save();

            File.WriteAllText(file, confString);
        }

        public void loadFrom(string file)
        {
            Properties.Settings.Default.SettingsFile = file;
            Properties.Settings.Default.Save();

            if (!File.Exists(file))
            {
                return;
            }

            List<AutoSplit> autosplitsNew = new List<AutoSplit>();
            string[] conf = File.ReadAllLines(file);
            string[] parts;<commit_msg>Minor fix for saving settings.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;

namespace DiabloInterface
{
    public class SettingsHolder
    {
        const string defaultSettingsFile = "settings.conf";

        public string fileFolder;
        public string fontName;
        public string d2Version;
        public int fontSize;
        public int titleFontSize;
        public bool createFiles;
        public bool doAutosplit;
        public bool showDebug;
        public bool checkUpdates;
        public string triggerKeys;
        public List<AutoSplit> autosplits;
        public List<int> runes;

        public SettingsHolder ()
        {
            // init members with default values
            init();
        }

        private void init()
        {
            fileFolder = "txt";
            fontName = "Courier New";
            d2Version = "";
            fontSize = 10;
            titleFontSize = 18;
            createFiles = false;
            doAutosplit = false;
            showDebug = false;
            checkUpdates = false;
            triggerKeys = "";
            autosplits = new List<AutoSplit>();
            runes = new List<int>();
        }
        
        public void saveAs(string file)
        {
            Dictionary<string, dynamic> dict = new Dictionary<string, dynamic>();

            string confString = "";
            confString += "Font: " + fontName + "\n";
            confString += "FontSize: " + fontSize + "\n";
            confString += "FontSizeTitle: " + titleFontSize + "\n";
            confString += "CreateFiles: " + (createFiles ? "1" : "0") + "\n";
            confString += "DoAutosplit: " + (doAutosplit ? "1" : "0") + "\n";
            confString += "ShowDebug: " + (showDebug ? "1" : "0") + "\n";
            confString += "CheckUpdates: " + (checkUpdates ? "1" : "0") + "\n";
            confString += "TriggerKeys: " + triggerKeys + "\n";
            confString += "D2Version: " + d2Version + "\n";
            foreach (AutoSplit autosplit in autosplits)
            {
                confString += "AutoSplit: " + autosplit.name.Replace('|', ' ') + "|" + (int)autosplit.type + "|" + autosplit.value + "|" + autosplit.difficulty + "\n";
            }
            foreach (int rune in runes)
            {
                confString += "Rune: " + rune + "\n";
            }

            Properties.Settings.Default.SettingsFile = file;
            Properties.Settings.Default.Save();

            File.WriteAllText(file, confString);
        }

        public void loadFrom(string file)
        {
            Properties.Settings.Default.SettingsFile = file;
            Properties.Settings.Default.Save();

            if (!File.Exists(file))
            {
                return;
            }

            // init members with default values
            init();

            List<AutoSplit> autosplitsNew = new List<AutoSplit>();
            string[] conf = File.ReadAllLines(file);
            string[] parts;
{'fraction_non_alphanumeric': 0.12481778425655976, 'fraction_numerical': 0.00564868804664723, 'mean_word_length': 1.7764289327263532, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '2122522', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1465, 'n_words': 362}