129 lines
3.9 KiB
C#
129 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AdjustBuildRevision
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
// args[0] - FileName
|
|
try
|
|
{
|
|
FileInfo fi = new FileInfo(args[0]);
|
|
DateTime dtLatest = GetLatestDateTime(fi.Directory.Parent,fi.LastWriteTime);
|
|
if (fi.Exists)
|
|
{
|
|
StreamReader sr = fi.OpenText();
|
|
string content = sr.ReadToEnd();
|
|
sr.Close();
|
|
string[] seps = { "\r\n" };
|
|
string[] lines = content.Split(seps, StringSplitOptions.None);
|
|
bool changed = false;
|
|
for (int i = 0; i < lines.Length;i++ )
|
|
{
|
|
string line = lines[i];
|
|
string outline = line;
|
|
if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion"))
|
|
{
|
|
// Allow for setting build revision on either proms or the roeditor:
|
|
if (Directory.GetCurrentDirectory().ToUpper().Contains("REFOBJ"))
|
|
outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("2.3.yyMM.dHH") + "\")");
|
|
else
|
|
outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("2.2.yyMM.dHH") + "\")");
|
|
// if (outline != line)
|
|
// {
|
|
// Console.WriteLine("Before: '{0}'", line);
|
|
// Console.WriteLine("After: '{0}'", outline);
|
|
// lines[i] = outline;
|
|
// changed = true;
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("No change: '{0}'", line);
|
|
// }
|
|
// }
|
|
//}
|
|
//if (changed)
|
|
//{
|
|
// if (!fi.IsReadOnly) fi.IsReadOnly = false;
|
|
// StreamWriter sw = fi.CreateText();
|
|
// foreach (string line in lines)
|
|
// sw.WriteLine(line);
|
|
// sw.Close();
|
|
// string line = lines[i];
|
|
// string outline = line;
|
|
// if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion"))
|
|
// {
|
|
//outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("1.1.yyMM.dHH") + "\")");
|
|
if (outline != line)
|
|
{
|
|
Console.WriteLine("Before: '{0}'", line);
|
|
Console.WriteLine("After: '{0}'", outline);
|
|
lines[i] = outline;
|
|
changed = true;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("No change: '{0}'", line);
|
|
}
|
|
}
|
|
}
|
|
if (changed)
|
|
{
|
|
if (!fi.IsReadOnly) fi.IsReadOnly = false;
|
|
StreamWriter sw = fi.CreateText();
|
|
foreach (string line in lines)
|
|
sw.WriteLine(line);
|
|
sw.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("File " + fi.FullName + " does not exist");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
//private static DateTime GetLatestDateTime(string path)
|
|
//{
|
|
// return GetLatestDateTime(new DirectoryInfo(path));
|
|
//}
|
|
private static DateTime GetLatestDateTime(DirectoryInfo di, DateTime dtCheck)
|
|
{
|
|
DateTime dtMax = dtCheck;
|
|
FileInfo[] myFiles = di.GetFiles();
|
|
foreach(FileInfo myFile in myFiles)
|
|
{
|
|
DateTime dt = myFile.LastWriteTime;
|
|
//if (dt > dtCheck)
|
|
//{
|
|
//Console.WriteLine("\"File\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}",myFile.FullName,dt.ToString("1.1.yyMM.dHH"),dt,dtCheck);
|
|
if(dtMax < dt) dtMax = dt;
|
|
//}
|
|
}
|
|
DirectoryInfo[] myFolders = di.GetDirectories();
|
|
foreach (DirectoryInfo diChild in myFolders)
|
|
{
|
|
DateTime dtChild = GetLatestDateTime(diChild,dtCheck);
|
|
//if (dtChild > dtCheck)
|
|
//{
|
|
//Console.WriteLine("\"SubFolder\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}", diChild.FullName, dtChild.ToString("1.1.yyMM.dHH"),dtChild,dtCheck);
|
|
if(dtChild > dtMax) dtMax = dtChild;
|
|
//}
|
|
}
|
|
//if(dtMax > dtCheck)
|
|
// Console.WriteLine("\"Folder\"\t\"{0}\"\t\"{1}\"", di.FullName, dtMax.ToString("1.1.yyMM.dHH"));
|
|
return dtMax;
|
|
}
|
|
}
|
|
}
|