ChangeCopyrightInfo tool
This commit is contained in:
parent
4efda60872
commit
fe517c0569
6 changed files with 475 additions and 0 deletions
116
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs
Normal file
116
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs
Normal file
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
|
||||
namespace ChangeCopyrightInfo
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static string Path
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["path"]; }
|
||||
}
|
||||
|
||||
static string Files
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["files"]; }
|
||||
}
|
||||
|
||||
static List<string> copyrigth = null;
|
||||
static List<string> Copyrigth
|
||||
{
|
||||
get {
|
||||
if (copyrigth != null) return copyrigth;
|
||||
copyrigth = new List<string>();
|
||||
string text = ConfigurationManager.AppSettings["copyrigth"];
|
||||
if (text == null) return copyrigth;
|
||||
copyrigth.AddRange( text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) );
|
||||
return copyrigth;
|
||||
}
|
||||
}
|
||||
static string startcopyrigth
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["startcopyrigth"]; }
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Log.Initialize(ConfigurationManager.AppSettings["LogFile"]);
|
||||
Log.WriteApplicationStart();
|
||||
|
||||
if (Path != null)
|
||||
CheckDirectory(Path);
|
||||
|
||||
Log.WriteApplicationEnd();
|
||||
}
|
||||
|
||||
static void CheckDirectory(string directory)
|
||||
{
|
||||
Log.WriteLine("Check " + directory);
|
||||
|
||||
string[] dirFiles = Directory.GetFiles(directory, Files);
|
||||
|
||||
foreach (string file in dirFiles)
|
||||
CheckFile(file);
|
||||
|
||||
string[] dirDirs = Directory.GetDirectories(directory);
|
||||
|
||||
foreach(string dir in dirDirs)
|
||||
CheckDirectory(dir);
|
||||
}
|
||||
|
||||
static void CheckFile(string file)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
lines.AddRange(File.ReadAllLines(file));
|
||||
|
||||
bool copyrigthExist = false;
|
||||
if (Copyrigth.Count <= lines.Count)
|
||||
{
|
||||
for (int i = 0; i < Copyrigth.Count; i++)
|
||||
if (Copyrigth[i].Trim().ToLower() != lines[i].Trim().ToLower())
|
||||
break;
|
||||
|
||||
copyrigthExist = true;
|
||||
}
|
||||
|
||||
if (copyrigthExist)
|
||||
return;
|
||||
|
||||
Log.WriteLine("Change copyrigth : " + file);
|
||||
|
||||
// skip copyrigth
|
||||
int skip = 0;
|
||||
if (lines.Count>0)
|
||||
{
|
||||
if (lines[0].StartsWith(startcopyrigth, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
for (int i = 1; i < lines.Count; i++)
|
||||
{
|
||||
if (!lines[i].StartsWith("//"))
|
||||
break;
|
||||
skip = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// skip WhiteSpace
|
||||
for (int i = skip+1; i < lines.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(lines[i]))
|
||||
break;
|
||||
skip = i;
|
||||
}
|
||||
|
||||
lines.RemoveRange(0, skip);
|
||||
|
||||
File.WriteAllLines(file, Copyrigth);
|
||||
File.AppendAllText(file, Environment.NewLine);
|
||||
File.AppendAllLines(file, lines);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue