123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using Resources;
- using System;
- using System.Drawing;
- using System.IO;
- using System.Reflection;
- using System.Text;
- using System.Windows.Forms;
- namespace SmartCoalApplication.Resources
- {
- /// <summary>
- /// 特定的本应用程序相关的功能
- /// </summary>
- public static class PdnInfo
- {
- private static Icon appIcon;
- public static Icon AppIcon
- {
- get
- {
- if (appIcon == null)
- {
- Stream stream = PdnResources.GetResourceStream("Icons.sanas.ico");
- appIcon = new Icon(stream);
- stream.Close();
- }
- return appIcon;
- }
- }
- public static DateTime BuildTime
- {
- get
- {
- Version version = GetVersion();
- DateTime time = new DateTime(2000, 1, 1, 0, 0, 0);
- time = time.AddDays(version.Build);
- time = time.AddSeconds(version.Revision * 2);
- return time;
- }
- }
- /// <summary>
- /// Gets the full path to where user customization files should be stored.
- /// </summary>
- /// <returns>
- /// User data files should include settings or customizations that don't go into data files such as *.PDN.
- /// An example of a user data file is a color palette.
- /// </returns>
- public static string UserDataPath
- {
- get
- {
- string myDocsPath = SystemLayer.Shell.GetVirtualPath(SystemLayer.VirtualFolderName.UserDocuments, true);
- string userDataDirName = PdnResources.GetString("SystemLayer.UserDataDirName");
- string userDataPath = Path.Combine(myDocsPath, userDataDirName);
- return userDataPath;
- }
- }
- private static string GetAppConfig()
- {
- object[] attributes = typeof(PdnInfo).Assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
- AssemblyConfigurationAttribute aca = (AssemblyConfigurationAttribute)attributes[0];
- return aca.Configuration;
- }
- private static readonly bool isFinalBuild = GetIsFinalBuild();
- private static bool GetIsFinalBuild()
- {
- return !(GetAppConfig().IndexOf("Final", StringComparison.OrdinalIgnoreCase) == -1);
- }
- public static bool IsFinalBuild
- {
- get
- {
- return isFinalBuild;
- }
- }
- public static bool IsDebugBuild
- {
- get
- {
- return false;
- }
- }
- public const int BetaExpireTimeDays = 60;
- public static DateTime ExpirationDate
- {
- get
- {
- if (PdnInfo.IsFinalBuild && !IsDebugBuild)
- {
- return DateTime.MaxValue;
- }
- else
- {
- return PdnInfo.BuildTime + new TimeSpan(BetaExpireTimeDays, 0, 0, 0);
- }
- }
- }
- public static string GetApplicationDir()
- {
- string appPath = Application.StartupPath;
- return appPath;
- }
- public static string GetProductName(bool withTag)
- {
- string bareProductName = GetBareProductName();
- string productNameFormat = PdnResources.GetString("Application.ProductName.Format");
- string tag;
- if (withTag)
- {
- string tagFormat = PdnResources.GetString("Application.ProductName.Tag.Format");
- tag = string.Format(tagFormat, GetAppConfig());
- }
- else
- {
- tag = string.Empty;
- }
- string version = "1.10";
- string productName = string.Format(
- productNameFormat,
- bareProductName,
- version,
- tag);
- return productName;
- }
- public static string GetBareProductName()
- {
- return "SANAS Vision";
- }
- private static string copyrightString = null;
- public static string GetCopyrightString()
- {
- copyrightString = "Copyright 2020 HuiHong. All rights reserved.";
- return copyrightString;
- }
- public static Version GetVersion()
- {
- return new Version(Application.ProductVersion);
- }
- public static string GetVersionNumberString(Version version, int fieldCount)
- {
- if (fieldCount < 1 || fieldCount > 4)
- {
- throw new ArgumentOutOfRangeException("fieldCount", "must be in the range [1, 4]");
- }
- StringBuilder sb = new StringBuilder();
- sb.Append(version.Major.ToString());
- if (fieldCount >= 2)
- {
- //sb.AppendFormat(".{0}", version.Minor.ToString("D2"));
- }
- if (fieldCount >= 3)
- {
- sb.AppendFormat(".{0}", version.Build.ToString());
- }
- if (fieldCount == 4)
- {
- sb.AppendFormat(".{0}", version.Revision.ToString());
- }
- return sb.ToString();
- }
- public static string GetFullAppName()
- {
- return PdnInfo.GetProductName(false);
- }
- public static string GetAppName()
- {
- if (PdnInfo.IsFinalBuild && !PdnInfo.IsDebugBuild)
- {
- return PdnInfo.GetProductName(false);
- }
- else
- {
- return GetFullAppName();
- }
- }
- }
- }
|