using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Security.Principal;

namespace NewPosInstaller
{
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            // 작업디렉토리 설정 
            ComLib.CreateDirectory(DirInfo.WorkDir);
            ComLib.CreateDirectory(DirInfo.LogDir);
            ComLib.CreateDirectory(DirInfo.DownDir);
            ComLib.CreateDirectory(DirInfo.TempDir);

            // 로그 리스너 시작 
            ComLog.Start();

            string processName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName(processName);
            if (process.Length > 1)
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "The Application is already running.");
            }
            else
            {
                //IsAdministrator();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmInstaller());
            }

            // 로그 리스너 종료 
            ComLog.Stop();
        }

        private static bool IsAdministrator()
        {
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
 
            if (null != identity)
            {
                WindowsPrincipal principal = new WindowsPrincipal(identity);
                return principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
            return false;
        }
    }
}
