- Tool mit dem der Copyright Vermerk in allen Assemblies im ausgewählten Ordner auf das aktuelle Jahr korrigiert wird
108 lines
3.0 KiB
C#
108 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Eugen.ESystem.IO;
|
|
|
|
namespace CorrectDateInCopyright
|
|
{
|
|
static class CorrectDateInLine
|
|
{
|
|
//public CorrectDateInLine()
|
|
//{
|
|
//}
|
|
|
|
static CorrectDateInLine()
|
|
{
|
|
}
|
|
|
|
public static string LogFile { set; get; }
|
|
|
|
/// <summary>
|
|
/// Corrects the specified file
|
|
/// </summary>
|
|
/// <param name="fullFileName">A valid filename with path and extension.</param>
|
|
public static void Correct(string fullFileName)
|
|
{
|
|
List<string> lines = new List<string>();
|
|
|
|
lines = ReadFileLineByLine.Read(fullFileName);
|
|
|
|
for (int i = 0; i < lines.Count; i++)
|
|
{
|
|
if (lines[i].Contains("AssemblyCopyright"))
|
|
{
|
|
lines[i] = SwapDate(lines[i]);
|
|
}
|
|
}
|
|
|
|
WriteFile(fullFileName, lines);
|
|
}
|
|
|
|
private static string SwapDate(string line)
|
|
{
|
|
var log = new LogWriter(String.Concat(Path.GetDirectoryName(LogFile), "\\"), Path.GetFileName(LogFile));
|
|
log.WriteMessage(String.Concat(" Alter Wert: ", line));
|
|
|
|
string startPart = "[assembly: AssemblyCopyright(\"Copyright © ";
|
|
string endPart = " by Eugen Höglinger\")]";
|
|
string startDate = ExtractStartDate(line);
|
|
|
|
string currentDate = DateTime.Now.ToString("yyyy");
|
|
|
|
//Neu zusammenstellen
|
|
if (startDate == currentDate)
|
|
{
|
|
line = String.Concat(startPart, startDate, endPart);
|
|
}
|
|
else
|
|
{
|
|
line = String.Concat(startPart, startDate, "-", currentDate, endPart);
|
|
}
|
|
|
|
log.WriteMessage(String.Concat(" Neuer Wert: ", line));
|
|
|
|
return line;
|
|
}
|
|
|
|
private static string ExtractStartDate(string text)
|
|
{
|
|
char[] delimiterChars = { ' ', '-' }; //Trennzeichen
|
|
string[] words = text.Split(delimiterChars);
|
|
int year = 0;
|
|
|
|
foreach (var word in words)
|
|
{
|
|
//Prüfen ob der Wert eine Zahl ist
|
|
if (int.TryParse(word, out year))
|
|
{
|
|
break; //Sobald eine Zahl gefunden wurde, dann aufhören
|
|
}
|
|
}
|
|
|
|
return year.ToString();
|
|
}
|
|
|
|
private static void WriteFile(string fullFileName, List<string> lines)
|
|
{
|
|
//Datei umbenennen
|
|
File.Move(fullFileName, String.Concat(fullFileName, "_old"));
|
|
|
|
//Datei schreiben
|
|
StreamWriter writer;
|
|
writer = new StreamWriter(fullFileName, true, Encoding.Default);
|
|
foreach (var item in lines)
|
|
{
|
|
writer.WriteLine(item);
|
|
}
|
|
|
|
writer.Close();
|
|
|
|
//Umbenannte Datei löschen
|
|
File.Delete(String.Concat(fullFileName, "_old"));
|
|
}
|
|
}
|
|
}
|