using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

using ITC81DB_0H.Forms;

namespace ITC81DB_0H
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            try
            {
                Application.Run(new FormMain());
            }
            catch (Exception ex)
            {
                bool fileCheck = false, directoryCheck = false;
                string fullFilePath = "", message = "";
                StreamWriter sw;

                DateTime time = DateTime.Now;

                fullFilePath = string.Format("SD Card\\DataBackup\\{0:yyyyMMdd_HHmmss}.txt", time);
                message = ex.ToString();

                DirectoryInfo di = new DirectoryInfo("SD Card\\DataBackup\\");
                directoryCheck = di.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    di.Create();

                FileInfo fileInfo = new FileInfo(fullFilePath);
                fileCheck = fileInfo.Exists;

                sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);
                sw.WriteLine(time.ToString("yyyy-MM-dd HH:mm:ss"));
                sw.Write(message);
                sw.WriteLine();
                sw.Close();

                MessageBox.Show(message);
            }
        }
    }
}