- Programmicon dazu - Ordner 'Netz' neu dazu - Script zum Erzeugen einer komprimierten EXE im Ordner 'Netz' neu dazu - Komprimierte EXE neu erzeugt
231 lines
7.7 KiB
C#
231 lines
7.7 KiB
C#
using Eugen.ESystem.IO;
|
|
using Eugen.ESystem.Windows.Forms;
|
|
using Eugen.NX;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ShowInstalledNXversion
|
|
{
|
|
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)
|
|
{
|
|
InstalledVersions();
|
|
}
|
|
|
|
private void textBoxInstallationFolder_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (String.IsNullOrEmpty(textBoxInstallationFolder.Text))
|
|
{
|
|
textBoxInstalledNxVersion.Text = "";
|
|
}
|
|
}
|
|
|
|
private void textBoxInstallationFolder_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (textBoxInstallationFolder.Text.EndsWith("\\"))
|
|
{
|
|
textBoxInstallationFolder.Text = textBoxInstallationFolder.Text.TrimEnd('\\');
|
|
}
|
|
InstallationFolder = textBoxInstallationFolder.Text;
|
|
|
|
InstalledVersions();
|
|
}
|
|
}
|
|
|
|
private void buttonInstallationFolder_Click(object sender, EventArgs e)
|
|
{
|
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
textBoxInstallationFolder.Text = folderBrowserDialog.SelectedPath;
|
|
|
|
InstalledVersions();
|
|
}
|
|
}
|
|
|
|
private void comboBoxInstalledNX_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Version = comboBoxInstalledNX.SelectedItem.ToString();
|
|
|
|
ShowVersion();
|
|
}
|
|
|
|
private void buttonExportVersion_Click(object sender, EventArgs e)
|
|
{
|
|
WriteListToDesktop.Write(InstallationFolder, InstalledNxVersions);
|
|
}
|
|
|
|
private void buttonAbout_Click(object sender, EventArgs e)
|
|
{
|
|
//Zeigt das 'AboutBox' Fenster an
|
|
var about = new AboutBox(ProgramName, ProgramVersion, Copyright, true, 550, 400);
|
|
about.ShowDialog();
|
|
}
|
|
|
|
protected string InstallationFolder { private set; get; }
|
|
protected List<string> InstalledNxVersions { private set; get; }
|
|
protected string Version { private set; get; }
|
|
|
|
private void InstalledVersions()
|
|
{
|
|
if (Directory.Exists(textBoxInstallationFolder.Text))
|
|
{
|
|
InstallationFolder = textBoxInstallationFolder.Text;
|
|
InstalledNxVersions = NxVersions(textBoxInstallationFolder.Text);
|
|
|
|
foreach (var item in InstalledNxVersions)
|
|
{
|
|
comboBoxInstalledNX.Items.Add(item);
|
|
}
|
|
comboBoxInstalledNX.SelectedIndex = 0;
|
|
comboBoxInstalledNX.Refresh();
|
|
Version = comboBoxInstalledNX.SelectedItem.ToString();
|
|
|
|
ShowVersion();
|
|
}
|
|
else
|
|
{
|
|
textBoxInstallationFolder.Text = "";
|
|
InstallationFolder = textBoxInstallationFolder.Text;
|
|
textBoxInstalledNxVersion.Text = "";
|
|
}
|
|
}
|
|
|
|
private List<string> NxVersions(string folder)
|
|
{
|
|
List<string> version = new List<string>();
|
|
|
|
if (Directory.Exists(folder))
|
|
{
|
|
|
|
string pattern = "NX";
|
|
|
|
var versionPath = new ReadFoldersFromFolder(folder, pattern, true, false);
|
|
foreach (var item in versionPath.FoldersFound)
|
|
{
|
|
version.Add(item.Remove(0, item.LastIndexOf("\\") + 1).Replace(pattern, ""));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new DirectoryNotFoundException(folder);
|
|
}
|
|
|
|
return version;
|
|
}
|
|
|
|
private void ShowVersion()
|
|
{
|
|
NxVersion nxVer = new NxVersion(String.Concat(InstallationFolder, "\\NX", Version)); //Informationen über diese Version abrufen
|
|
|
|
if (Convert.ToInt32(Version) <= 12)
|
|
{
|
|
textBoxInstalledNxVersion.Text = nxVer.NXpatch;
|
|
}
|
|
else
|
|
{
|
|
textBoxInstalledNxVersion.Text = String.Concat(nxVer.UgiiMajorVersion, ".", nxVer.UgiiMinorVersion);
|
|
}
|
|
|
|
}
|
|
|
|
//TODO: Basisversion auch im Programmfenster anzeigen
|
|
}
|
|
}
|