123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- using System;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Reflection;
- using System.Text;
- using System.Windows.Forms;
- namespace PaintDotNet
- {
- /// <summary>
- /// 特定的本应用程序相关的功能
- /// </summary>
- public static class PdnInfo
- {
- private static Icon appIcon;
- public static Icon AppIcon
- {
- get
- {
- if (appIcon == null)
- {
- Stream stream = PdnResources.GetResourceStream("Icons.Metis.ico");
- appIcon = new Icon(stream);
- stream.Close();
- }
- return appIcon;
- }
- }
- /// <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(PaintDotNet.SystemLayer.VirtualFolderName.UserDocuments, true);
- string userDataDirName = PdnResources.GetString("SystemLayer.UserDataDirName");
- string userDataPath = Path.Combine(myDocsPath, userDataDirName);
- return userDataPath;
- }
- }
- private static StartupTestType startupTest = StartupTestType.None;
- public static StartupTestType StartupTest
- {
- get
- {
- return startupTest;
- }
- set
- {
- startupTest = value;
- }
- }
- private static bool isTestMode = false;
- public static bool IsTestMode
- {
- get
- {
- return isTestMode;
- }
- set
- {
- isTestMode = value;
- }
- }
- 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;
- }
- }
- 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") == -1);
- }
- public static bool IsFinalBuild
- {
- get
- {
- return isFinalBuild;
- }
- }
- public static bool IsDebugBuild
- {
- get
- {
- #if DEBUG
- return true;
- #else
- return false;
- #endif
- }
- }
- // Pre-release builds expire after this many days. (debug+"final" also equals expiration)
- 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 bool IsExpired
- {
- get
- {
- if (!PdnInfo.IsFinalBuild || PdnInfo.IsDebugBuild)
- {
- if (DateTime.Now > PdnInfo.ExpirationDate)
- {
- return true;
- }
- }
- return false;
- }
- }
- public static bool HandleExpiration(IWin32Window owner)
- {
- if (IsExpired)
- {
- string expiredMessage = PdnResources.GetString("ExpiredDialog.Message");
- DialogResult result = MessageBox.Show(expiredMessage, PdnInfo.GetProductName(true),
- MessageBoxButtons.OKCancel);
- if (result == DialogResult.OK)
- {
- string expiredRedirect = "http://www.baidu.com"; //InvariantStrings.ExpiredPage;
- PdnInfo.LaunchWebSite(owner, expiredRedirect);
- }
- return false;
- }
- return true;
- }
- public static string GetApplicationDir()
- {
- string appPath = Application.StartupPath;
- return appPath;
- }
- public static string GetProductName()
- {
- return GetProductName(!IsFinalBuild);
- }
- 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 = GetVersionNumberString(GetVersion(), 3);
- string productName = string.Format(
- productNameFormat,
- bareProductName,
- version,
- tag);
- return productName;
- }
- public static string GetBareProductName()
- {
- return "Metis Vision";//PdnResources.GetString("Application.ProductName.Bare");
- }
- private static string copyrightString = null;
- public static string GetCopyrightString()
- {
- /*if (copyrightString == null)
- {
- string format = " Corporation. {0}";
- string allRightsReserved = PdnResources.GetString("Application.Copyright.AllRightsReserved");
- copyrightString = string.Format(CultureInfo.CurrentCulture, format, allRightsReserved);
- }
- return copyrightString;*/
- copyrightString = "Copyright 2020 HuiHong. All rights reserved.";
- return copyrightString;
- }
- public static Version GetVersion()
- {
- return new Version(Application.ProductVersion);
- }
- private static string GetConfigurationString()
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
- AssemblyConfigurationAttribute aca = (AssemblyConfigurationAttribute)attributes[0];
- return aca.Configuration;
- }
- /// <summary>
- /// Returns a full version string of the form: ApplicationConfiguration + BuildType + BuildVersion
- /// i.e.: "Beta 2 Debug build 1.0.*.*"
- /// </summary>
- /// <returns></returns>
- public static string GetVersionString()
- {
- string buildType =
- #if DEBUG
- "Debug";
- #else
- "Release";
- #endif
- string versionFormat = PdnResources.GetString("PdnInfo.VersionString.Format");
- string versionText = string.Format(
- versionFormat,
- GetConfigurationString(),
- buildType,
- GetVersionNumberString(GetVersion(), 4));
- //return versionText;
- return "";
- }
- /// <summary>
- /// Returns a string for just the version number, i.e. "3.01"
- /// </summary>
- /// <returns></returns>
- 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 GetFriendlyVersionString()
- {
- Version version = PdnInfo.GetVersion();
- string versionFormat = PdnResources.GetString("PdnInfo.FriendlyVersionString.Format");
- string configFormat = PdnResources.GetString("PdnInfo.FriendlyVersionString.ConfigWithSpace.Format");
- string config = string.Format(configFormat, GetConfigurationString());
- string configText;
- if (PdnInfo.IsFinalBuild)
- {
- configText = string.Empty;
- }
- else
- {
- configText = config;
- }
- string versionText = string.Format(versionFormat, GetVersionNumberString(version, 2), configText);
- return versionText;
- }
- public static string GetFullAppName()
- {
- return PdnInfo.GetProductName(false);
- //string fullAppNameFormat = PdnResources.GetString("PdnInfo.FullAppName.Format");
- //string fullAppName = string.Format(fullAppNameFormat, PdnInfo.GetProductName(false), GetVersionString());
- //return fullAppName;
- }
- public static string GetAppName()
- {
- if (PdnInfo.IsFinalBuild && !PdnInfo.IsDebugBuild)
- {
- return PdnInfo.GetProductName(false);
- }
- else
- {
- return GetFullAppName();
- }
- }
- public static void LaunchWebSite(IWin32Window owner)
- {
- LaunchWebSite(owner, null);
- }
- public static void LaunchWebSite(IWin32Window owner, string page)
- {
- string webSite = "http://www.baidu.com";// InvariantStrings.WebsiteUrl;
- Uri baseUri = new Uri(webSite);
- Uri uri;
- if (page == null)
- {
- uri = baseUri;
- }
- else
- {
- uri = new Uri(baseUri, page);
- }
- string url = uri.ToString();
- if (url.IndexOf("@") == -1)
- {
- OpenUrl(owner, url);
- }
- }
- public static bool OpenUrl(IWin32Window owner, string url)
- {
- bool result = SystemLayer.Shell.LaunchUrl(owner, url);
- if (!result)
- {
- string messageFormat = PdnResources.GetString("LaunchLink.Error.Format");
- string message = string.Format(messageFormat, url);
- MessageBox.Show(owner, message, PdnInfo.GetBareProductName(), MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- return result;
- }
- public static string GetNgenPath()
- {
- return GetNgenPath(false);
- }
- public static string GetNgenPath(bool force32bit)
- {
- string fxDir;
- if (UIntPtr.Size == 8 && !force32bit)
- {
- fxDir = "Framework64";
- }
- else
- {
- fxDir = "Framework";
- }
- string fxPathBase = @"%WINDIR%\Microsoft.NET\" + fxDir + @"\v";
- string fxPath = fxPathBase + Environment.Version.ToString(3) + @"\";
- string fxPathExp = System.Environment.ExpandEnvironmentVariables(fxPath);
- string ngenExe = Path.Combine(fxPathExp, "ngen.exe");
- return ngenExe;
- }
- }
- }
|