Datei: Tools/MakeEnhancerDate/Class1.cs

Last Commit (522a947)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Text.RegularExpressions;
25 using System.IO;
26 using System.Globalization;
27 using System.Threading;
28
29 namespace MakeEnhancerDate
30 {
31 ····/// <summary>
32 ····/// Zusammenfassung für Class1.
33 ····/// </summary>
34 ····class Class1
35 ····{
36 ········/// <summary>
37 ········/// Der Haupteinstiegspunkt für die Anwendung.
38 ········/// </summary>
39 ········[STAThread]
40 ········static void Main(string[] args)
41 ········{
42 ············ConsoleProcess cp = new ConsoleProcess(false);
43 ············string ndoRootPath = AppDomain.CurrentDomain.BaseDirectory;
44 ············string gitDir;
45
46 ············do
47 ············{
48 ················ndoRootPath = Path.GetFullPath( Path.Combine( ndoRootPath, ".." ) );
49 ················gitDir = Path.Combine( ndoRootPath, ".git" );
50 ············} while (!Directory.Exists( gitDir ));
51
52 ············string? head = null;
53 ············char[] buf = new char[7];
54 ············using (StreamReader sr = new StreamReader( Path.Combine( gitDir, "HEAD" ) ))
55 ············{
56 ················sr.Read( buf, 0, 5 );
57 ················head = sr.ReadToEnd().Trim();
58 ············}
59
60 var refHeadPath = Path. Combine( gitDir, head!. Replace( "/", "\\" ) ) ;
 
 
 
61 ············if (!File.Exists( refHeadPath ))
62 ················throw new Exception( "Ref head doesn't exist: " + refHeadPath );
63
64 ············using (StreamReader sr = new StreamReader( refHeadPath ))
65 ············{
66 ················sr.Read( buf, 0, 7 );··// first 7 chars of the head················
67 ············}
68
69 ············string rev = "r. " + new string( buf );
70 ············Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
71 ············Console.Write(@"namespace NDOEnhancer
72 {
73 ····public class EnhDate
74 ····{
75 ········public const string String = ""{0} " + DateTime.Now.ToShortDateString() + " (V. {1} " + rev + @")"";
76 ····}
77 }
78 ");
79 ········}
80 ····}
81 }
82
New Commit (4a388b2)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Text.RegularExpressions;
25 using System.IO;
26 using System.Globalization;
27 using System.Threading;
28
29 namespace MakeEnhancerDate
30 {
31 ····/// <summary>
32 ····/// Zusammenfassung für Class1.
33 ····/// </summary>
34 ····class Class1
35 ····{
36 ········/// <summary>
37 ········/// Der Haupteinstiegspunkt für die Anwendung.
38 ········/// </summary>
39 ········[STAThread]
40 ········static void Main(string[] args)
41 ········{
42 ············ConsoleProcess cp = new ConsoleProcess(false);
43 ············string ndoRootPath = AppDomain.CurrentDomain.BaseDirectory;
44 ············string gitDir;
45
46 ············do
47 ············{
48 ················ndoRootPath = Path.GetFullPath( Path.Combine( ndoRootPath, ".." ) );
49 ················gitDir = Path.Combine( ndoRootPath, ".git" );
50 ············} while (!Directory.Exists( gitDir ));
51
52 ············string? head = null;
53 ············char[] buf = new char[7];
54 ············using (StreamReader sr = new StreamReader( Path.Combine( gitDir, "HEAD" ) ))
55 ············{
56 ················sr.Read( buf, 0, 5 );
57 ················head = sr.ReadToEnd().Trim();
58 ············}
59
60 var refHeadPath = Path. Combine( gitDir, head ) ;
61 ············if (Path.DirectorySeparatorChar == '\\')
62 ················refHeadPath = refHeadPath.Replace( "/", "\\" );
63
64 ············if (!File.Exists( refHeadPath ))
65 ················throw new Exception( "Ref head doesn't exist: " + refHeadPath );
66
67 ············using (StreamReader sr = new StreamReader( refHeadPath ))
68 ············{
69 ················sr.Read( buf, 0, 7 );··// first 7 chars of the head················
70 ············}
71
72 ············string rev = "r. " + new string( buf );
73 ············Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
74 ············Console.Write(@"namespace NDOEnhancer
75 {
76 ····public class EnhDate
77 ····{
78 ········public const string String = ""{0} " + DateTime.Now.ToShortDateString() + " (V. {1} " + rev + @")"";
79 ····}
80 }
81 ");
82 ········}
83 ····}
84 }
85