From f8cbfb92b6a274267ffe509fa7843a247b0a64da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugen=20H=C3=B6glinger?= Date: Thu, 26 Nov 2020 07:33:18 +0100 Subject: [PATCH] Initialize --- StartStopExtProgram/StartStopExtProgram.cs | 85 ++++-- .../StartStopExtProgram.csproj | 1 + Test_StartStopExtProgram/Form1.Designer.cs | 49 +++- Test_StartStopExtProgram/Form1.cs | 85 ++++-- Test_StartStopExtProgram/Form1.de.resx | 123 +++++++++ Test_StartStopExtProgram/Form1.resx | 253 ++++++++++++------ .../Properties/AssemblyInfo.cs | 2 +- .../Test_StartStopExtProgram.csproj | 3 + 8 files changed, 471 insertions(+), 130 deletions(-) create mode 100644 Test_StartStopExtProgram/Form1.de.resx diff --git a/StartStopExtProgram/StartStopExtProgram.cs b/StartStopExtProgram/StartStopExtProgram.cs index dd9908d..5d65149 100644 --- a/StartStopExtProgram/StartStopExtProgram.cs +++ b/StartStopExtProgram/StartStopExtProgram.cs @@ -11,6 +11,7 @@ using System.Resources; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Forms; namespace Eugen.ESystem { @@ -18,10 +19,11 @@ namespace Eugen.ESystem { #region Version und Copyright // Version und Copyright - string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen - string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + static string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); - string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + static string copyright = GenerateCopyright(); + string icon = Application.StartupPath + "\\Info.bmp"; //Assembly Datum und Zeit static DateTime value = AssemblyDateTime(); string date = value.ToShortDateString(); @@ -33,44 +35,83 @@ namespace Eugen.ESystem //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 DLL-Info /// - /// Contains the name of the dll file. + /// Contains the name of the program file /// - public static string DllName { private set; get; } + public static string DllName { set; get; } /// - /// Contains the version of the dll file. + /// Contains the version of the program file /// - public static string DllVersion { private set; get; } + public static string DllVersion { set; get; } /// - /// Contains the copyright notice. + /// Contains the copyright notice /// - public static string Copyright { private set; get; } + public static string Copyright { set; get; } - /// - /// Contains the name-, version- and copyright-information of the dll file. - /// - public static string[] DllInfo { private set; get; } - - private void SetDllInfo() + private static void SetDllInfo() { //Name, Version und Copyright setzen DllName = dllName; DllVersion = dllVersion; - Copyright = this.copyright; - - string[] dllInfo = new string[3]; - dllInfo[0] = dllName; - dllInfo[1] = dllVersion; - dllInfo[2] = this.copyright; - DllInfo = dllInfo; + Copyright = copyright; } #endregion + /// + /// Starts or stops an external program. + /// + /// A valid program name with path and extension. + static StartStopExtProgram() + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + } + /// /// Starts or stops an external program. /// diff --git a/StartStopExtProgram/StartStopExtProgram.csproj b/StartStopExtProgram/StartStopExtProgram.csproj index 758d239..29717a1 100644 --- a/StartStopExtProgram/StartStopExtProgram.csproj +++ b/StartStopExtProgram/StartStopExtProgram.csproj @@ -33,6 +33,7 @@ + diff --git a/Test_StartStopExtProgram/Form1.Designer.cs b/Test_StartStopExtProgram/Form1.Designer.cs index 5057406..b35c930 100644 --- a/Test_StartStopExtProgram/Form1.Designer.cs +++ b/Test_StartStopExtProgram/Form1.Designer.cs @@ -30,8 +30,13 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.buttonStartStop = new System.Windows.Forms.Button(); - this.labelDllInfo = new System.Windows.Forms.Label(); this.labelStatus = new System.Windows.Forms.Label(); + this.groupBoxProgramInfo = new System.Windows.Forms.GroupBox(); + this.labelProgramInfo = new System.Windows.Forms.Label(); + this.groupBoxDLLInfo = new System.Windows.Forms.GroupBox(); + this.labelDLLInfo = new System.Windows.Forms.Label(); + this.groupBoxProgramInfo.SuspendLayout(); + this.groupBoxDLLInfo.SuspendLayout(); this.SuspendLayout(); // // buttonStartStop @@ -41,24 +46,49 @@ this.buttonStartStop.UseVisualStyleBackColor = true; this.buttonStartStop.Click += new System.EventHandler(this.buttonStartStop_Click); // - // labelDllInfo - // - resources.ApplyResources(this.labelDllInfo, "labelDllInfo"); - this.labelDllInfo.Name = "labelDllInfo"; - // // labelStatus // resources.ApplyResources(this.labelStatus, "labelStatus"); this.labelStatus.Name = "labelStatus"; // + // groupBoxProgramInfo + // + this.groupBoxProgramInfo.Controls.Add(this.labelProgramInfo); + resources.ApplyResources(this.groupBoxProgramInfo, "groupBoxProgramInfo"); + this.groupBoxProgramInfo.Name = "groupBoxProgramInfo"; + this.groupBoxProgramInfo.TabStop = false; + // + // labelProgramInfo + // + resources.ApplyResources(this.labelProgramInfo, "labelProgramInfo"); + this.labelProgramInfo.Name = "labelProgramInfo"; + // + // groupBoxDLLInfo + // + this.groupBoxDLLInfo.Controls.Add(this.labelDLLInfo); + resources.ApplyResources(this.groupBoxDLLInfo, "groupBoxDLLInfo"); + this.groupBoxDLLInfo.Name = "groupBoxDLLInfo"; + this.groupBoxDLLInfo.TabStop = false; + // + // labelDLLInfo + // + resources.ApplyResources(this.labelDLLInfo, "labelDLLInfo"); + this.labelDLLInfo.Name = "labelDLLInfo"; + // // Form1 // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.groupBoxProgramInfo); + this.Controls.Add(this.groupBoxDLLInfo); this.Controls.Add(this.labelStatus); - this.Controls.Add(this.labelDllInfo); this.Controls.Add(this.buttonStartStop); this.Name = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBoxProgramInfo.ResumeLayout(false); + this.groupBoxProgramInfo.PerformLayout(); + this.groupBoxDLLInfo.ResumeLayout(false); + this.groupBoxDLLInfo.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -67,8 +97,11 @@ #endregion private System.Windows.Forms.Button buttonStartStop; - private System.Windows.Forms.Label labelDllInfo; private System.Windows.Forms.Label labelStatus; + private System.Windows.Forms.GroupBox groupBoxProgramInfo; + private System.Windows.Forms.Label labelProgramInfo; + private System.Windows.Forms.GroupBox groupBoxDLLInfo; + private System.Windows.Forms.Label labelDLLInfo; } } diff --git a/Test_StartStopExtProgram/Form1.cs b/Test_StartStopExtProgram/Form1.cs index c497a76..d3e56d7 100644 --- a/Test_StartStopExtProgram/Form1.cs +++ b/Test_StartStopExtProgram/Form1.cs @@ -1,15 +1,8 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; +using Eugen.ESystem; +using System; using System.IO; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using Eugen.ESystem; namespace Test_StartStopExtProgram { @@ -20,7 +13,7 @@ namespace Test_StartStopExtProgram 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 = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + string copyright = GenerateCopyright(); string icon = Application.StartupPath + "\\Info.bmp"; //Assembly Datum und Zeit static DateTime value = AssemblyDateTime(); @@ -33,16 +26,60 @@ namespace Test_StartStopExtProgram //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 = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + //return startYear.Remove(0, startYear.LastIndexOf(" ") + 1); + 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 String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear); + return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear)); + } + } #endregion #region Programm-Info /// - /// Contains the name of the programName file + /// Contains the name of the program file /// public static string ProgramName { set; get; } /// - /// Contains the version of the programName file + /// Contains the version of the program file /// public static string ProgramVersion { set; get; } @@ -66,11 +103,27 @@ namespace Test_StartStopExtProgram InitializeComponent(); } + private void Form1_Load(object sender, EventArgs e) + { + ShowInformation(); //Programm- und DLL-Information anzeigen + } + + private void ShowInformation() + { + labelProgramInfo.Text = String.Concat(ProgramName, "\n", ProgramVersion, "\n", Copyright); //Programm-Information anzeigen + + // DLL-Information anzeigen + labelDLLInfo.Text = String.Concat(StartStopExtProgram.DllName, "\n", StartStopExtProgram.DllVersion, "\n", StartStopExtProgram.Copyright); + } + private void buttonStartStop_Click(object sender, EventArgs e) { + //-------------------------------------------------------------- + //--- Diesen Bereich ins eigene Programm einfügen --- Anfang --- + //-------------------------------------------------------------- string programPath = @"C:\Windows"; //Programmpfad string programName = "Notepad.exe"; //Programm Name - string arg = @"H:\Programmieren\Visual Studio 2017\Projekte\_DLL\StartStopExtProgram\Daten\Test.txt"; //Argument das übergeben wird + string arg = @"H:\Programmieren\Git-Repository\VisualStudio\2017\_DLL\StartStopExtProgram.git\Daten\Test.txt"; //Argument das übergeben wird bool winStyleMinimized = false; //Anzeige des Programmfensters. false=Sichtbar, true=Minimiert //Nachfolgend die möglichen Aufrufvarianten @@ -85,9 +138,9 @@ namespace Test_StartStopExtProgram { MessageBox.Show(ex.Message); } - - //Ausgabe der DLL Informationen - labelDllInfo.Text = String.Concat(StartStopExtProgram.DllName, "\r\n", StartStopExtProgram.DllVersion, "\r\n", StartStopExtProgram.Copyright); + //-------------------------------------------------------------- + //--- Diesen Bereich ins eigene Programm einfügen --- Ende --- + //-------------------------------------------------------------- } } } diff --git a/Test_StartStopExtProgram/Form1.de.resx b/Test_StartStopExtProgram/Form1.de.resx new file mode 100644 index 0000000..a5374ac --- /dev/null +++ b/Test_StartStopExtProgram/Form1.de.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Start / Stop drücken um das Programm zu starten oder zu Beenden. + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Form1.resx b/Test_StartStopExtProgram/Form1.resx index b6c680d..f3a6680 100644 --- a/Test_StartStopExtProgram/Form1.resx +++ b/Test_StartStopExtProgram/Form1.resx @@ -117,106 +117,193 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - 6, 13 - Bottom - - - 1 - - - 13, 13 - - - labelStatus - - - 16, 13 - - - $this - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Form1 - - - $this - - - True - - - 350, 155 - - - 0 - - - 327, 13 - - - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 13, 88 - - - 1 + + + 12, 215 - 109, 23 - - - Start / Stop drücken um das Programm zu starten oder zu Beenden. + 776, 23 + 0 Start / Stop - - - 2 - - - 121, 120 - - - labelDllInfo - - - True - - - ... - - - Form1 - - - 2 + @Invariant buttonStartStop + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + True + + + 13, 187 + + + 327, 13 + + + 2 + + + Start / Stop drücken um das Programm zu starten oder zu Beenden. + + + labelStatus + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + NoControl + + + 7, 20 + + + 16, 13 + + + 0 + + + ... + @Invariant + + + labelProgramInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBoxProgramInfo + + + 0 + + + 12, 372 + + + 385, 66 + + + 9 + + + Programm Information + @Invariant + + + groupBoxProgramInfo + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + NoControl + + + 7, 20 + + + 16, 13 + + + 0 + + + ... + @Invariant + + + labelDLLInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBoxDLLInfo + + + 0 + + + 403, 372 + + + 385, 66 + + + 10 + + + DLL Information + @Invariant + + + groupBoxDLLInfo + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + True + + 6, 13 + + + 800, 450 + + + Form1 + @Invariant + + + Form1 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Properties/AssemblyInfo.cs b/Test_StartStopExtProgram/Properties/AssemblyInfo.cs index 69cb15b..aefdc54 100644 --- a/Test_StartStopExtProgram/Properties/AssemblyInfo.cs +++ b/Test_StartStopExtProgram/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Test_StartStopExtProgram")] -[assembly: AssemblyCopyright("Copyright © 2019 ")] +[assembly: AssemblyCopyright("Copyright © 2019 by Eugen Höglinger")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj b/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj index ba5292c..1e60e69 100644 --- a/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj +++ b/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj @@ -54,6 +54,9 @@ + + Form1.cs + Form1.cs