<commit_before>﻿namespace Mappy.IO
{
    using System.IO;

    using Mappy.Data;
    using Mappy.Models;

    using TAUtil.Hpi;
    using TAUtil.Tnt;

    /// <summary>
    /// Provides methods for writing out a IMapModel instance
    /// as TNT or HPI.
    /// </summary>
    public class MapSaver
    {
        public void SaveTnt(IMapModel map, string filename)
        {
            using (var s = new TntWriter(File.Create(filename)))
            {
                s.WriteTnt(new MapModelTntAdapter(map));
            }
        }

        public void SaveOta(MapAttributes attrs, string filename)
        {
            using (Stream s = File.Create(filename))
            {
                attrs.WriteOta(s);
            }
        }

        public void SaveHpi(IMapModel map, string filename)
        {
            string tmpTntName = Path.GetTempFileName();
            string tmpOtaName = Path.GetTempFileName();

            try
            {
                using (var s = new TntWriter(File.Create(tmpTntName)))
                {
                    s.WriteTnt(new MapModelTntAdapter(map));
                }

                using (Stream s = File.Create(tmpOtaName))
                {
                    map.Attributes.WriteOta(s);
                }

                string fname = "maps\\" + map.Attributes.Name;

                using (HpiWriter wr = new HpiWriter(filename, HpiWriter.CompressionMethod.ZLib))
                {
                    wr.AddFile(fname + ".tnt", tmpTntName);
                    wr.AddFile(fname + ".ota", tmpOtaName);
                }
            }
            finally
            {<commit_msg>Use saved filename as map title instead of missionname<commit_after>﻿namespace Mappy.IO
{
    using System.IO;

    using Mappy.Data;
    using Mappy.Models;

    using TAUtil.Hpi;
    using TAUtil.Tnt;

    /// <summary>
    /// Provides methods for writing out a IMapModel instance
    /// as TNT or HPI.
    /// </summary>
    public class MapSaver
    {
        public void SaveTnt(IMapModel map, string filename)
        {
            using (var s = new TntWriter(File.Create(filename)))
            {
                s.WriteTnt(new MapModelTntAdapter(map));
            }
        }

        public void SaveOta(MapAttributes attrs, string filename)
        {
            using (Stream s = File.Create(filename))
            {
                attrs.WriteOta(s);
            }
        }

        public void SaveHpi(IMapModel map, string filename)
        {
            string namePart = Path.GetFileNameWithoutExtension(filename);

            string tmpTntName = Path.GetTempFileName();
            string tmpOtaName = Path.GetTempFileName();

            try
            {
                using (var s = new TntWriter(File.Create(tmpTntName)))
                {
                    s.WriteTnt(new MapModelTntAdapter(map));
                }

                using (Stream s = File.Create(tmpOtaName))
                {
                    map.Attributes.WriteOta(s);
                }

                string fname = "maps\\" + namePart;

                using (HpiWriter wr = new HpiWriter(filename, HpiWriter.CompressionMethod.ZLib))
                {
                    wr.AddFile(fname + ".tnt", tmpTntName);
                    wr.AddFile(fname + ".ota", tmpOtaName);
                }
            }
            finally
            {
{'fraction_non_alphanumeric': 0.09300265721877768, 'fraction_numerical': 0.0, 'mean_word_length': 1.3285223367697594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5790118', 'n_tokens_mistral': 963, 'n_tokens_neox': 911, 'n_words': 201}