/[AnywhereTS-MSSQL]/trunk/SvnVersionHelper/Program.cs
ViewVC logotype

Contents of /trunk/SvnVersionHelper/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 221 - (show annotations) (download)
Thu Aug 23 17:20:28 2012 UTC (7 years, 6 months ago) by william
File size: 4545 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6
7 namespace SvnVersionHelper
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 if (args.Count() == 0 || args.Count() > 1) {
14 Console.WriteLine("SvnVersionHelper: invalid arguments (must be path to file)");
15 return;
16 }
17 string file = args[0];
18 readfile(file);
19 }
20
21 static void readfile(string file)
22 {
23 Console.WriteLine("SvnVersionHelper: reading {0}", file);
24
25 List<string> builder = new List<string>();
26 #region file reader
27 using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
28 {
29 StreamReader sr = new StreamReader(fs);
30 while (!sr.EndOfStream)
31 {
32 string line = sr.ReadLine();
33 if (line.ToLower().Contains("private const string Minor = ".ToLower()) ||
34 line.ToLower().Contains("Private Const Minor As String = ".ToLower()))
35 {
36 Console.WriteLine("########## found ########## Minor ###########");
37 Console.WriteLine("{0} (transformed to) ",line);
38 string line2 = line.Replace("private const string Minor = ", "").Trim().Replace(";", "");
39 line2 = line2.Replace("Private Const Minor As String = ", "").Trim();
40 //Console.WriteLine(line2);
41
42 string[] shifts = line2.Split(new string[]{"|","Or"}, StringSplitOptions.RemoveEmptyEntries);
43 List<int> shift_ors = new List<int>();
44 int final_value = 0;
45 foreach (string shift in shifts)
46 {
47 int shift_value = 0;
48 string t_shift = shift.Trim().Replace("\"","");
49 //Console.Write("001 shift: {0} = ", t_shift);
50
51 if (t_shift.Contains("<<") || t_shift.Contains("Or"))
52 {
53 string[] shift_registers = t_shift.Split(new string[] { "<<", "Or" }, StringSplitOptions.RemoveEmptyEntries);
54 //foreach (string shift_register in shift_registers)
55 //{
56 // string t_shift_reg = shift_register.Trim();
57 // Console.WriteLine(" shift reg: {0}", t_shift_reg);
58 //}
59 int shift_t1 = Convert.ToInt32(shift_registers[0].Trim());
60 int shift_t2 = Convert.ToInt32(shift_registers[1].Trim());
61 shift_value = shift_t1 << shift_t2;
62 }
63 else
64 {
65 shift_value = Convert.ToInt32(t_shift);
66 }
67 //Console.Write(shift_value);
68 //Console.WriteLine();
69 shift_ors.Add(shift_value);
70 }
71
72 foreach (int shift_or in shift_ors)
73 {
74 final_value = final_value | shift_or;
75 }
76 //Console.Write("{0} = ", line2);
77 //Console.Write(final_value);
78 //Console.WriteLine();
79 string replace = string.Format("\"{0}\"", final_value.ToString());
80 Console.WriteLine("{0}", line.Replace(line2,replace));
81 line = line.Replace(line2, replace);
82 }
83 builder.Add(line);
84 }
85 sr.Close();
86 }
87 #endregion
88
89 using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read))
90 {
91 StreamWriter sw = new StreamWriter(fs);
92 sw.AutoFlush = true;
93 foreach (string t in builder)
94 {
95 sw.WriteLine(t);
96 }
97 sw.Close();
98 }
99 }
100 }
101 }

  ViewVC Help
Powered by ViewVC 1.1.22