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 |
{ |
35 |
Console.WriteLine("########## found ########## Minor ###########"); |
36 |
Console.WriteLine("{0} (transformed to) ",line); |
37 |
string line2 = line.Replace("private const string Minor = ", "").Trim().Replace(";", ""); |
38 |
//Console.WriteLine(line2); |
39 |
|
40 |
string[] shifts = line2.Split('|'); |
41 |
List<int> shift_ors = new List<int>(); |
42 |
int final_value = 0; |
43 |
foreach (string shift in shifts) |
44 |
{ |
45 |
int shift_value = 0; |
46 |
string t_shift = shift.Trim(); |
47 |
//Console.Write("shift: {0} = ", t_shift); |
48 |
|
49 |
if (t_shift.Contains("<<")) |
50 |
{ |
51 |
string[] shift_registers = t_shift.Split(new string[] { "<<" }, StringSplitOptions.RemoveEmptyEntries); |
52 |
//foreach (string shift_register in shift_registers) |
53 |
//{ |
54 |
// string t_shift_reg = shift_register.Trim(); |
55 |
// Console.WriteLine(" shift reg: {0}", t_shift_reg); |
56 |
//} |
57 |
int shift_t1 = Convert.ToInt32(shift_registers[0].Trim()); |
58 |
int shift_t2 = Convert.ToInt32(shift_registers[1].Trim()); |
59 |
shift_value = shift_t1 << shift_t2; |
60 |
} |
61 |
else |
62 |
{ |
63 |
shift_value = Convert.ToInt32(t_shift); |
64 |
} |
65 |
//Console.Write(shift_value); |
66 |
//Console.WriteLine(); |
67 |
shift_ors.Add(shift_value); |
68 |
} |
69 |
|
70 |
foreach (int shift_or in shift_ors) |
71 |
{ |
72 |
final_value = final_value | shift_or; |
73 |
} |
74 |
//Console.Write("{0} = ",line2); |
75 |
//Console.Write(final_value); |
76 |
//Console.WriteLine(); |
77 |
string replace = string.Format("\"{0}\"", final_value.ToString()); |
78 |
Console.WriteLine("{0}", line.Replace(line2,replace)); |
79 |
line = line.Replace(line2, replace); |
80 |
} |
81 |
builder.Add(line); |
82 |
} |
83 |
sr.Close(); |
84 |
} |
85 |
#endregion |
86 |
|
87 |
using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read)) |
88 |
{ |
89 |
StreamWriter sw = new StreamWriter(fs); |
90 |
sw.AutoFlush = true; |
91 |
foreach (string t in builder) |
92 |
{ |
93 |
sw.WriteLine(t); |
94 |
} |
95 |
sw.Close(); |
96 |
} |
97 |
} |
98 |
} |
99 |
} |