PdnInfo.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using Resources;
  2. using System;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace SmartCoalApplication.Resources
  9. {
  10. /// <summary>
  11. /// 特定的本应用程序相关的功能
  12. /// </summary>
  13. public static class PdnInfo
  14. {
  15. private static Icon appIcon;
  16. public static Icon AppIcon
  17. {
  18. get
  19. {
  20. if (appIcon == null)
  21. {
  22. Stream stream = PdnResources.GetResourceStream("Icons.sanas.ico");
  23. appIcon = new Icon(stream);
  24. stream.Close();
  25. }
  26. return appIcon;
  27. }
  28. }
  29. public static DateTime BuildTime
  30. {
  31. get
  32. {
  33. Version version = GetVersion();
  34. DateTime time = new DateTime(2000, 1, 1, 0, 0, 0);
  35. time = time.AddDays(version.Build);
  36. time = time.AddSeconds(version.Revision * 2);
  37. return time;
  38. }
  39. }
  40. /// <summary>
  41. /// Gets the full path to where user customization files should be stored.
  42. /// </summary>
  43. /// <returns>
  44. /// User data files should include settings or customizations that don't go into data files such as *.PDN.
  45. /// An example of a user data file is a color palette.
  46. /// </returns>
  47. public static string UserDataPath
  48. {
  49. get
  50. {
  51. string myDocsPath = SystemLayer.Shell.GetVirtualPath(SystemLayer.VirtualFolderName.UserDocuments, true);
  52. string userDataDirName = PdnResources.GetString("SystemLayer.UserDataDirName");
  53. string userDataPath = Path.Combine(myDocsPath, userDataDirName);
  54. return userDataPath;
  55. }
  56. }
  57. private static string GetAppConfig()
  58. {
  59. object[] attributes = typeof(PdnInfo).Assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
  60. AssemblyConfigurationAttribute aca = (AssemblyConfigurationAttribute)attributes[0];
  61. return aca.Configuration;
  62. }
  63. private static readonly bool isFinalBuild = GetIsFinalBuild();
  64. private static bool GetIsFinalBuild()
  65. {
  66. return !(GetAppConfig().IndexOf("Final", StringComparison.OrdinalIgnoreCase) == -1);
  67. }
  68. public static bool IsFinalBuild
  69. {
  70. get
  71. {
  72. return isFinalBuild;
  73. }
  74. }
  75. public static bool IsDebugBuild
  76. {
  77. get
  78. {
  79. return false;
  80. }
  81. }
  82. public const int BetaExpireTimeDays = 60;
  83. public static DateTime ExpirationDate
  84. {
  85. get
  86. {
  87. if (PdnInfo.IsFinalBuild && !IsDebugBuild)
  88. {
  89. return DateTime.MaxValue;
  90. }
  91. else
  92. {
  93. return PdnInfo.BuildTime + new TimeSpan(BetaExpireTimeDays, 0, 0, 0);
  94. }
  95. }
  96. }
  97. public static string GetApplicationDir()
  98. {
  99. string appPath = Application.StartupPath;
  100. return appPath;
  101. }
  102. public static string GetProductName(bool withTag)
  103. {
  104. string bareProductName = GetBareProductName();
  105. string productNameFormat = PdnResources.GetString("Application.ProductName.Format");
  106. string tag;
  107. if (withTag)
  108. {
  109. string tagFormat = PdnResources.GetString("Application.ProductName.Tag.Format");
  110. tag = string.Format(tagFormat, GetAppConfig());
  111. }
  112. else
  113. {
  114. tag = string.Empty;
  115. }
  116. string version = "1.10";
  117. string productName = string.Format(
  118. productNameFormat,
  119. bareProductName,
  120. version,
  121. tag);
  122. return productName;
  123. }
  124. public static string GetBareProductName()
  125. {
  126. return "SANAS Vision";
  127. }
  128. private static string copyrightString = null;
  129. public static string GetCopyrightString()
  130. {
  131. copyrightString = "Copyright 2020 HuiHong. All rights reserved.";
  132. return copyrightString;
  133. }
  134. public static Version GetVersion()
  135. {
  136. return new Version(Application.ProductVersion);
  137. }
  138. public static string GetVersionNumberString(Version version, int fieldCount)
  139. {
  140. if (fieldCount < 1 || fieldCount > 4)
  141. {
  142. throw new ArgumentOutOfRangeException("fieldCount", "must be in the range [1, 4]");
  143. }
  144. StringBuilder sb = new StringBuilder();
  145. sb.Append(version.Major.ToString());
  146. if (fieldCount >= 2)
  147. {
  148. //sb.AppendFormat(".{0}", version.Minor.ToString("D2"));
  149. }
  150. if (fieldCount >= 3)
  151. {
  152. sb.AppendFormat(".{0}", version.Build.ToString());
  153. }
  154. if (fieldCount == 4)
  155. {
  156. sb.AppendFormat(".{0}", version.Revision.ToString());
  157. }
  158. return sb.ToString();
  159. }
  160. public static string GetFullAppName()
  161. {
  162. return PdnInfo.GetProductName(false);
  163. }
  164. public static string GetAppName()
  165. {
  166. if (PdnInfo.IsFinalBuild && !PdnInfo.IsDebugBuild)
  167. {
  168. return PdnInfo.GetProductName(false);
  169. }
  170. else
  171. {
  172. return GetFullAppName();
  173. }
  174. }
  175. }
  176. }