-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cs
More file actions
212 lines (182 loc) · 7.36 KB
/
Logger.cs
File metadata and controls
212 lines (182 loc) · 7.36 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace ConversationTranslator
{
public partial class Logger : Form, ILogger
{
public Logger()
{
InitializeComponent();
}
Setting _settings = new Setting();
Setting DefaultSettings()
{
// sample settings
Setting newSetting = new Setting();
newSetting.origin = @"C:\origin.txt";
newSetting.target = @"C:\target.txt";
newSetting.root = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Neverwinter Nights 2\modules\");
newSetting.miss = @"C:\miss.txt";
newSetting.log = @"C:\log.txt";
newSetting.custom = @"C:\custom.txt";
newSetting.modules = new string[]{
"Module1",
"Module2",
};
return newSetting;
}
void LoadSettings(string filename)
{
filename = filename.Trim();
if (filename.Length > 0)
{
AppendLog(string.Format("Loading setting file {0}...", filename));
using (StreamReader sr = new StreamReader(filename))
{
XmlSerializer s = new XmlSerializer(_settings.GetType());
_settings = s.Deserialize(sr) as Setting;
}
}
else
{
_settings = DefaultSettings();
}
AppendLog(string.Format("Setting loaded:\r\n Origin:{0}\r\n Target:{1}\r\n Miss:{2}\r\n Log:{3}\r\n Custom:{4}\r\n Root:{5}\r\n",
_settings.origin, _settings.target,
_settings.miss, _settings.log, _settings.custom,
_settings.root));
lstMods.Items.Clear();
foreach (var s in _settings.modules)
lstMods.Items.Add(s);
}
void SaveSetting(string filename)
{
AppendLog(string.Format("Saving setting file {0}...", filename));
using (StreamWriter sw = new StreamWriter(filename))
{
XmlSerializer s = new XmlSerializer(_settings.GetType());
s.Serialize(sw, _settings);
}
}
int _counter = 0;
public void AppendLog(string content)
{
this.BeginInvoke(new System.Threading.ThreadStart(delegate()
{
_counter++;
if (_counter > 1000)
{
txtLogger.Clear();
_counter = 0;
}
txtLogger.AppendText(content + "\r\n");
}));
Application.DoEvents();
}
private void btnStart_Click(object sender, EventArgs e)
{
if(!cbJournal.Checked && !cbBlueprint.Checked && !cbConversation.Checked)
{
AppendLog("Include something pls...");
return;
}
List<string> selected = new List<string>();
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("Continue? (ReadOnly: {0})", cbReadonly.Checked));
sb.AppendLine("These Modules will be exported: ");
foreach (var s in lstMods.SelectedItems)
{
selected.Add((string)s);
if (selected.Count < 30)
{
sb.AppendLine((string)s);
}
else if (selected.Count == 50)
{
sb.AppendLine("...");
}
}
sb.AppendLine(string.Format("Total: {0}", selected.Count));
if (selected.Count > 0)
{
if (MessageBox.Show(sb.ToString(), "Question", MessageBoxButtons.OKCancel) != DialogResult.OK)
return;
try
{
Translator trans = new Translator(_settings.origin,
_settings.target,
this,
cbReadonly.Checked,
cbNoTranslate.Checked,
cbSkipCamp.Checked,
cbJournal.Checked,
cbBlueprint.Checked,
cbConversation.Checked);
trans.ConvertConversation(_settings.root,
selected.ToArray(),
_settings.miss,
_settings.log,
_settings.custom);
MessageBox.Show("Finished!");
}
catch (System.Exception ex)
{
AppendLog(ex.Message);
AppendLog(ex.StackTrace);
MessageBox.Show("Got an error!");
}
}
else
{
MessageBox.Show("Did nothing...");
}
}
private void btnLoad_Click(object sender, EventArgs e)
{
using (OpenFileDialog fd = new OpenFileDialog())
{
fd.Filter = "Setting files (*.xml)|*.xml|All files (*.*)|*.*";
if (fd.ShowDialog() == DialogResult.OK)
{
LoadSettings(fd.FileName);
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
using (SaveFileDialog fd = new SaveFileDialog())
{
fd.Filter = "Setting files (*.xml)|*.xml|All files (*.*)|*.*";
if (fd.ShowDialog() == DialogResult.OK)
{
SaveSetting(fd.FileName);
}
}
}
private void Logger_Load(object sender, EventArgs e)
{
AppendLog("================================");
AppendLog(" If you want to change the setting, save it and modify the XML.");
AppendLog(" Then load the modified XML again.");
AppendLog("================================");
LoadSettings("");
}
}
public class Setting
{
public string[] modules; // valid modules
public string root; // module root folder (<game foder>/modules)
public string origin; // origin text (E.X: English version)
public string target; // target text (E.X: Chinese version)
public string miss; // missing record, all the text you still need to translate
public string log; // output log, everything happened during translation
public string custom; // export to custom tlk (in plain text), you may translate later
}
}