-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathForm1.cs
More file actions
191 lines (177 loc) · 6.25 KB
/
Copy pathForm1.cs
File metadata and controls
191 lines (177 loc) · 6.25 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace codeLoader
{
public partial class CodeLoaderGen : Form
{
IniParse ini;
string sourcePath;
string encryption;
string icoPath;
string cmdline;
Process process;
public CodeLoaderGen()
{
InitializeComponent();
}
private void run_output(string command)
{
process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.AutoFlush = true;
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);
process.ErrorDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);
button_gen.Enabled = false;
}
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data))
{
this.textBox_output.BeginInvoke((MethodInvoker)(() =>
{
textBox_output.Text += e.Data + "\r\n";
}));
}
else
{
if (process.HasExited)
{
this.button_gen.BeginInvoke((MethodInvoker)(() =>
{
button_gen.Enabled = true;
}));
}
}
}
private void button_gen_Click(object sender, EventArgs e)
{
textBox_output.Text = textBox_cmdline.Text +"\r\n" + "---------------------------------" + "\r\n";
run_output(textBox_cmdline.Text);
}
private void CodeLoaderGen_Load(object sender, EventArgs e)
{
#if DEBUG
// Debug 模式下执行的代码
ini = new IniParse(@"..\..\..\..\config\Compiler.ini");
#else
// Release 模式下执行的代码
ini = new IniParse(@"config\Compiler.ini");
#endif
try
{
List<string> loadList = ini.GetKeyList("compile");
comboBox_Method.DataSource = loadList;
}
catch (Exception)
{
MessageBox.Show("配置文件错误!","错误!");
Environment.Exit(0);
}
cmdlineChangeCallback();
icoBox.AllowDrop = true;
}
private void comboBox_Method_SelectedIndexChanged(object sender, EventArgs e)
{
cmdlineChangeCallback();
}
private void cmdlineChangeCallback()
{
sourcePath = textBox_codePath.Text;
encryption = check_encrypt_caesar.Checked ? "Caesar" : check_encrypt_aes.Checked ? "AES" : "XOR";
string tmpArg = ini.IniReadValue("compile", comboBox_Method.Text);
cmdline = tmpArg.Replace("<encrypt>", encryption);
if (icoPath == null)
{
cmdline = cmdline.Replace(" <ico>", "");
}
else
{
cmdline = cmdline.Replace("<ico>", "-d:icoPath=\"" + icoPath.Replace("\\", "/") + "\"");
}
if (!string.IsNullOrEmpty(sourcePath))
{
cmdline = cmdline.Replace("<source>", sourcePath);
button_gen.Enabled = true;
}
else
{
button_gen.Enabled = false;
}
textBox_cmdline.Text = cmdline;
}
private void textBox_codePath_TextChanged(object sender, EventArgs e)
{
cmdlineChangeCallback();
}
private void radioButton_encrypt_CheckedChanged(object sender, EventArgs e)
{
cmdlineChangeCallback();
}
private void textBox_output_TextChanged(object sender, EventArgs e)
{
textBox_output.SelectionStart = textBox_output.Text.Length;
textBox_output.ScrollToCaret();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(linkLabel1.Text);
}
private void textBox_codePath_DragEnter(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
textBox_codePath.Text = path;
}
private void icoBox_DragEnter(object sender, DragEventArgs e)
{
if (e.KeyState == 0)
{
return;
}
string tmpIcoPath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
// 文件存在性检查
if (!File.Exists(tmpIcoPath))
{
MessageBox.Show("文件不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
icoBox.Image = Image.FromFile(tmpIcoPath);
icoPath = tmpIcoPath;
cmdlineChangeCallback();
button_clear.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(
"无法加载 .ico 图标文件!\n\n可能原因:\n" +
"• 文件已损坏\n" +
"• 不是有效的 .ico 格式\n\n",
"加载失败",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
}
private void button_clear_Click(object sender, EventArgs e)
{
icoBox.Image = null;
icoPath = null;
cmdlineChangeCallback();
button_clear.Enabled = false;
}
}
}