-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
83 lines (71 loc) · 1.93 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using IniParser;
using IniParser.Model;
using System;
using System.Collections.Generic;
using System.IO;
namespace Merger
{
internal class Program
{
public delegate void ArgumentHandler(List<string> args);
static void Main(string[] a)
{
bool traceSection = false;
bool traceOnlyName = false;
List<string> args = new List<string>(a);
var handlers = new Dictionary<string, ArgumentHandler>();
handlers["-tr"] = (List<string> arguments) =>
{
traceSection = true;
traceOnlyName = false;
};
handlers["-tron"] = (List<string> arguments) =>
{
traceSection = true;
traceOnlyName = true;
};
int si = 0;
foreach(var arg in args)
{
if(handlers.ContainsKey(arg))
{
handlers[arg](args);
si++;
}
}
if(args.Count < 3)
{
Console.WriteLine("format: Merger [-tr|-trn] %result file% %file1 %file2% ... %filen%, - be sure that last file have greatest priority on merge and will overwrite values");
return;
}
var parser = new FileIniDataParser();
List<IniData> items = new List<IniData>();
IniData trSect = new IniData();
for(int i = si + 1; i < args.Count; i++)
{
FileInfo fi = new FileInfo(args[i]);
if(!fi.Exists)
{
Console.WriteLine($"A file {fi.FullName} does not exist, skipping");
continue;
}
var data = parser.ReadFile(fi.FullName);
items.Add(data);
var tr = traceOnlyName ? fi.Name : args[i];
trSect["merger_trace_section"][tr] = tr;
}
IniData resultData = new IniData();
//items.Reverse();
foreach(var item in items)
resultData.Merge(item);
if(traceSection)
resultData.Merge(trSect);
FileInfo rfi = new FileInfo(args[si]);
string dumped = resultData.ToString();
dumped = dumped.Replace(" = ", "=");
//parser.WriteFile(rfi.FullName, resultData, System.Text.Encoding.UTF8);
File.WriteAllText(rfi.FullName, dumped);
Console.WriteLine($"Saved to {rfi.FullName}");
}
}
}