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

namespace ryCommon
{
    /// <summary>
    /// 文件信息
    /// </summary>
    public class RySoft
    {
        /// <summary>
        /// 获取版本号
        /// </summary>
        public static string VersionStr
        {
            get
            {
                //Version ver = Assembly.LoadFile(Application.ExecutablePath).GetName().Version;
                //Version ver = Assembly.GetEntryAssembly().GetName().Version;
                //return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.;
                return GetVersionStr(Application.ExecutablePath);
            }
        }
        /// <summary>
        /// 获取版本号
        /// </summary>
        /// <param name="exe_path"></param>
        /// <returns></returns>
        public static string GetVersionStr(string exe_path)
        {
            try
            {
                System.Diagnostics.FileVersionInfo info = System.Diagnostics.FileVersionInfo.GetVersionInfo(exe_path);
                return info.ProductVersion;
            }
            catch { return ""; }
            //Version ver = Assembly.LoadFile(exe_path).GetName().Version;
            //return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.Revision.ToString();
        }
        /// <summary>
        /// 判断是否是管理员方式运行
        /// </summary>
        /// <returns></returns>
        public static bool IsAdministrator()
        {
            System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
            return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
        }
    }
}
