162 lines
5.7 KiB
C#
162 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Test_ShowUsedDll
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
#region Version und Copyright
|
|
// Version und Copyright
|
|
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
string copyright = GenerateCopyright();
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//Assembly Datum und Zeit
|
|
static DateTime value = AssemblyDateTime();
|
|
string date = value.ToShortDateString();
|
|
string time = value.ToLongTimeString();
|
|
private static DateTime AssemblyDateTime()
|
|
{
|
|
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
|
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
|
return buildDateTime;
|
|
}
|
|
|
|
private static string CurrentYear()
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
|
|
private static string StartYear()
|
|
{
|
|
string startYear = "";
|
|
if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © "))
|
|
{
|
|
startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", "");
|
|
while (startYear.StartsWith(" "))
|
|
{
|
|
startYear = startYear.Remove(0, 1);
|
|
}
|
|
startYear = startYear.Remove(startYear.IndexOf(" "));
|
|
return startYear;
|
|
}
|
|
else
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
}
|
|
|
|
private static string GenerateCopyright()
|
|
{
|
|
string startYear = StartYear();
|
|
string currentYear = CurrentYear();
|
|
|
|
if (startYear == currentYear)
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
}
|
|
else
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Programm-Info
|
|
/// <summary>
|
|
/// Contains the name of the program file
|
|
/// </summary>
|
|
public static string ProgramName { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the program file
|
|
/// </summary>
|
|
public static string ProgramVersion { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice
|
|
/// </summary>
|
|
public static string Copyright { set; get; }
|
|
|
|
private void SetProgramInfo()
|
|
{
|
|
//Name, Version und Copyright setzen
|
|
ProgramName = programName;
|
|
ProgramVersion = programVersion;
|
|
Copyright = copyright;
|
|
}
|
|
#endregion
|
|
public Form1()
|
|
{
|
|
SetProgramInfo();
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
string dlls = "";
|
|
|
|
foreach (var item in ShowUsedDll())
|
|
{
|
|
dlls += item + Environment.NewLine + Environment.NewLine;
|
|
}
|
|
|
|
textBoxDllInfo.Text = dlls.Remove(dlls.LastIndexOf("\r\n\r\n"));
|
|
}
|
|
|
|
private List<string> ShowUsedDll()
|
|
{
|
|
List<string> dlls = new List<string>();
|
|
string name = "";
|
|
string dllInfos = "";
|
|
string dllName = "";
|
|
string dllVersion = "";
|
|
|
|
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
|
|
{
|
|
dlls.Add(module.ModuleName + Environment.NewLine + module.FileVersionInfo.ProductVersion + Environment.NewLine + module.FileName);
|
|
}
|
|
|
|
DirectoryInfo ParentDirectory = new DirectoryInfo(Application.StartupPath);
|
|
foreach (FileInfo fi in ParentDirectory.GetFiles())
|
|
{
|
|
if (fi.Extension.ToLower() == ".dll")
|
|
{
|
|
name = fi.FullName.Remove(0, fi.FullName.LastIndexOf("\\") + 1);
|
|
|
|
Assembly assembly = Assembly.LoadFrom(name);
|
|
|
|
dllName = String.Concat(assembly.ToString().Remove(assembly.ToString().IndexOf(",")), ".dll");
|
|
dllVersion = assembly.ToString().Remove(0, assembly.ToString().IndexOf("Version=") + 8);
|
|
dllVersion = dllVersion.Remove(dllVersion.IndexOf(","));
|
|
|
|
dllInfos = String.Concat(dllInfos, dllName, "\r\n", dllVersion, "\r\n\r\n");
|
|
|
|
dlls.Add(fi.FullName.Remove(0, fi.FullName.LastIndexOf("\\") + 1) + Environment.NewLine + dllVersion + Environment.NewLine + ParentDirectory + Environment.NewLine + dllName);
|
|
}
|
|
}
|
|
|
|
dlls.Sort();
|
|
|
|
return dlls;
|
|
}
|
|
|
|
|
|
}
|
|
}
|