-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateCMD.cs
319 lines (290 loc) · 11.9 KB
/
CreateCMD.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
using System;
using System.Net;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Web;
using System.Web.Security;
namespace MapnikTileRenderer
{
public partial class CreateCMD : Form
{
string projectFile;
Multilang ml = new Multilang();
bool noSave_Start = false;
public CreateCMD(string projectFile, bool noSave_Start)
{
InitializeComponent();
this.noSave_Start = noSave_Start;
if (noSave_Start)
{
this.Text = "Çàïóñê íàðåçêè â êëèåíò-ñåðâåðíîì ðåæèìå èç-ïîä êîíñîëè";
button1.Text = "ïóñê ñåðâåðà";
button2.Text = "ïóñê êëèåíòà";
label7.Text = "Çàïóñòèòü íàðåçêó...";
};
this.projectFile = projectFile;
string[] ips = GetLocalIPs();
tIp.Items.AddRange(ips);
this.tIp.Text = ips[ips.Length-1];
this.tTask.Text = ml.Translit(System.IO.Path.GetFileNameWithoutExtension(projectFile).Trim().Replace(" ", "_"));
this.tServerAs.SelectedIndex = 0;
this.tDump.SelectedIndex = 1;
this.tSClose.SelectedIndex = 0;
this.tCClose.SelectedIndex = 0;
this.ccn.SelectedIndex = 0;
}
private void CreateCMD_Load(object sender, EventArgs e)
{
}
private void tServerAs_SelectedIndexChanged(object sender, EventArgs e)
{
tDump.Visible = tServerAs.SelectedIndex == 0;
tDumpLabel.Visible = tServerAs.SelectedIndex == 0;
tHolesLabel.Visible = tServerAs.SelectedIndex > 0;
tHoles.Visible = tServerAs.SelectedIndex > 0;
tHolesB.Visible = tServerAs.SelectedIndex > 0;
tHolesLabel.Text = tServerAs.SelectedIndex == 1 ? "Ôàéë ñ äûðàìè:" : "Ôàéë äàìïà: ";
}
public static string[] GetLocalIPs()
{
List<string> ips = new List<string>();
ips.Add("127.0.0.1");
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
ips.Add(ip.ToString());
return ips.ToArray();
}
private void button1_Click(object sender, EventArgs e)
{
if (noSave_Start)
{
if (tServerAs.SelectedIndex == 1)
{
FileInfo fi = new FileInfo(tHoles.Text);
if (MessageBox.Show(String.Format("Ôàéë ñ äûðàìè: {1}\r\nÐàçìåð ôàéëà {0}!\r\nÂû äåéñòâèòåëüíî õîòèòå çàïóñòèòü íàðåçêó êâàäðàòîâ ñ äûðàìè èç-ïîä ñåðâåðà?", TileRendering.TileRenderer.FileSizeSuffix(fi.Length), tHoles.Text), "Çàïóñê èç-ïîä ñåðâåðà", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
};
string pars = String.Format("\"{0}\"", projectFile);
if (tServerAs.SelectedIndex == 0)
pars += (" /server");
else if (tServerAs.SelectedIndex == 1)
pars += (" /holeserver");
else
pars += (" /dumpserver");
pars += String.Format(" {0}", (int)tPort.Value);
if (tServerAs.SelectedIndex > 0)
pars += String.Format(" \"{0}\"", tHoles.Text);
pars += String.Format(" -task_{0}", ml.Translit(tTask.Text.Trim().Replace(" ", "_")));
if ((tServerAs.SelectedIndex == 0) && (tDump.SelectedIndex == 1))
pars += String.Format(" -dump");
if (tSClose.SelectedIndex == 1)
pars += String.Format(" -cs");
if (tCClose.SelectedIndex == 1)
pars += String.Format(" -cc");
System.Diagnostics.Process.Start(TileRendering.TileRenderer.GetCurrentDir() + @"\mtrc.exe", pars);
return;
};
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "SERVER CMD FILE";
sfd.DefaultExt = ".cmd";
sfd.Filter = "CMD files (*.cmd)|*.cmd|Batch files (*.bat)|*.bat|All types (*.*)|*.*";
sfd.FileName = "mtrc." + System.IO.Path.GetFileNameWithoutExtension(projectFile.Replace(" ", "_")) + ".multi.SERVER.cmd";
if (sfd.ShowDialog() != DialogResult.OK) return;
string fn = sfd.FileName;
sfd.Dispose();
string ext = System.IO.Path.GetExtension(fn).ToLower();
if ((ext != ".cmd") && (ext != ".bat")) fn += ".cmd";
FileStream fs = new FileStream(fn, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write("{0}\\mtrc.exe \"{1}\"",TileRendering.TileRenderer.GetCurrentDir(), projectFile);
if (tServerAs.SelectedIndex == 0)
sw.Write(" /server");
else if (tServerAs.SelectedIndex == 1)
sw.Write(" /holeserver");
else
sw.Write(" /dumpserver");
sw.Write(" {0}", (int)tPort.Value);
if (tServerAs.SelectedIndex > 0)
sw.Write(" \"{0}\"", tHoles.Text);
sw.Write(" -task_{0}", ml.Translit(tTask.Text.Trim().Replace(" ", "_")));
if((tServerAs.SelectedIndex == 0) && (tDump.SelectedIndex == 1))
sw.Write(" -dump");
if(tSClose.SelectedIndex == 1)
sw.Write(" -cs");
if (tCClose.SelectedIndex == 1)
sw.Write(" -cc");
sw.Close();
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (noSave_Start)
{
string pars = String.Format("\"{0}\" /client", projectFile);
pars += String.Format(" {0}:{1}", tIp.Text.Trim(), (int)tPort.Value);
pars += String.Format(" -task_{0}", ml.Translit(tTask.Text.Trim().Replace(" ", "_")));
pars += String.Format(" -threads_{0}", ccn.Text.Substring(0,2));
System.Diagnostics.Process.Start(TileRendering.TileRenderer.GetCurrentDir() + @"\mtrc.exe", pars);
return;
};
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "CLIENT CMD FILE";
sfd.DefaultExt = ".cmd";
sfd.Filter = "CMD files (*.cmd)|*.cmd|Batch files (*.bat)|*.bat|All types (*.*)|*.*";
sfd.FileName = "mtrc." + System.IO.Path.GetFileNameWithoutExtension(projectFile.Replace(" ", "_")) + ".multi.CLIENT-" + ccn.Text.Substring(0, 2).ToUpper() + ".cmd";
if (sfd.ShowDialog() != DialogResult.OK) return;
string fn = sfd.FileName;
sfd.Dispose();
string ext = System.IO.Path.GetExtension(fn).ToLower();
if ((ext != ".cmd") && (ext != ".bat")) fn += ".cmd";
FileStream fs = new FileStream(fn, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write("{0}\\mtrc.exe \"{1}\" /client", TileRendering.TileRenderer.GetCurrentDir(), projectFile);
sw.Write(" {0}:{1}", tIp.Text.Trim(), (int)tPort.Value);
sw.Write(" -task_{0}", ml.Translit(tTask.Text.Trim().Replace(" ", "_")));
sw.Write(" -threads_{0}", ccn.Text.Substring(0, 2));
sw.Close();
fs.Close();
}
private void tHolesB_Click(object sender, EventArgs e)
{
if (tServerAs.SelectedIndex == 1)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "*.holes";
ofd.Filter = "Holes & Error files (*.holes;*.errorlog)|*.holes;*.errorlog|Holes files (*.holes)|*.holes|Error Log files (*.errorlog)|*.errorlog|All Types (*.*)|*.*";
ofd.Title = "Âûáåðèòå ôàéë ñ äûðàìè";
if (ofd.ShowDialog() != DialogResult.OK) return;
tHoles.Text = ofd.FileName;
ofd.Dispose();
};
if (tServerAs.SelectedIndex == 2)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "*.holes";
ofd.Filter = "Dump files (*.dump)|*.dump|All Types (*.*)|*.*";
ofd.Title = "Âûáåðèòå ôàéë äàìïà";
if (ofd.ShowDialog() != DialogResult.OK) return;
tHoles.Text = ofd.FileName;
ofd.Dispose();
};
}
}
[Serializable]
public class Multilang
{
private Dictionary<string, string> words = new Dictionary<string, string>();
private string en = "";
private string ru = "";
public string EN
{
get { return en; }
set
{
en = System.Web.HttpUtility.HtmlEncode(value);
}
}
public string RU
{
get { return ru; }
set
{
ru = System.Web.HttpUtility.HtmlEncode(value);
if ((en == null) || (en == String.Empty) || (en.Length == 0)) en = Translit(ru);
}
}
private void InitDict()
{
words.Add("à", "a");
words.Add("á", "b");
words.Add("â", "v");
words.Add("ã", "g");
words.Add("ä", "d");
words.Add("å", "e");
words.Add("¸", "yo");
words.Add("æ", "zh");
words.Add("ç", "z");
words.Add("è", "i");
words.Add("é", "j");
words.Add("ê", "k");
words.Add("ë", "l");
words.Add("ì", "m");
words.Add("í", "n");
words.Add("î", "o");
words.Add("ï", "p");
words.Add("ð", "r");
words.Add("ñ", "s");
words.Add("ò", "t");
words.Add("ó", "u");
words.Add("ô", "f");
words.Add("õ", "h");
words.Add("ö", "c");
words.Add("÷", "ch");
words.Add("ø", "sh");
words.Add("ù", "sch");
words.Add("ú", "j");
words.Add("û", "i");
words.Add("ü", "j");
words.Add("ý", "e");
words.Add("þ", "yu");
words.Add("ÿ", "ya");
words.Add("À", "A");
words.Add("Á", "B");
words.Add("Â", "V");
words.Add("Ã", "G");
words.Add("Ä", "D");
words.Add("Å", "E");
words.Add("¨", "Yo");
words.Add("Æ", "Zh");
words.Add("Ç", "Z");
words.Add("È", "I");
words.Add("É", "J");
words.Add("Ê", "K");
words.Add("Ë", "L");
words.Add("Ì", "M");
words.Add("Í", "N");
words.Add("Î", "O");
words.Add("Ï", "P");
words.Add("Ð", "R");
words.Add("Ñ", "S");
words.Add("Ò", "T");
words.Add("Ó", "U");
words.Add("Ô", "F");
words.Add("Õ", "H");
words.Add("Ö", "C");
words.Add("×", "Ch");
words.Add("Ø", "Sh");
words.Add("Ù", "Sch");
words.Add("Ú", "J");
words.Add("Û", "I");
words.Add("Ü", "J");
words.Add("Ý", "E");
words.Add("Þ", "Yu");
words.Add("ß", "Ya");
}
public string Translit(string RU)
{
string EN = RU;
foreach (KeyValuePair<string, string> pair in words)
EN = EN.Replace(pair.Key, pair.Value);
return EN;
}
public Multilang()
{
InitDict();
}
public Multilang(string EN, string RU)
{
InitDict();
this.EN = EN;
this.RU = RU;
}
}
}