/* ==============================================================================
 * 功能描述：App  
 * 创 建 者：Garrett
 * 创建日期：2019/9/16 20:39:19
 * ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using SAGA.DotNetUtils;

namespace Test
{
    /// <summary>
    /// App
    /// </summary>
    class App
    {
        [STAThread]
        static void Main(string[] args)
        {
#if DEBUG
            MainWindow win = new MainWindow();
            Application myAp = new Application();
            myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            myAp.Run(win);
#else
    string fullPath = Path.Combine(AppBaseInfo.AppRunPath, "Updater", "Update.exe");
            //有参数时直接启动
            if (args != null && args.Length > 0 || !File.Exists(fullPath))
            {
                MainWindow win = new MainWindow();
                Application myAp = new Application();
                myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                myAp.Run(win);
            }
            else
            {
                try
                {
                    //无参数可看做双击启动，启动前检测版本
                    //arguments参数用空格分开，"Program Files"使用时被拆分成两个参数，使用时请注意
                    //设置启动动作,确保以管理员身份运行
                    ProcessStartInfo startInfo = new ProcessStartInfo(fullPath)
                    {
                        UseShellExecute = true,
                        Verb = "runas",
                        WindowStyle = ProcessWindowStyle.Normal,
                        Arguments = Assembly.GetExecutingAssembly().Location,
                        CreateNoWindow = true
                    };
                    Process.Start(startInfo);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }

            }
#endif


        }
    }
}
