using Helper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Windows.Forms;
using Update;

namespace SunnyMusic
{
    static class Program
    {
        /// <summary>
        /// 版本信息
        /// </summary>
        public static VersionInfo Info
        {
            get
            {
                VersionInfo ver = new VersionInfo();
                Assembly assembly = Assembly.Load("DAL");
                AssemblyName assemblyName = assembly.GetName();
                ver.Time = new DateTime(2020, 12, 21);
                ver.DALVersion = assemblyName.Version;
                ver.UIVersion = Assembly.GetExecutingAssembly().GetName().Version;
                return ver;
            }
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        //[System.STAThreadAttribute]
        static void Main(string[] args)
        {
            //允许跨线程访问控件
            FrmUpdate.UpdateUrl = "http://" + MusicHelper.Ip + "/update.aspx";
            Control.CheckForIllegalCrossThreadCalls = false;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new FrmBack());
            //return;
            WakeupServer();
            if (args.Length == 0)
            {
                Application.Run(new FrmMain());
            }
            else { Application.Run(new FrmMain(Music.FromFile(args[0]))); }
        }

        /// <summary>
        /// 免费服务器不好使,需要提前访问一下以唤醒服务器
        /// </summary>
        public static void WakeupServer()
        {
            try
            {
                HttpHelper.Get(FrmUpdate.UpdateUrl);
            }
            catch
            { }
        }

        #region 程序集特性访问器(代码自动生成)
        public static string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }
        public static string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }
        public static string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }
        public static string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }
        public static string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }
        public static string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion
    }
}
