-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateWriter.cs
62 lines (53 loc) · 1.65 KB
/
TemplateWriter.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace UniversalEmoticonPackBuilderLib
{
public class TemplateWriter
{
private string outfile;
private Dictionary<string, string> replaces;
private string tpl_file;
public string data;
public TemplateWriter(string name, string outfile, PackInfo pack)
{
this.tpl_file = name;
this.outfile = outfile;
replaces = new Dictionary<string, string>
{
{"__PACKNAME__", pack.name},
{"__PACKAUTHOR__", pack.author},
{"__PACKVERSION__", pack.version}
};
}
public void AddReplacement(string key, string value) {
replaces.Add(key, value);
}
public void Write(string s) {
data += s;
}
public void WriteLine(string l)
{
Write(String.Format("{0}\n", l));
}
public void Flush() {
var tpl = new StreamReader(String.Format("{0}/templates/{1}", System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), tpl_file));
var o = new StreamWriter(outfile);
o.AutoFlush = true;
string l;
while ((l = tpl.ReadLine()) != null)
{
foreach (var kv in replaces)
l = l.Replace(kv.Key, kv.Value);
l = l.Replace("__PACKDATA__", data);
o.WriteLine(l);
}
tpl.Close();
o.Flush();
o.Close();
}
}
}