Facebook
From Botched Parakeet, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 42
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using System.Reflection;
  6.  
  7. namespace NsiTools.Utils.Utils
  8. {
  9.     /// <summary>
  10.     /// </summary>
  11.     public static class ApplicationInfo
  12.     {
  13.         /// <summary>
  14.         /// </summary>
  15.         public static Version Version =>
  16.             Assembly.GetCallingAssembly()
  17.                     .GetName()
  18.                     .Version;
  19.  
  20.         /// <summary>
  21.         /// </summary>
  22.         public static string Title
  23.         {
  24.             get
  25.             {
  26.                 var attributes = Assembly.GetCallingAssembly()
  27.                                          .GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
  28.                 if (attributes.Length > 0)
  29.                 {
  30.                     var titleAttribute = (AssemblyTitleAttribute) attributes[0];
  31.                     if (titleAttribute.Title.Length > 0) return titleAttribute.Title;
  32.                 }
  33.  
  34.                 return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly()
  35.                                                                 .CodeBase);
  36.             }
  37.         }
  38.  
  39.  
  40.         /// <summary>
  41.         /// </summary>
  42.         public static string ProductVersion
  43.         {
  44.             get
  45.             {
  46.                 var attributes = Assembly.GetCallingAssembly()
  47.                                          .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
  48.                 return attributes.Length == 0 ? "" : ((AssemblyInformationalVersionAttribute) attributes[0]).InformationalVersion;
  49.             }
  50.         }
  51.  
  52.         /// <summary>
  53.         /// </summary>
  54.         public static string ProductName
  55.         {
  56.             get
  57.             {
  58.                 var attributes = Assembly.GetCallingAssembly()
  59.                                          .GetCustomAttributes(typeof(AssemblyProductAttribute), false);
  60.                 return attributes.Length == 0 ? "" : ((AssemblyProductAttribute) attributes[0]).Product;
  61.             }
  62.         }
  63.  
  64.         public static string Description
  65.         {
  66.             get
  67.             {
  68.                 var attributes = Assembly.GetCallingAssembly()
  69.                                          .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
  70.                 return attributes.Length == 0 ? "" : ((AssemblyDescriptionAttribute) attributes[0]).Description;
  71.             }
  72.         }
  73.  
  74.         public static string CopyrightHolder
  75.         {
  76.             get
  77.             {
  78.                 var attributes = Assembly.GetCallingAssembly()
  79.                                          .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
  80.                 return attributes.Length == 0 ? "" : ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
  81.             }
  82.         }
  83.  
  84.         public static string CompanyName
  85.         {
  86.             get
  87.             {
  88.                 var attributes = Assembly.GetCallingAssembly()
  89.                                          .GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
  90.                 return attributes.Length == 0 ? "" : ((AssemblyCompanyAttribute) attributes[0]).Company;
  91.             }
  92.         }
  93.  
  94.         public static string LocalIpAddress
  95.         {
  96.             get
  97.             {
  98.                 var localIp = "";
  99.                 var host = Dns.GetHostEntry(Dns.GetHostName());
  100.  
  101.                 foreach (var ip in host.AddressList)
  102.                     if (ip.AddressFamily == AddressFamily.InterNetwork)
  103.                     {
  104.                         localIp = ip.ToString();
  105.                         break;
  106.                     }
  107.  
  108.                 return localIp;
  109.             }
  110.         }
  111.     }
  112. }