<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using TribalWars.Data;

namespace TribalWars.Forms
{
    public partial class LoadWorldForm : Form
    {
        #region Fields
        private string[] _existingWorlds;
        #endregion

        #region Constants
        const int ImageWorld = 0;
        const int ImageData = 1;
        const int ImageSettings = 2;

        const string PathDataWorldFormat = "yyyyMMddHH";
        const string PathDataWorldFormatShort = "yyyyMMdd";
        #endregion

        #region Constructors
        public LoadWorldForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Events
        private void LoadWorldForm_Load(object sender, EventArgs e)
        {
            // Load last selected world
            FillTree();
            if (Worlds.Nodes.ContainsKey(TribalWars.Properties.Settings.Default.LastWorld))
            {
                Worlds.SelectedNode = Worlds.Nodes[TribalWars.Properties.Settings.Default.LastWorld];
                Worlds.SelectedNode.Expand();
            }

            // Add a new world
            IEnumerable<string> worlds = World.GetAllWorlds();
            AvailableWorlds.DataSource = worlds.Where(x => !_existingWorlds.Contains(x)).ToArray();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            string path = FindSelectedWorldPath();
            string pathData = FindSelectedWorldDataPath();
            if (path.Length == 0)
            {
                MessageBox.Show("No world selected!");
            }
            else
            {
                string settings = World.InternalStructure.DefaultSettingsString;
                if (WorldSettings.SelectedItems.Count == 1)
                {
                    settings = WorldSettings.SelectedItems[0].Tag.ToString();
                }

                // save last selected world
                TribalWars.Properties.Settings.Default.LastWorld = path;
                TribalWars.Properties.Settings.Default.LastSettings = settings;
                TribalWars.Properties.Settings.Default.Save();

                World.Default.LoadWorld(pathData, settings);
                Close();
            }
        }

        private void Worlds_AfterSelect(object sender, TreeViewEventArgs e)
        {
            WorldSettings.Items.Clear();
            string pathSettings = FindSelectedWorldPath();
            if (pathSettings.Length > 0)<commit_msg>LoadWorld: bugfix saving last opened world (final:)<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using TribalWars.Data;

namespace TribalWars.Forms
{
    public partial class LoadWorldForm : Form
    {
        #region Fields
        private string[] _existingWorlds;
        #endregion

        #region Constants
        const int ImageWorld = 0;
        const int ImageData = 1;
        const int ImageSettings = 2;

        const string PathDataWorldFormat = "yyyyMMddHH";
        const string PathDataWorldFormatShort = "yyyyMMdd";
        #endregion

        #region Constructors
        public LoadWorldForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Events
        private void LoadWorldForm_Load(object sender, EventArgs e)
        {
            // Load last selected world
            FillTree();
            if (Worlds.Nodes.ContainsKey(TribalWars.Properties.Settings.Default.LastWorld))
            {
                Worlds.SelectedNode = Worlds.Nodes[TribalWars.Properties.Settings.Default.LastWorld];
                Worlds.SelectedNode.Expand();
            }

            // Add a new world
            IEnumerable<string> worlds = World.GetAllWorlds();
            AvailableWorlds.DataSource = worlds.Where(x => !_existingWorlds.Contains(x)).ToArray();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            string path = FindSelectedWorldPath();
            string pathData = FindSelectedWorldDataPath();
            if (path.Length == 0)
            {
                MessageBox.Show("No world selected!");
            }
            else
            {
                string settings = World.InternalStructure.DefaultSettingsString;
                if (WorldSettings.SelectedItems.Count == 1)
                {
                    settings = WorldSettings.SelectedItems[0].Tag.ToString() + World.InternalStructure.SettingsExtensionString;
                }

                // save last selected world
                TribalWars.Properties.Settings.Default.LastWorld = path;
                TribalWars.Properties.Settings.Default.LastSettings = settings;
                TribalWars.Properties.Settings.Default.Save();

                World.Default.LoadWorld(pathData, settings);
                Close();
            }
        }

        private void Worlds_AfterSelect(object sender, TreeViewEventArgs e)
        {
            WorldSettings.Items.Clear();
            string pathSettings = FindSelectedWorldPath();
            if (pathSettings.Length > 0)
{'fraction_non_alphanumeric': 0.08173076923076923, 'fraction_numerical': 0.002692307692307692, 'mean_word_length': 1.8405243036592027, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4311421', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1246, 'n_words': 274}