From 36c50d51d2561644bbdd13c0d3de2d7e6f137cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugen=20H=C3=B6glinger?= Date: Thu, 26 Nov 2020 12:04:08 +0100 Subject: [PATCH] Initialize --- OwnMessageBox/OwnMessageBox.cs | 46 ++++++++++++++++++- OwnMessageBox/Properties/AssemblyInfo.cs | 2 +- .../Test_OwnMessageBox/Form1.cs | 46 ++++++++++++++++++- .../Properties/AssemblyInfo.cs | 2 +- 4 files changed, 92 insertions(+), 4 deletions(-) diff --git a/OwnMessageBox/OwnMessageBox.cs b/OwnMessageBox/OwnMessageBox.cs index e41a678..e501a40 100644 --- a/OwnMessageBox/OwnMessageBox.cs +++ b/OwnMessageBox/OwnMessageBox.cs @@ -19,7 +19,7 @@ namespace EOwnMessageBox 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(); @@ -32,6 +32,50 @@ namespace EOwnMessageBox //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 diff --git a/OwnMessageBox/Properties/AssemblyInfo.cs b/OwnMessageBox/Properties/AssemblyInfo.cs index 8e6a712..a66b16a 100644 --- a/OwnMessageBox/Properties/AssemblyInfo.cs +++ b/OwnMessageBox/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OwnMessageBox")] -[assembly: AssemblyCopyright("Copyright © 2018 ")] +[assembly: AssemblyCopyright("Copyright © 2018 by Eugen Höglinger")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Test_OwnMessageBox/Test_OwnMessageBox/Form1.cs b/Test_OwnMessageBox/Test_OwnMessageBox/Form1.cs index 778d8c9..756ea64 100644 --- a/Test_OwnMessageBox/Test_OwnMessageBox/Form1.cs +++ b/Test_OwnMessageBox/Test_OwnMessageBox/Form1.cs @@ -20,7 +20,7 @@ namespace Test_OwnMessageBox 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,6 +33,50 @@ namespace Test_OwnMessageBox //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 diff --git a/Test_OwnMessageBox/Test_OwnMessageBox/Properties/AssemblyInfo.cs b/Test_OwnMessageBox/Test_OwnMessageBox/Properties/AssemblyInfo.cs index e8d263d..3502694 100644 --- a/Test_OwnMessageBox/Test_OwnMessageBox/Properties/AssemblyInfo.cs +++ b/Test_OwnMessageBox/Test_OwnMessageBox/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Test_OwnMessageBox")] -[assembly: AssemblyCopyright("Copyright © 2018 ")] +[assembly: AssemblyCopyright("Copyright © 2018 by Eugen Höglinger")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]