Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Program.cs 1.72 KiB
Newer Older
* Copyright 2015, 2016 Graz University of Technology,
* Institute of Internal Combustion Engines and Thermodynamics,
* Institute of Technical Informatics
*
* Licensed under the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software 
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and 
* limitations under the Licence.
*/

using System;
using System.Text;
using System.Text.RegularExpressions;

namespace LicenceHeader
{
	/// <summary>
	/// Updates/Adds the EUPL license header to every .cs file in the solution directory
	/// </summary>
	internal class Program
	{
		private const string SolutionRootDirectory = @"..\\..\\..";

		private static void Main()
		{
			var licence = File.ReadAllText("header.txt");
			foreach (var file in Directory.GetFiles(SolutionRootDirectory, "*.cs", SearchOption.AllDirectories)) {
				Console.WriteLine(file);
				if (file.Contains("\\obj\\") || file.Contains("\\bin\\")) {
					continue;
				}
				var re = new Regex("^.*?(?=using|namespace)", RegexOptions.Singleline);
				var content = File.ReadAllText(file, Encoding.Default);
				var updatedContent = re.Replace(content, licence);
				if (updatedContent != content) {
					File.WriteAllText(file, updatedContent, Encoding.Default);
					Console.WriteLine("Updated " + file);
					count++;
			Console.WriteLine("Finished. Updated {0} files.", count);
			Console.ReadKey();