using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace MicronSync.Components
{
    public partial class ChangeLog : Form
    {
        public ChangeLog()
        {
            InitializeComponent();
        }

        private void ChangeLog_Load(object sender, System.EventArgs e)
        {
            var assembly = Assembly.GetExecutingAssembly();

            labelVersionInfo.Text = $"MicronSync: {assembly.GetName().Version}";

            using (Stream steam = assembly.GetManifestResourceStream("MicronSync.Components.Forms.ChangeLog.txt"))
            using (StreamReader sr = new StreamReader(steam, true))
            {
                List<string> listChangelog = new List<string>();

                string currentLine;
                while (!string.IsNullOrEmpty(
                    currentLine = sr.ReadLine()))
                {
                    if (currentLine.Contains(@"//"))
                    {
                        currentLine = currentLine.Remove(currentLine.IndexOf(@"//"));
                        if (!string.IsNullOrEmpty(currentLine))
                            listChangelog.Add(currentLine);
                    }
                    else
                        listChangelog.Add(currentLine);
                }

                richTextBox.Text = string.Join(Environment.NewLine, listChangelog);
            }
        }
    }
}
